]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/tests/translit/src/com/ibm/icu/dev/test/translit/TestUnicodeProperty.java
Clean up imports.
[Dictionary.git] / jars / icu4j-52_1 / main / tests / translit / src / com / ibm / icu / dev / test / translit / TestUnicodeProperty.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 2011-2012, International Business Machines Corporation and         *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7 package com.ibm.icu.dev.test.translit;
8
9 import java.util.List;
10
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;
17
18 /**
19  * @author markdavis
20  *
21  */
22 public class TestUnicodeProperty extends TestFmwk{
23     public static void main(String[] args) {
24         new TestUnicodeProperty().run(args);
25     }
26     static final UnicodeSet casedLetter = new UnicodeSet("[:gc=cased letter:]");
27     static final UnicodeSet letter = new UnicodeSet("[:gc=L:]");
28
29
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));
38         }
39     }
40
41     public void TestSymbolTable() {
42         Factory factory = ICUPropertyFactory.make();
43         UnicodePropertySymbolTable upst = new UnicodePropertySymbolTable(factory);
44         UnicodeSet.setDefaultXSymbolTable(upst);
45         try {
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);
52         } finally {
53             // restore the world
54             UnicodeSet.setDefaultXSymbolTable(null);
55         }
56     }
57
58     public void TestSymbolTable2() {
59         Factory factory = new MyUnicodePropertyFactory();
60         UnicodePropertySymbolTable upst = new UnicodePropertySymbolTable(factory);
61         UnicodeSet.setDefaultXSymbolTable(upst);
62         try {
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));
67             }
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);
71         } finally {
72             // restore the world
73             UnicodeSet.setDefaultXSymbolTable(null);
74         }
75     }
76
77
78     /**
79      * For testing, override to set A-M to Cn.
80      */
81     static class MyUnicodeGCProperty extends UnicodeProperty.SimpleProperty {
82         UnicodeProperty icuProperty = ICUPropertyFactory.make().getProperty("Gc");
83         {
84             setName(icuProperty.getName());
85             setType(icuProperty.getType());
86         }
87         @Override
88         protected String _getValue(int codepoint) {
89             if (codepoint >= 'A' && codepoint <= 'M') {
90                 return "Unassigned";
91             } else {
92                 return icuProperty.getValue(codepoint);
93             }
94         }
95         @Override
96         protected List _getValueAliases(String valueAlias, List result) {
97             return icuProperty.getValueAliases(valueAlias, result);
98         }
99         @Override
100         public List _getNameAliases(List result) {
101             return icuProperty.getNameAliases();
102         }
103     }
104
105     /**
106      * For testing, override to set A-Z to Cn.
107      */
108     static class MyUnicodePropertyFactory extends ICUPropertyFactory {
109         private MyUnicodePropertyFactory() {
110             add(new MyUnicodeGCProperty());
111         }
112     }
113
114     static class MyUnicodePropertySymbolTable extends UnicodePropertySymbolTable {
115         public MyUnicodePropertySymbolTable(Factory factory) {
116             super(factory);
117         }
118     }
119 }