Search in sources :

Example 1 with Base

use of org.mvel2.tests.core.res.Base in project mvel by mikebrock.

the class PropertyHandlerTests method testListPropertyHandler2.

public void testListPropertyHandler2() {
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
    Serializable s = MVEL.compileSetExpression("list[0]");
    Base b;
    MVEL.executeSetExpression(s, new Base(), "hey you");
    MVEL.executeSetExpression(s, b = new Base(), "hey you");
    assertEquals("set", b.list.get(0));
}
Also used : Serializable(java.io.Serializable) Base(org.mvel2.tests.core.res.Base)

Example 2 with Base

use of org.mvel2.tests.core.res.Base in project mvel by mikebrock.

the class PropertyHandlerTests method testListPropertyHandler3.

public void testListPropertyHandler3() {
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
    OptimizerFactory.setDefaultOptimizer("ASM");
    Serializable s = MVEL.compileSetExpression("list[0]");
    Base b;
    MVEL.executeSetExpression(s, new Base(), "hey you");
    MVEL.executeSetExpression(s, b = new Base(), "hey you");
    assertEquals("set", b.list.get(0));
}
Also used : Serializable(java.io.Serializable) Base(org.mvel2.tests.core.res.Base)

Example 3 with Base

use of org.mvel2.tests.core.res.Base in project mvel by mikebrock.

the class PropertyHandlerTests method testListPropertyHandler4.

public void testListPropertyHandler4() {
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
    OptimizerFactory.setDefaultOptimizer("ASM");
    final String[] res = new String[1];
    GlobalListenerFactory.registerGetListener(new Listener() {

        public void onEvent(Object context, String contextName, VariableResolverFactory variableFactory, Object value) {
            System.out.println("Listener Fired:" + contextName);
            res[0] = contextName;
        }
    });
    Serializable s = MVEL.compileSetExpression("list[0]");
    Base b;
    MVEL.executeSetExpression(s, new Base(), "hey you");
    res[0] = null;
    MVEL.executeSetExpression(s, b = new Base(), "hey you");
    assertEquals("set", b.list.get(0));
    assertEquals("list", res[0]);
}
Also used : Serializable(java.io.Serializable) Base(org.mvel2.tests.core.res.Base)

Example 4 with Base

use of org.mvel2.tests.core.res.Base in project mvel by mikebrock.

the class ProjectionsTests method testProjectionSupport3.

public void testProjectionSupport3() {
    String ex = "(toUpperCase() in ['bar', 'foo'])[1]";
    Map vars = createTestMap();
    assertEquals("FOO", MVEL.eval(ex, new Base(), vars));
    assertEquals("FOO", test("(toUpperCase() in ['bar', 'foo'])[1]"));
}
Also used : Map(java.util.Map) Base(org.mvel2.tests.core.res.Base)

Example 5 with Base

use of org.mvel2.tests.core.res.Base in project mvel by mikebrock.

the class TemplateTests method testInclusionOfNamedTemplate.

//    public void testTemplateFile2() {
//        String s = (String) TemplateRuntime.eval(new File("src/test/java/org/mvel2/tests/templates/templateDeclareTest.mv"),
//                base, new MapVariableResolverFactory(map), null);
//
//        System.out.println(s);
//
//    }
public void testInclusionOfNamedTemplate() {
    SimpleTemplateRegistry registry = new SimpleTemplateRegistry();
    registry.addNamedTemplate("footemplate", compileTemplate("@{_foo_}@{_bar_}"));
    registry.addNamedTemplate("bartemplate", compileTemplate("@{_bar_}@{_foo_}"));
    String s = "@includeNamed{'footemplate'}  ::  @includeNamed{'bartemplate'}";
    assertEquals("FooBar  ::  BarFoo", TemplateRuntime.eval(s, map, registry));
}
Also used : SimpleTemplateRegistry(org.mvel2.templates.SimpleTemplateRegistry)

Aggregations

Base (org.mvel2.tests.core.res.Base)8 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)5 Serializable (java.io.Serializable)4 Map (java.util.Map)3 CompiledExpression (org.mvel2.compiler.CompiledExpression)3 List (java.util.List)1 WeakHashMap (java.util.WeakHashMap)1 ParserContext (org.mvel2.ParserContext)1 Accessor (org.mvel2.compiler.Accessor)1 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)1 ArrayCreator (org.mvel2.optimizers.impl.refl.collection.ArrayCreator)1 ExprValueAccessor (org.mvel2.optimizers.impl.refl.collection.ExprValueAccessor)1 ListCreator (org.mvel2.optimizers.impl.refl.collection.ListCreator)1 MapCreator (org.mvel2.optimizers.impl.refl.collection.MapCreator)1 SimpleTemplateRegistry (org.mvel2.templates.SimpleTemplateRegistry)1 PropertyTools.getFieldOrAccessor (org.mvel2.util.PropertyTools.getFieldOrAccessor)1 PropertyTools.getFieldOrWriteAccessor (org.mvel2.util.PropertyTools.getFieldOrWriteAccessor)1 StringAppender (org.mvel2.util.StringAppender)1