Revision 44379 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/TestGrammarCompiler.java

View differences:

TestGrammarCompiler.java
1 1
package org.gvsig.expresionevaluator.impl;
2 2

  
3
import static junit.framework.Assert.assertEquals;
4 3
import junit.framework.TestCase;
5 4
import org.gvsig.expressionevaluator.Code;
6 5
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
......
74 73
    }
75 74

  
76 75
    public void testBlock() {
77
        String source = "BEGIN LET V1 = 23 END";
76
        String source = "BEGIN LET V1 = 23; END";
78 77

  
79 78
        Compiler compiler = createCompiler();
80 79

  
......
83 82
    }
84 83

  
85 84
    public void testBlock2() {
86
        String source = "BEGIN LET V1 = 11; LET V2 = 22  END";
85
        String source = "BEGIN LET V1 = 11; LET V2 = 22;  END";
87 86

  
88 87
        Compiler compiler = createCompiler();
89 88

  
......
104 103
    }
105 104

  
106 105
    public void testIfThen() {
107
        String source = "IF V1 = 11 THEN LET V2 = 22";
106
        String source = "IF V1 = 11 THEN LET V2 = 22; END IF";
108 107

  
109 108
        Compiler compiler = createCompiler();
110 109

  
......
112 111
        assertEquals("IFF((\"V1\" = 11), LET('V2', 22))", code.toString());
113 112
    }
114 113

  
115
    public void testIfThen2() {
116
        String source = "IF V1 = 11 LET V2 = 22";
117

  
118
        Compiler compiler = createCompiler();
119

  
120
        Code code = compiler.compileExpression(source);
121
        assertEquals("IFF((\"V1\" = 11), LET('V2', 22))", code.toString());
122
    }
123

  
124
    public void testIfThen3() {
125
        String source = "IF V1 = 11: LET V2 = 22";
126

  
127
        Compiler compiler = createCompiler();
128

  
129
        Code code = compiler.compileExpression(source);
130
        assertEquals("IFF((\"V1\" = 11), LET('V2', 22))", code.toString());
131
    }
132

  
133 114
    public void testIfThenElse() {
134
        String source = "IF V1 = 11 THEN LET V2 = 11 ELSE LET V2 = 22";
115
        String source = "IF V1 = 11 THEN LET V2 = 11; ELSE LET V2 = 22; END IF";
135 116

  
136 117
        Compiler compiler = createCompiler();
137 118

  
......
140 121
    }
141 122

  
142 123
    public void testIfThenBlock() {
143
        String source = "IF V1 = 11 THEN BEGIN LET V2 = 22; LET V1 = 10 END";
124
        String source = "IF V1 = 11 THEN LET V2 = 22; LET V1 = 10; END IF";
144 125

  
145 126
        Compiler compiler = createCompiler();
146 127

  
......
149 130
    }
150 131

  
151 132
    public void testWhile() {
152
        String source = "WHILE n < 10 LET n = n + 1";
133
        String source = "WHILE n < 10 BEGIN LET n = n + 1; END WHILE";
153 134

  
154 135
        Compiler compiler = createCompiler();
155 136

  
......
158 139
    }
159 140

  
160 141
    public void testWhileBlock() {
161
        String source = "WHILE n < 10 BEGIN LET n = n + 1; print(n) END";
142
        String source = "WHILE n < 10 BEGIN LET n = n + 1; print(n); END WHILE";
162 143

  
163 144
        Compiler compiler = createCompiler();
164 145

  
......
203 184
    }
