-
-
Notifications
You must be signed in to change notification settings - Fork 44
TestUnicodeInvariants: add tests for TestCodeInvariants #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2bd8c54
a0d2657
56627a6
32199e9
dc7466f
beed3cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,18 +13,6 @@ | |
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
import org.unicode.cldr.draft.FileUtilities; | ||
import org.unicode.cldr.util.Tabber; | ||
import org.unicode.cldr.util.Tabber.HTMLTabber; | ||
import org.unicode.props.BagFormatter; | ||
import org.unicode.jsp.ICUPropertyFactory; | ||
import org.unicode.cldr.util.props.UnicodeLabel; | ||
import org.unicode.props.UnicodeProperty; | ||
import org.unicode.props.UnicodeProperty.Factory; | ||
import org.unicode.props.UnicodeProperty.PatternMatcher; | ||
import org.unicode.props.IndexUnicodeProperties; | ||
import org.unicode.text.utility.Settings; | ||
|
||
import com.ibm.icu.dev.tool.UOption; | ||
import com.ibm.icu.dev.util.UnicodeMap; | ||
import com.ibm.icu.lang.UCharacter; | ||
|
@@ -34,6 +22,18 @@ | |
import com.ibm.icu.text.UnicodeSet; | ||
import com.ibm.icu.text.UnicodeSetIterator; | ||
|
||
import org.unicode.cldr.draft.FileUtilities; | ||
import org.unicode.cldr.util.Tabber; | ||
import org.unicode.cldr.util.Tabber.HTMLTabber; | ||
import org.unicode.cldr.util.props.UnicodeLabel; | ||
import org.unicode.jsp.ICUPropertyFactory; | ||
import org.unicode.props.BagFormatter; | ||
import org.unicode.props.IndexUnicodeProperties; | ||
import org.unicode.props.UnicodeProperty; | ||
import org.unicode.props.UnicodeProperty.Factory; | ||
import org.unicode.props.UnicodeProperty.PatternMatcher; | ||
import org.unicode.text.utility.Settings; | ||
|
||
public class TestUnicodeInvariants { | ||
private static final boolean DEBUG = false; | ||
|
||
|
@@ -45,6 +45,7 @@ public class TestUnicodeInvariants { | |
private static final boolean SHOW_LOOKUP = false; | ||
private static int showRangeLimit = 20; | ||
static boolean doHtml = true; | ||
public static final String DEFAULT_FILE = "UnicodeInvariantTest.txt"; | ||
|
||
private static final int | ||
//HELP1 = 0, | ||
|
@@ -64,7 +65,7 @@ public class TestUnicodeInvariants { | |
public static void main(String[] args) throws IOException { | ||
UOption.parseArgs(args, options); | ||
|
||
String file = "UnicodeInvariantTest.txt"; | ||
String file = DEFAULT_FILE; | ||
if (options[FILE].doesOccur) { | ||
file = options[FILE].value; | ||
} | ||
|
@@ -77,12 +78,6 @@ public static void main(String[] args) throws IOException { | |
System.out.println("HTML?\t" + doHtml); | ||
|
||
testInvariants(file, doRange); | ||
if (TestCodeInvariants.testScriptExtensions() < 0) { | ||
System.out.println("Invariant test for Script_Extensions failed!"); | ||
} | ||
if (TestCodeInvariants.testGcbInDecompositions(false) < 0) { | ||
System.out.println("Invariant test for GCB in canonical decompositions failed!"); | ||
} | ||
} | ||
|
||
static Transliterator toHTML; | ||
|
@@ -113,7 +108,31 @@ enum Expected {empty, not_empty, irrelevant}; | |
|
||
private static PrintWriter out; | ||
|
||
public static void testInvariants(String outputFile, boolean doRange) throws IOException { | ||
/** | ||
* Fetch a reader for our input data. | ||
* @param inputFile if null, read DEFAULT_FILE from classpath | ||
* @return BufferedReader | ||
* @throws IOException | ||
*/ | ||
private static BufferedReader getInputReader(String inputFile) throws IOException { | ||
if (inputFile != null) { | ||
return FileUtilities.openUTF8Reader(Settings.SRC_UCD_DIR, inputFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI This should work in the build bots. For example, https://github.com/unicode-org/unicodetools/blob/main/.github/workflows/build-jsp.yml#L52 does set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should but does not |
||
} | ||
|
||
// null: read it from resource data | ||
return FileUtilities.openFile(TestUnicodeInvariants.class, DEFAULT_FILE); | ||
} | ||
|
||
/** | ||
* | ||
* @param inputFile file to input, defaults to DEFAULT_FILE | ||
* @param doRange normally true | ||
* @return number of failures (0 is better) | ||
* @throws IOException | ||
*/ | ||
public static int testInvariants(String inputFile, boolean doRange) throws IOException { | ||
parseErrorCount = 0; | ||
testFailureCount = 0; | ||
boolean showScript = false; | ||
try (final PrintWriter out2 = FileUtilities.openUTF8Writer(Settings.Output.GEN_DIR, "UnicodeTestResults." + (doHtml ? "html" : "txt"))) { | ||
final StringWriter writer = new StringWriter(); | ||
|
@@ -134,7 +153,7 @@ public static void testInvariants(String outputFile, boolean doRange) throws IOE | |
} else { | ||
out3.write('\uFEFF'); // BOM | ||
} | ||
try (final BufferedReader in = FileUtilities.openUTF8Reader(Settings.SRC_UCD_DIR, outputFile)) { | ||
try (final BufferedReader in = getInputReader(inputFile)) { | ||
final HTMLTabber tabber = new Tabber.HTMLTabber(); | ||
|
||
errorLister = new BagFormatter() | ||
|
@@ -167,8 +186,6 @@ public static void testInvariants(String outputFile, boolean doRange) throws IOE | |
// new ChainedSymbolTable(new SymbolTable[] { | ||
// ToolUnicodePropertySource.make(UCD.lastVersion).getSymbolTable("\u00D7"), | ||
// ToolUnicodePropertySource.make(Default.ucdVersion()).getSymbolTable("")}); | ||
parseErrorCount = 0; | ||
testFailureCount = 0; | ||
while (true) { | ||
String line = in.readLine(); | ||
if (line == null) { | ||
|
@@ -226,6 +243,7 @@ public static void testInvariants(String outputFile, boolean doRange) throws IOE | |
} | ||
out = null; | ||
} | ||
return parseErrorCount + testFailureCount; | ||
} | ||
|
||
static class PropertyComparison { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.unicode.text.UCD; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.unicode.text.utility.Settings; | ||
|
||
public class TestTestUnicodeInvariants { | ||
@Test | ||
void testSRC_UCD_DIR() { | ||
assertAll("assert that no components of Settings.SRC_UCD_DIR are null", | ||
() -> assertNotNull(Settings.SRC_UCD_DIR, "Settings.SRC_UCD_DIR"), | ||
() -> assertNotNull(Settings.SRC_DIR, "Settings.SRC_DIR"), | ||
() -> assertNotNull(Settings.UnicodeTools.UNICODETOOLS_RSRC_DIR, "Settings.UnicodeTools.UNICODETOOLS_RSRC_DIR"), | ||
() -> assertNotNull(Settings.UnicodeTools.UNICODETOOLS_DIR, "Settings.UnicodeTools.UNICODETOOLS_DIR"), | ||
() -> assertNotNull(Settings.UnicodeTools.UNICODETOOLS_REPO_DIR, "Settings.UnicodeTools.UNICODETOOLS_REPO_DIR")); | ||
} | ||
|
||
@Test | ||
void testUnicodeInvariants() throws IOException { | ||
int rc = TestUnicodeInvariants.testInvariants(null, true); | ||
assertEquals(0, rc, "TestUnicodeInvariants.testInvariants() failed"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would it be null? Line 80 calls testInvariants() with DEFAULT_FILE, or with a String from a command-line argument, if there is one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pass null from TestTestUnicodeInvariants to mean default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about passing TestUnicodeInvariants.DEFAULT_FILE from the TestTest... code?