Refine search
@Test public void test1() { final ParserContext pc = new ParserContext(); pc.addInput("x", String.class); pc.setStrongTyping(true); final Object o = MVEL.compileExpression("x.startsWith('d')", pc); final Map vars = new HashMap(); vars.put("x", "d"); MVEL.executeExpression(o, vars); System.out.println(o); }
private void testMVELTyped(String text) { String str = IMPORTS + text; ParserContext pctx = new ParserContext(); pctx.setStrongTyping(true); Map<String, Object> vars = new HashMap<String, Object>(); Object o = MVEL.compileExpression(str, pctx); MVEL.executeExpression(o, vars); }
private ParserContext ctxJIRA170(boolean strictTypeEnforcement, boolean strongTyping) { ParserContext ctx = new ParserContext(); // ctx.setStrictTypeEnforcement(strictTypeEnforcement); ctx.setStrongTyping(strongTyping); ctx.addInput("x", Collection.class, new Class[]{Integer.class}); ctx.addInput("y", Integer.class); return ctx; }
public void testShouldFail7() { try { ParserContext pctx = new ParserContext(); pctx.setStrongTyping(true); MVEL.compileExpression("String x = 'foo'; int y = 2; new int[] { x, y }", pctx); } catch (Exception e) { // e.printStackTrace(); return; } shouldThrowException(); }
public void testParameterizedTypeInStrictMode3() { ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.addInput("base", Base.class); ExpressionCompiler compiler = new ExpressionCompiler("base.list"); // assertTrue(compiler.compile(ctx).getParserContext().getLastTypeParameters()[0].equals(String.class)); }
public void testVarArgs() throws Exception { ParserContext parserContext = new ParserContext(); parserContext.setStrictTypeEnforcement(true); parserContext.setStrongTyping(true); MVEL.analyze("String.format(\"\");", parserContext); }
public void testArrayLength() { ParserContext context = new ParserContext(); context.setStrongTyping(true); context.addInput("x", String[].class); ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("x.length", context); }
public void testPippo() { final ParserContext parserContext = new ParserContext(); parserContext.setStrongTyping(true); assertEquals(String.class, MVEL.analyze("new String(\"b)ar\")", parserContext)); }
public void testArrayLength() { ParserContext context = new ParserContext(); context.setStrongTyping(true); context.addInput("x", String[].class); ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("x.length", context); }
public void testShouldFail6() { try { ParserContext pctx = new ParserContext(); pctx.setStrongTyping(true); MVEL.compileExpression("new int[] {1.5}", pctx); } catch (Exception e) { return; } shouldThrowException(); }
public void testRegExWithCast() { final ParserContext parserContext = new ParserContext(); parserContext.setStrongTyping(true); parserContext.addInput("this", Foo.class); assertEquals(Boolean.class, MVEL.analyze("(String)bar.name ~= '[a-z].+'", parserContext)); }
public void testShouldFail8() { try { ParserContext pCtx = new ParserContext(); pCtx.setStrongTyping(true); MVEL.compileExpression("for (String s : new java.util.HashMap()) { }", pCtx); } catch (Exception e) { // e.printStackTrace(); return; } shouldThrowException(); }
public void testParameterizedTypeInStrictMode() { ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.addInput("foo", HashMap.class, new Class[]{String.class, String.class}); ExpressionCompiler compiler = new ExpressionCompiler("foo.get('bar').toUpperCase()", ctx); compiler.compile(); }
public void testReturnBoolean() { String ex = "list = new java.util.ArrayList(); return list != null"; ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); Serializable s = compileExpression(ex, ctx); assertEquals(true, executeExpression(s, new HashMap())); }
public void testUppercaseField() { String ex = "Field1 == \"foo\" || FIELD2 == \"bar\""; final ParserContext parserContext2 = new ParserContext(); parserContext2.setStrictTypeEnforcement(true); parserContext2.setStrongTyping(true); parserContext2.addInput("this", Bean1.class); MVEL.analyze(ex, parserContext2); }
public void testArrays() { String str = "Object[] a = new Object[3]; a[0] = \"a\"; a[1] = \"b\"; a[2] = \"c\"; System.out.println(java.util.Arrays.toString(a));"; ParserConfiguration pconf = new ParserConfiguration(); ParserContext pctx = new ParserContext(pconf); pctx.setStrongTyping(true); ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx); MVEL.executeExpression(stmt, new HashMap()); }
public void testClassLiteral() { try { MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true; final ParserContext parserContext = new ParserContext(); parserContext.setStrictTypeEnforcement(true); parserContext.setStrongTyping(true); parserContext.addInput("a", Class.class); MVEL.compileExpression("a == String", parserContext); } finally { MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = false; } }
public void testEmpty() { ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); Serializable s = compileExpression("list = new java.util.ArrayList(); list == empty", ctx); Map vars = new HashMap(); Boolean x = (Boolean) executeExpression(s, vars); assertNotNull(x); assertTrue(x.booleanValue()); }
public void testAnalyzeTernary() { final ParserContext parserContext = new ParserContext(); parserContext.setStrictTypeEnforcement(true); parserContext.setStrongTyping(true); parserContext.addInput("value", String.class); parserContext.addInput("x", Integer.class); parserContext.addInput("y", Integer.class); parserContext.addInput("z", Integer.class); Class<?> clazz = MVEL.analyze("z = (value == \"ALU\" ? x : y);", parserContext); assertEquals(Integer.class, clazz); }
public void testForLoopWithVar() { String str = "int height = 100; int j = 0; for (i = 0; i < height; i++) {j++ }; return j;"; ParserConfiguration pconf = new ParserConfiguration(); ParserContext pctx = new ParserContext(pconf); pctx.setStrongTyping(true); ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx); Map vars = new HashMap(); assertEquals(new Integer(100), MVEL.executeExpression(stmt, vars)); }