-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tara Drwenski
committed
Dec 11, 2023
1 parent
9e64be4
commit 1705c65
Showing
2 changed files
with
56 additions
and
64 deletions.
There are no files selected for viewing
64 changes: 0 additions & 64 deletions
64
cdm/core/src/test/groovy/ucar/nc2/iosp/netcdf3/N3iospSpec.groovy
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
cdm/core/src/test/java/ucar/nc2/iosp/netcdf3/TestN3iosp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ucar.nc2.iosp.netcdf3; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import org.junit.Test; | ||
|
||
public class TestN3iosp { | ||
|
||
@Test | ||
public void shouldReturnInvalidForNullOrEmptyNames() { | ||
assertThat(N3iosp.isValidNetcdfObjectName(null)).isFalse(); | ||
assertThrows(NullPointerException.class, () -> N3iosp.makeValidNetcdfObjectName(null)); | ||
|
||
assertThat(N3iosp.isValidNetcdfObjectName("")).isFalse(); | ||
IllegalArgumentException e = | ||
assertThrows(IllegalArgumentException.class, () -> N3iosp.makeValidNetcdfObjectName("")); | ||
assertThat(e.getMessage()).isEqualTo("Illegal NetCDF object name: ''"); | ||
} | ||
|
||
@Test | ||
public void shouldReturnInvalidForBadFirstCharacters() { | ||
// names with first chars not in ([a-zA-Z0-9_]|{UTF8}) are invalid | ||
assertThat(N3iosp.isValidNetcdfObjectName(" blah")).isFalse(); | ||
assertThat(N3iosp.makeValidNetcdfObjectName(" blah")).isEqualTo("blah"); | ||
|
||
assertThat(N3iosp.isValidNetcdfObjectName("\n/blah")).isFalse(); | ||
assertThat(N3iosp.makeValidNetcdfObjectName("\n/blah")).isEqualTo("blah"); | ||
|
||
// Unit separator and DEL | ||
assertThat(N3iosp.isValidNetcdfObjectName("\u001F\u007F blah")).isFalse(); | ||
assertThat(N3iosp.makeValidNetcdfObjectName("\u001F\u007F blah")).isEqualTo("blah"); | ||
} | ||
|
||
@Test | ||
public void shouldReturnInvalidForBadCharacters() { | ||
// names with remaining chars not in ([^\x00-\x1F\x7F/]|{UTF8})* are invalid | ||
assertThat(N3iosp.isValidNetcdfObjectName("1\u000F2\u007F3/4")).isFalse(); | ||
assertThat(N3iosp.makeValidNetcdfObjectName("1\u000F2\u007F3/4")).isEqualTo("1234"); | ||
|
||
// names may not have trailing spaces | ||
assertThat(N3iosp.isValidNetcdfObjectName("foo ")).isFalse(); | ||
assertThat(N3iosp.makeValidNetcdfObjectName("foo ")).isEqualTo("foo"); | ||
} | ||
|
||
@Test | ||
public void shouldAcceptValidNames() { | ||
// valid names have syntax: ([a-zA-Z0-9_]|{UTF8})([^\x00-\x1F\x7F/]|{UTF8})* | ||
assertThat(N3iosp.isValidNetcdfObjectName("_KfS9Jn_s9__")).isTrue(); | ||
assertThat(N3iosp.makeValidNetcdfObjectName("_KfS9Jn_s9__")).isEqualTo("_KfS9Jn_s9__"); | ||
|
||
// unicode characters greater than 0x7F can appear anywhere | ||
assertThat(N3iosp.isValidNetcdfObjectName("\u0123\u1234\u2345\u3456")).isTrue(); | ||
assertThat(N3iosp.makeValidNetcdfObjectName("\u0123\u1234\u2345\u3456")).isEqualTo("\u0123\u1234\u2345\u3456"); | ||
} | ||
} |