public void TestUnicodeSetErrors() { String badPattern = "[[:L:]-[0x0300-0x0400]"; UnicodeSet set = new UnicodeSet(); //String result; if (!set.IsEmpty) { Errln("FAIL: The default ctor of UnicodeSet created a non-empty object."); } try { set.ApplyPattern(badPattern); Errln("FAIL: Applied a bad pattern to the UnicodeSet object okay."); } catch (ArgumentException e) { Logln("Test applying with the bad pattern."); } try { new UnicodeSet(badPattern); Errln("FAIL: Created a UnicodeSet based on bad patterns."); } catch (ArgumentException e) { Logln("Test constructing with the bad pattern."); } }
private int ParseUnicodeSet(int i, UnicodeSet set) { // Collect a UnicodeSet pattern between a balanced pair of [brackets]. int level = 0; int j = i; for (; ;) { if (j == rules.Length) { SetParseError("unbalanced UnicodeSet pattern brackets"); return(j); } char c = rules[j++]; if (c == 0x5b) { // '[' ++level; } else if (c == 0x5d) { // ']' if (--level == 0) { break; } } } try { set.ApplyPattern(rules.Substring(i, j - i)); // ICU4N: Corrected 2nd parameter } catch (Exception e) { SetParseError("not a valid UnicodeSet pattern: " + e.ToString()); } j = SkipWhiteSpace(j); if (j == rules.Length || rules[j] != 0x5d) { SetParseError("missing option-terminating ']' after UnicodeSet pattern"); return(j); } return(++j); }
public void TestSetEquals() { // Initialize UnicodeSets var thaiWordSet = new UnicodeSet(); var thaiWordSet2 = new UnicodeSet(); var burmeseWordSet = new UnicodeSet(); burmeseWordSet.ApplyPattern("[[:Mymr:]&[:LineBreak=SA:]]"); burmeseWordSet.Compact(); thaiWordSet.ApplyPattern("[[:Thai:]&[:LineBreak=SA:]]"); thaiWordSet.Compact(); thaiWordSet2.ApplyPattern("[[:Thai:]&[:LineBreak=SA:]]"); thaiWordSet2.Compact(); assertTrue("UnicodeSet.SetEquals: The word sets are not equal", thaiWordSet.SetEquals(thaiWordSet2)); assertTrue("UnicodeSet.SetEquals: The word sets are not equal", thaiWordSet2.SetEquals(thaiWordSet)); assertFalse("UnicodeSet.SetEquals: The word sets are equal", thaiWordSet.SetEquals(burmeseWordSet)); var equivSet = new List <string>(); thaiWordSet.AddAllTo(equivSet); assertTrue("UnicodeSet.SetEquals: The word sets are not equal", thaiWordSet.SetEquals(equivSet)); }