*/
public void TestToPattern() throws Exception {
// Test that toPattern() round trips with syntax characters
// and whitespace.
for (int i = 0; i < OTHER_TOPATTERN_TESTS.length; ++i) {
checkPat(OTHER_TOPATTERN_TESTS[i], new UnicodeSet(OTHER_TOPATTERN_TESTS[i]));
}
for (int i = 0; i <= 0x10FFFF; ++i) {
if ((i <= 0xFF && !UCharacter.isLetter(i)) || UCharacter.isWhitespace(i)) {
// check various combinations to make sure they all work.
if (i != 0 && !toPatternAux(i, i)) continue;
if (!toPatternAux(0, i)) continue;
if (!toPatternAux(i, 0xFFFF)) continue;
}
}
// Test pattern behavior of multicharacter strings.
UnicodeSet s = new UnicodeSet("[a-z {aa} {ab}]");
expectToPattern(s, "[a-z{aa}{ab}]",
new String[] {"aa", "ab", NOT, "ac"});
s.add("ac");
expectToPattern(s, "[a-z{aa}{ab}{ac}]",
new String[] {"aa", "ab", "ac", NOT, "xy"});
s.applyPattern("[a-z {\\{l} {r\\}}]");
expectToPattern(s, "[a-z{r\\}}{\\{l}]",
new String[] {"{l", "r}", NOT, "xy"});
s.add("[]");
expectToPattern(s, "[a-z{\\[\\]}{r\\}}{\\{l}]",
new String[] {"{l", "r}", "[]", NOT, "xy"});
s.applyPattern("[a-z {\u4E01\u4E02}{\\n\\r}]");
expectToPattern(s, "[a-z{\\u000A\\u000D}{\\u4E01\\u4E02}]",
new String[] {"\u4E01\u4E02", "\n\r"});
s.clear();
s.add("abc");
s.add("abc");
expectToPattern(s, "[{abc}]",
new String[] {"abc", NOT, "ab"});
// JB#3400: For 2 character ranges prefer [ab] to [a-b]
s.clear();
s.add('a', 'b');
expectToPattern(s, "[ab]", null);
// Cover applyPattern, applyPropertyAlias
s.clear();
s.applyPattern("[ab ]", true);
expectToPattern(s, "[ab]", new String[] {"a", NOT, "ab", " "});
s.clear();
s.applyPattern("[ab ]", false);
expectToPattern(s, "[\\ ab]", new String[] {"a", "\u0020", NOT, "ab"});
s.clear();
s.applyPropertyAlias("nv", "0.5");
expectToPattern(s, "[\\u00BD\\u0D74\\u0F2A\\u2CFD\\U00010141\\U00010175\\U00010176]", null);
// Unicode 5.1 adds Malayalam 1/2 (\u0D74)
s.clear();
s.applyPropertyAlias("gc", "Lu");
// TODO expectToPattern(s, what?)
// RemoveAllStrings()
s.clear();
s.applyPattern("[a-z{abc}{def}]");
expectToPattern(s, "[a-z{abc}{def}]", null);
s.removeAllStrings();
expectToPattern(s, "[a-z]", null);
}