Package org.auraframework.expression

Examples of org.auraframework.expression.Expression


    /**
     * Number literals include integers, decimals, and exponents.
     */
    public void testLiteralNumbers() throws Exception {
        Expression e = buildExpression("5");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        LiteralImpl l = (LiteralImpl) e;
        assertEquals("Unexpected number literal value", 5.0, l.getValue());

        e = buildExpression("5.345");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Unexpected number literal value", 5.345, l.getValue());

        e = buildExpression("911.");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Unexpected number literal value", 911., l.getValue());

        e = buildExpression(".119");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Unexpected number literal value", .119, l.getValue());

        e = buildExpression("1e10");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Unexpected number literal value", 1e10, l.getValue());

        e = buildExpression("2.e20");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Unexpected number literal value", 2.e20, l.getValue());

        e = buildExpression("0e0");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Unexpected number literal value", 0e0, l.getValue());

        e = buildExpression("1e01");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Unexpected number literal value", 1e01, l.getValue());

        e = buildExpression(".3e3");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Unexpected number literal value", .3e3, l.getValue());
    }
View Full Code Here


    /**
     * String literals require single quotes and may be empty.
     */
    public void testLiteralStrings() throws Exception {
        Expression e = buildExpression("'ahfdh'");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        LiteralImpl l = (LiteralImpl) e;
        assertEquals("ahfdh", l.getValue());

        verifyInvalidExpressionException("\"ahfdh\"", "unexpected token: '\"' at column 1 of expression: \"ahfdh\"");

        e = buildExpression("''");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("", l.getValue());
    }
View Full Code Here

    /**
     * Boolean literals are case insensitive.
     */
    public void testLiteralBools() throws Exception {
        Expression e = buildExpression("true");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        LiteralImpl l = (LiteralImpl) e;
        assertTrue("Case sensitivity of Boolean literlas failed", l.getValue());

        e = buildExpression("TRUE");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertTrue("Case sensitivity of Boolean literlas failed", l.getValue());

        e = buildExpression("false");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertFalse("Case sensitivity of Boolean literlas failed", l.getValue());

        e = buildExpression("FALSE");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertFalse("Case sensitivity of Boolean literlas failed", l.getValue());
    }
View Full Code Here

    /**
     * Property references can have multiple parts.
     */
    public void testPropertyReference() throws Exception {
        Expression e = buildExpression("im");
        assertEquals("Unexpected expression type", ExpressionType.PROPERTY, e.getExpressionType());
        PropertyReference pr = (PropertyReference) e;
        assertEquals("Unexpected root of PropertyReference", "im", pr.getRoot());
        assertNull("Stemming end of PropertyReference should return null", pr.getStem());

        e = buildExpression("im.parsing");
        assertEquals("Unexpected expression type", ExpressionType.PROPERTY, e.getExpressionType());
        pr = (PropertyReferenceImpl) e;
        assertEquals("Unexpected root of PropertyReference", "im", pr.getRoot());
        pr = pr.getStem();
        assertEquals("Unexpected root of PropertyReference after stemming", "parsing", pr.getRoot());
        assertNull("Stemming end of PropertyReference should return null", pr.getStem());

        e = buildExpression("im.not.nullish");
        assertEquals("Unexpected expression type", ExpressionType.PROPERTY, e.getExpressionType());
        pr = (PropertyReferenceImpl) e;
        assertEquals("Unexpected root of PropertyReference", "im", pr.getRoot());
        pr = pr.getStem();
        assertEquals("Unexpected root of PropertyReference after stemming", "not", pr.getRoot());
        pr = pr.getStem();
        assertEquals("Unexpected root of PropertyReference after stemming twice", "nullish", pr.getRoot());
        assertNull("Stemming end of PropertyReference should return null", pr.getStem());

        e = buildExpression("_i.am_very._.readable_");
        assertEquals("Unexpected expression type", ExpressionType.PROPERTY, e.getExpressionType());
        pr = (PropertyReferenceImpl) e;
        assertEquals("Unexpected root of PropertyReference", "_i", pr.getRoot());
        pr = pr.getStem();
        assertEquals("Unexpected root of PropertyReference after stemming", "am_very", pr.getRoot());
        pr = pr.getStem();
View Full Code Here

    /**
     * Property references can access array members
     */
    public void testArrayAccessors() throws Exception {
        Expression e = buildExpression("im[0]");
        assertEquals("Unexpected expression type", ExpressionType.PROPERTY, e.getExpressionType());
        PropertyReference pr = (PropertyReference) e;
        assertEquals("Unexpected root of PropertyReference", "im", pr.getRoot());
        pr = pr.getStem();
        assertEquals("Unable to access array member via PropertyReference", "0", pr.getRoot());
        assertNull("Stemming end of PropertyReference should return null", pr.getStem());

        e = buildExpression("im.an[3151345]");
        assertEquals("Unexpected expression type", ExpressionType.PROPERTY, e.getExpressionType());
        pr = (PropertyReference) e;
        assertEquals("Unexpected root of PropertyReference", "im", pr.getRoot());
        pr = pr.getStem();
        assertEquals("Unexpected root of PropertyReference after stemming", "an", pr.getRoot());
        pr = pr.getStem();
        assertEquals("Unable to access array member via PropertyReference after stemming", "3151345", pr.getRoot());
        assertNull("Stemming end of PropertyReference should return null", pr.getStem());

        e = buildExpression("im.an[3151345].array");
        assertEquals("Unexpected expression type", ExpressionType.PROPERTY, e.getExpressionType());
        pr = (PropertyReference) e;
        assertEquals("Unexpected root of PropertyReference", "im", pr.getRoot());
        pr = pr.getStem();
        assertEquals("Unexpected root of PropertyReference after stemming", "an", pr.getRoot());
        pr = pr.getStem();
        assertEquals("Unable to access array member via PropertyReference after stemming", "3151345", pr.getRoot());
        pr = pr.getStem();
        assertEquals("Unexpected root of PropertyReference after stemming and accessing array", "array", pr.getRoot());
        assertNull("Stemming end of PropertyReference should return null", pr.getStem());

        e = buildExpression("multi[1][364]");
        assertEquals("Unexpected expression type", ExpressionType.PROPERTY, e.getExpressionType());
        pr = (PropertyReference) e;
        assertEquals("Unexpected root of PropertyReference", "multi", pr.getRoot());
        pr = pr.getStem();
        assertEquals("Unable to access array member via PropertyReference", "1", pr.getRoot());
        pr = pr.getStem();
View Full Code Here

    /**
     * Escape sequences in strings are parsed correctly.
     */
    public void testEscapedString() throws Exception {
        Expression e = buildExpression("\t'over there! '\r\n\n");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        LiteralImpl l = (LiteralImpl) e;
        assertEquals("Escape sequences not parsed correctly", "over there! ", l.getValue());

        e = buildExpression(" '\\'stuff me,\\' the unfilled teddy bear said to the child.'");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Escape sequences not parsed correctly", "'stuff me,' the unfilled teddy bear said to the child.",
                l.getValue());

        e = buildExpression("'the child blinked and replied,\\n \\t\\'I\\'d be delighted.\\''");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Escape sequences not parsed correctly", "the child blinked and replied,\n \t'I'd be delighted.'",
                l.getValue());

        e = buildExpression("'top\\\\\\\"2\\\"\\b\\f\\r\\n\\tbottom'");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Escape sequences not parsed correctly", "top\\\"2\"\b\f\r\n\tbottom", l.getValue());
    }
