svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / test / java / org / gvsig / expresionevaluator / impl / TestSymbolTable.java @ 47738
History | View | Annotate | Download (3.65 KB)
1 |
package org.gvsig.expresionevaluator.impl; |
---|---|
2 |
|
3 |
import junit.framework.TestCase; |
4 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
5 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
6 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
7 |
import org.gvsig.expressionevaluator.SymbolTable; |
8 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
9 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
10 |
|
11 |
|
12 |
public class TestSymbolTable extends TestCase { |
13 |
|
14 |
public TestSymbolTable(String testName) { |
15 |
super(testName);
|
16 |
} |
17 |
|
18 |
@Override
|
19 |
protected void setUp() throws Exception { |
20 |
super.setUp();
|
21 |
new DefaultLibrariesInitializer().fullInitialize();
|
22 |
} |
23 |
|
24 |
@Override
|
25 |
protected void tearDown() throws Exception { |
26 |
super.tearDown();
|
27 |
} |
28 |
|
29 |
// TODO add test methods here. The name must begin with 'test'. For example:
|
30 |
// public void testHello() {}
|
31 |
|
32 |
|
33 |
private MutableSymbolTable createMutableSymbolTable() {
|
34 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
35 |
MutableSymbolTable t = manager.createSymbolTable(); |
36 |
return t;
|
37 |
} |
38 |
|
39 |
private SymbolTable createSymbolTable() {
|
40 |
SymbolTable t = new AbstractSymbolTable() {
|
41 |
}; |
42 |
return t;
|
43 |
} |
44 |
|
45 |
public void testGetter() { |
46 |
SymbolTable symbolTable = createSymbolTable(); |
47 |
|
48 |
assertNull(symbolTable.value("number"));
|
49 |
assertFalse(symbolTable.exists("number"));
|
50 |
|
51 |
assertNull(symbolTable.function("abs"));
|
52 |
|
53 |
assertEquals(0, symbolTable.variables().size());
|
54 |
assertEquals(0, symbolTable.functions().size());
|
55 |
// assertEquals(0, symbolTable.scripts().size());
|
56 |
} |
57 |
|
58 |
public void testGetter2() { |
59 |
MutableSymbolTable symbolTable = createMutableSymbolTable(); |
60 |
|
61 |
assertNull(symbolTable.value("number"));
|
62 |
assertFalse(symbolTable.exists("number"));
|
63 |
|
64 |
assertNotNull(symbolTable.function("abs"));
|
65 |
|
66 |
assertEquals(0, symbolTable.variables().size());
|
67 |
assertFalse(symbolTable.functions().isEmpty()); |
68 |
// assertEquals(0, symbolTable.scripts().size());
|
69 |
} |
70 |
|
71 |
public void testSetter1() { |
72 |
MutableSymbolTable symbolTable = createMutableSymbolTable(); |
73 |
|
74 |
symbolTable.setVar("number", 10); |
75 |
|
76 |
assertEquals(10, symbolTable.value("number")); |
77 |
assertTrue(symbolTable.exists("number"));
|
78 |
|
79 |
assertEquals(1, symbolTable.variables().size());
|
80 |
assertFalse(symbolTable.functions().isEmpty()); |
81 |
// assertEquals(0, symbolTable.scripts().size());
|
82 |
} |
83 |
|
84 |
public void testDelegated1() { |
85 |
|
86 |
MutableSymbolTable symbolTable1 = createMutableSymbolTable(); |
87 |
|
88 |
MutableSymbolTable symbolTable2 = createMutableSymbolTable(); |
89 |
symbolTable2.setVar("number", 10); |
90 |
|
91 |
symbolTable1.addSymbolTable(symbolTable2); |
92 |
assertEquals(10, symbolTable1.value("number")); |
93 |
assertTrue(symbolTable1.exists("number"));
|
94 |
assertNotNull(symbolTable1.function("abs"));
|
95 |
|
96 |
assertEquals(symbolTable2.functions().size(), symbolTable1.functions().size()); |
97 |
} |
98 |
|
99 |
public void testDelegated2() { |
100 |
|
101 |
SymbolTable symbolTable1 = createSymbolTable(); |
102 |
|
103 |
MutableSymbolTable symbolTable2 = createMutableSymbolTable(); |
104 |
symbolTable2.setVar("number", 10); |
105 |
|
106 |
symbolTable1.addSymbolTable(symbolTable2); |
107 |
assertEquals(10, symbolTable1.value("number")); |
108 |
assertTrue(symbolTable1.exists("number"));
|
109 |
assertNotNull(symbolTable1.function("abs"));
|
110 |
|
111 |
assertEquals(symbolTable2.functions().size(), symbolTable1.functions().size()); |
112 |
} |
113 |
|
114 |
} |