use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class AviatorPatternUnitTest method testMatchString.
@Test
public void testMatchString() {
Env env = TestUtils.getTestEnv();
AviatorPattern p1 = new AviatorPattern("[a-zA-Z]+");
assertTrue((Boolean) p1.match(new AviatorString("hello"), env).getValue(env));
assertFalse((Boolean) p1.match(new AviatorString("hello world"), env).getValue(env));
}
use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class AviatorPatternUnitTest method testPatternGroup.
@Test
public void testPatternGroup() {
//
AviatorPattern p1 = new AviatorPattern("-\\d+\\.\\d+");
Env env = TestUtils.getTestEnv();
p1.match(new AviatorString("-3.4"), env);
assertEquals(1, env.size());
assertEquals("-3.4", env.get("$0"));
p1 = new AviatorPattern("^(-?\\d+)(\\.\\d+)?$");
env.clear();
p1.match(new AviatorString("-3.4"), env);
assertEquals(3, env.size());
assertEquals("-3.4", env.get("$0"));
assertEquals("-3", env.get("$1"));
assertEquals(".4", env.get("$2"));
// Disable putting capturing groups into env
try {
AviatorEvaluator.setOption(Options.PUT_CAPTURING_GROUPS_INTO_ENV, false);
env.clear();
assertTrue(p1.match(new AviatorString("-3.4"), env).booleanValue(env));
assertEquals(0, env.size());
} finally {
AviatorEvaluator.setOption(Options.PUT_CAPTURING_GROUPS_INTO_ENV, true);
}
}
use of com.googlecode.aviator.utils.Env in project aviatorscript by killme2008.
the class TestScripts method testUseStatement.
@Test
public void testUseStatement() {
Env env = (Env) testScript("use1.av", "Long", Long.class);
assertNotNull(env);
List<String> symbols = env.getImportedSymbols();
assertNotNull(symbols);
assertEquals(2, symbols.size());
assertTrue(symbols.contains("com.googlecode.aviator.runtime.type.AviatorObject"));
assertTrue(symbols.contains("java.util.List"));
testScript("use2.av");
testScript("use3.av");
testScript("use4.av");
try {
testScript("use5.av");
fail();
} catch (ExpressionSyntaxErrorException e) {
assertTrue(e.getMessage().contains("expect variable name or * to use at"));
}
}
Aggregations