View Full Code Here

    /**
     * Unicode escapes in strings are parsed correctly.
     */
    public void testUnicodeEscapesInString() throws Exception {
        Expression e = buildExpression("'\\u0032'");
        assertEquals(ExpressionType.LITERAL, e.getExpressionType());
        LiteralImpl l = (LiteralImpl) e;
        assertEquals("2", l.getValue());

        e = buildExpression("'good\\u0032go'");
        assertEquals(ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("good2go", l.getValue());

        e = buildExpression("'Ocean\\'s \\u0031\\u0031'");
        assertEquals(ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("Ocean's 11", l.getValue());

        e = buildExpression("'\\u0031\\u0032\\u0020Monkeys\\u0020\\u0099'");
        assertEquals(ExpressionType.LITERAL, e.getExpressionType());
        l = (LiteralImpl) e;
        assertEquals("12 Monkeys \u0099", l.getValue());
    }
View Full Code Here

    /**
     * Operators may be accessed as function calls and may be nested.
     */
    public void testFunctionCalls() throws Exception {
        Expression e = buildExpression("or(true, false)");
        assertTrue("Operator could not be accessed as function call", e.evaluate(null));
        e = buildExpression("and(false, true)");
        assertFalse("Operator could not be accessed as function call", e.evaluate(null));
        e = buildExpression("add(24, 23525)");
        assertEquals("Operator could not be accessed as function call", 24 + 23525, e.evaluate(null));

        e = buildExpression("sub(24, add(63, 23525))");
        assertEquals("Error evaluating nested operators as function calls", 24.0 - (63 + 23525), e.evaluate(null));

        e = buildExpression("add('The child', ' picked up the teddy bear in one hand')");
        assertEquals("Error adding strings with add operator as function call",
                "The child picked up the teddy bear in one hand", e.evaluate(null));

        e = buildExpression("notequals(add(' and grasped a', ' pick axe in the other.'), '\"Wait!\" screamed the bear.')");
        assertTrue("Error in evaluating nested operators as funtion calls", e.evaluate(null));

        e = buildExpression("if(equals(true, greaterthan(-2, -52)), add('The child hesitated, ', '\"I cannot stuff you without making a hole to stuff into.\"'), ' The bear squinted and noodled on this for a minute.')");
        assertEquals("Error in evaluating nested operators as funtion calls",
                "The child hesitated, \"I cannot stuff you without making a hole to stuff into.\"", e.evaluate(null));
    }
View Full Code Here

    /**
     * Non-english string literals are parsed correctly.
     */
    public void testNonEnglishString() throws Exception {
        Expression e = buildExpression("'天ぷらが食べたいです'");
        assertEquals("Unexpected expression type", ExpressionType.LITERAL, e.getExpressionType());
        assertEquals("Unexpected evaluation of non-english string", "天ぷらが食べたいです", e.evaluate(null));
    }
View Full Code Here

TOP

Related Classes of org.auraframework.expression.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.