2 *******************************************************************************
3 * Copyright (C) 2011-2012, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
7 package com.ibm.icu.dev.test.translit;
11 import com.ibm.icu.dev.test.TestFmwk;
12 import com.ibm.icu.dev.util.ICUPropertyFactory;
13 import com.ibm.icu.dev.util.UnicodeProperty;
14 import com.ibm.icu.dev.util.UnicodeProperty.Factory;
15 import com.ibm.icu.dev.util.UnicodePropertySymbolTable;
16 import com.ibm.icu.text.UnicodeSet;
22 public class TestUnicodeProperty extends TestFmwk{
23 public static void main(String[] args) {
24 new TestUnicodeProperty().run(args);
26 static final UnicodeSet casedLetter = new UnicodeSet("[:gc=cased letter:]");
27 static final UnicodeSet letter = new UnicodeSet("[:gc=L:]");
30 public void TestBasic() {
31 Factory factory = ICUPropertyFactory.make();
32 UnicodeProperty property = factory.getProperty("gc");
33 List values = property.getAvailableValues();
34 assertTrue("Values contain GC values", values.contains("Unassigned"));
35 final UnicodeSet lu = property.getSet("Lu");
36 if (!assertTrue("Gc=L contains 'A'", lu.contains('A'))) {
37 errln("Contents:\t" + lu.complement().complement().toPattern(false));
41 public void TestSymbolTable() {
42 Factory factory = ICUPropertyFactory.make();
43 UnicodePropertySymbolTable upst = new UnicodePropertySymbolTable(factory);
44 UnicodeSet.setDefaultXSymbolTable(upst);
46 final UnicodeSet luSet = new UnicodeSet("[:gc=L:]");
47 assertTrue("Gc=L contains 'A'", luSet.contains('A'));
48 assertTrue("Gc=L contains 'Z'", luSet.contains('Z'));
49 assertFalse("Gc=L contains 'a'", luSet.contains('1'));
50 UnicodeSet casedLetter2 = new UnicodeSet("[:gc=cased letter:]");
51 assertEquals("gc=lc are equal", casedLetter, casedLetter2);
54 UnicodeSet.setDefaultXSymbolTable(null);
58 public void TestSymbolTable2() {
59 Factory factory = new MyUnicodePropertyFactory();
60 UnicodePropertySymbolTable upst = new UnicodePropertySymbolTable(factory);
61 UnicodeSet.setDefaultXSymbolTable(upst);
63 final UnicodeSet luSet = new UnicodeSet("[:gc=L:]");
64 assertFalse("Gc=L contains 'A'", luSet.contains('A'));
65 if (!assertTrue("Gc=L contains 'Z'", luSet.contains('Z'))) {
66 errln("Contents:\t" + luSet.complement().complement().toPattern(false));
68 assertFalse("Gc=L contains 'a'", luSet.contains('1'));
69 UnicodeSet casedLetter2 = new UnicodeSet("[:gc=cased letter:]");
70 assertNotEquals("gc=lc should not be equal", casedLetter, casedLetter2);
73 UnicodeSet.setDefaultXSymbolTable(null);
79 * For testing, override to set A-M to Cn.
81 static class MyUnicodeGCProperty extends UnicodeProperty.SimpleProperty {
82 UnicodeProperty icuProperty = ICUPropertyFactory.make().getProperty("Gc");
84 setName(icuProperty.getName());
85 setType(icuProperty.getType());
88 protected String _getValue(int codepoint) {
89 if (codepoint >= 'A' && codepoint <= 'M') {
92 return icuProperty.getValue(codepoint);
96 protected List _getValueAliases(String valueAlias, List result) {
97 return icuProperty.getValueAliases(valueAlias, result);
100 public List _getNameAliases(List result) {
101 return icuProperty.getNameAliases();
106 * For testing, override to set A-Z to Cn.
108 static class MyUnicodePropertyFactory extends ICUPropertyFactory {
109 private MyUnicodePropertyFactory() {
110 add(new MyUnicodeGCProperty());
114 static class MyUnicodePropertySymbolTable extends UnicodePropertySymbolTable {
115 public MyUnicodePropertySymbolTable(Factory factory) {