204 185

  
205 186
    public void testForEach() {
206
        String source = "FOR n in RANGE(10) print(n)";
187
        String source = "FOR n in RANGE(10): print(n); END FOR";
207 188

  
208 189
        Compiler compiler = createCompiler();
209 190

  
......
221 202
//    }
222 203

  
223 204
    public void testCase() {
224
        String source = "CASE WHEN software LIKE '%gvSIG%' THEN 'gvSIG' ELSE 'Other' END"; // ;)
205
        String source = "CASE WHEN software LIKE '%gvSIG%' THEN 'gvSIG'; ELSE 'Other'; END CASE"; // ;)
225 206

  
226 207
        Compiler compiler = createCompiler();
227 208

  
......
230 211
    }
231 212

  
232 213
    public void testCase1() {
233
        String source = "CASE WHEN software LIKE '%gvSIG%' THEN 'gvSIG' ELSE 'Other'"; // ;)
214
        String source = "CASE WHEN software LIKE '%gvSIG%' THEN 'gvSIG'; ELSE 'Other'; END CASE"; // ;)
234 215

  
235 216
        Compiler compiler = createCompiler();
236 217

  
......
239 220
    }
240 221

  
241 222
    public void testCase2() {
242
        String source = "CASE WHEN Field_1 >= 75 AND Field_1 <=79 THEN 100 WHEN Field_1 >=80 AND Field_1 <=84 THEN 110 END"; // ;)
223
        String source = "CASE WHEN Field_1 >= 75 AND Field_1 <=79 THEN 100; WHEN Field_1 >=80 AND Field_1 <=84 THEN 110; END CASE"; // ;)
243 224

  
244 225
        Compiler compiler = createCompiler();
245 226

  
......
248 229
    }
249 230
    
250 231
    public void testCase3() {
251
        String source = "CASE WHEN Field_1 >= 75 AND Field_1 <=79 THEN 100 WHEN Field_1 >=80 AND Field_1 <=84 THEN 110 ELSE 120 END"; // ;)
232
        String source = "CASE WHEN Field_1 >= 75 AND Field_1 <=79 THEN 100; WHEN Field_1 >=80 AND Field_1 <=84 THEN 110; ELSE 120; END CASE"; // ;)
252 233

  
253 234
        Compiler compiler = createCompiler();
254 235

  
......
257 238
    }
258 239
    
259 240
    public void testDef1() {
260
        String source = "DEF test1() print('Hola')"; 
241
        String source = "CREATE FUNCTION test1() print('Hola'); END FUNCTION"; 
261 242

  
262 243
        Compiler compiler = createCompiler();
263 244

  
......
266 247
    }
267 248
    
268 249
    public void testDef2() {
269
        String source = "DEF test1(nombre) print('Hola '+nombre)";
250
        String source = "CREATE FUNCTION test1(nombre) print('Hola '+nombre); END FUNCTION";
270 251

  
271 252
        Compiler compiler = createCompiler();
272 253

  
......
275 256
    }
276 257

  
277 258
    public void testDef3() {
278
        String source = "DEF test1(nombre) BEGIN RETURN 'Hola '||nombre END";
259
        String source = "CREATE FUNCTION test1(nombre) RETURN 'Hola '||nombre; END FUNCTION";
279 260

  
280 261
        Compiler compiler = createCompiler();
281 262

  
282 263
        Code code = compiler.compileExpression(source);
283
        assertEquals("CREATE_FUNCTION('test1', LIST('nombre'), BLOCK(RETURN(('Hola ' || \"nombre\"))))", code.toString());
264
        assertEquals("CREATE_FUNCTION('test1', LIST('nombre'), RETURN(('Hola ' || \"nombre\")))", code.toString());
284 265
    }
285 266

  
286 267
    public void testUseCase1() {
287
        String source = "begin set x = ''; for n in list('hola','adios','fin'): let x = x || ' ' || n end";
268
        String source = "begin set x = ''; for n in list('hola','adios','fin'): let x = x || ' ' || n; end for; end";
288 269

  
289 270
        Compiler compiler = createCompiler();
290 271

  
......
293 274
    }
294 275

  
295 276
    public void testUseCase2() {
296
        String source = "begin set s = ''; set x = LIST('hola','adios','fin'); FOR n in RANGE(3): set s = s || ' ' || x[n] end";
277
        String source = "begin set s = ''; set x = LIST('hola','adios','fin'); FOR n in RANGE(3): set s = s || ' ' || x[n]; end for; end";
297 278

  
298 279
        Compiler compiler = createCompiler();
299 280

  

Also available in: Unified diff