@Test public void testNullLiteral() { String inputExpression = "null"; BaseNode nullLit = parse( inputExpression ); assertThat( nullLit, is( instanceOf( NullNode.class ) ) ); assertThat( nullLit.getResultType(), is( BuiltInType.UNKNOWN ) ); assertLocation( inputExpression, nullLit ); }
@Test public void testIntegerLiteral() { String inputExpression = "10"; BaseNode number = parse( inputExpression ); assertThat( number, is( instanceOf( NumberNode.class ) ) ); assertThat( number.getResultType(), is( BuiltInType.NUMBER ) ); assertLocation( inputExpression, number ); }
@Test public void testFloatLiteral() { String inputExpression = "10.5"; BaseNode number = parse( inputExpression ); assertThat( number, is( instanceOf( NumberNode.class ) ) ); assertThat( number.getResultType(), is( BuiltInType.NUMBER ) ); assertLocation( inputExpression, number ); }
@Test public void testBooleanTrueLiteral() { String inputExpression = "true"; BaseNode bool = parse( inputExpression ); assertThat( bool, is( instanceOf( BooleanNode.class ) ) ); assertThat( bool.getResultType(), is( BuiltInType.BOOLEAN ) ); assertLocation( inputExpression, bool ); }
@Test public void testBooleanFalseLiteral() { String inputExpression = "false"; BaseNode bool = parse( inputExpression ); assertThat( bool, is( instanceOf( BooleanNode.class ) ) ); assertThat( bool.getResultType(), is( BuiltInType.BOOLEAN ) ); assertLocation( inputExpression, bool ); }
@Test public void testStringLiteral() { String inputExpression = "\"some string\""; BaseNode stringLit = parse( inputExpression ); assertThat( stringLit, is( instanceOf( StringNode.class ) ) ); assertThat( stringLit.getResultType(), is( BuiltInType.STRING ) ); assertLocation( inputExpression, stringLit ); assertThat(stringLit.getText(), is(inputExpression)); }
@Test public void testNegativeIntegerLiteral() { String inputExpression = "-10"; BaseNode number = parse( inputExpression ); assertThat( number, is( instanceOf( SignedUnaryNode.class ) ) ); assertThat( number.getResultType(), is( BuiltInType.NUMBER ) ); assertLocation( inputExpression, number ); SignedUnaryNode sun = (SignedUnaryNode) number; assertThat( sun.getSign(), is( SignedUnaryNode.Sign.NEGATIVE ) ); assertThat( sun.getExpression(), is( instanceOf( NumberNode.class ) ) ); assertThat( sun.getExpression().getText(), is( "10" ) ); }
@Test public void testNameReference() { String inputExpression = "someSimpleName"; BaseNode nameRef = parse( inputExpression, mapOf( entry("someSimpleName", BuiltInType.STRING) ) ); assertThat( nameRef, is( instanceOf( NameRefNode.class ) ) ); assertThat( nameRef.getResultType(), is( BuiltInType.STRING ) ); assertLocation( inputExpression, nameRef ); }
@Test public void testNegativeFloatLiteral() { String inputExpression = "-10.5"; BaseNode number = parse( inputExpression ); assertThat( number, is( instanceOf( SignedUnaryNode.class ) ) ); assertThat( number.getResultType(), is( BuiltInType.NUMBER ) ); assertLocation( inputExpression, number ); SignedUnaryNode sun = (SignedUnaryNode) number; assertThat( sun.getSign(), is( SignedUnaryNode.Sign.NEGATIVE ) ); assertThat( sun.getExpression(), is( instanceOf( NumberNode.class ) ) ); assertThat( sun.getExpression().getText(), is( "10.5" ) ); }
@Test public void testPositiveIntegerLiteral() { String inputExpression = "+10"; BaseNode number = parse( inputExpression ); assertThat( number, is( instanceOf( SignedUnaryNode.class ) ) ); assertThat( number.getResultType(), is( BuiltInType.NUMBER ) ); assertLocation( inputExpression, number ); SignedUnaryNode sun = (SignedUnaryNode) number; assertThat( sun.getSign(), is( SignedUnaryNode.Sign.POSITIVE ) ); assertThat( sun.getExpression(), is( instanceOf( NumberNode.class ) ) ); assertThat( sun.getExpression().getText(), is( "10" ) ); }
@Test public void testPositiveFloatLiteral() { String inputExpression = "+10.5"; BaseNode number = parse( inputExpression ); assertThat( number, is( instanceOf( SignedUnaryNode.class ) ) ); assertThat( number.getResultType(), is( BuiltInType.NUMBER ) ); assertLocation( inputExpression, number ); SignedUnaryNode sun = (SignedUnaryNode) number; assertThat( sun.getSign(), is( SignedUnaryNode.Sign.POSITIVE ) ); assertThat( sun.getExpression(), is( instanceOf( NumberNode.class ) ) ); assertThat( sun.getExpression().getText(), is( "10.5" ) ); }
@Test public void testQualifiedName() { String inputExpression = "My Person.Full Name"; MapBackedType personType = new MapBackedType("Person", mapOf( entry("Full Name", BuiltInType.STRING), entry("Age", BuiltInType.NUMBER) ) ); BaseNode qualRef = parse( inputExpression, mapOf( entry("My Person", personType) ) ); assertThat( qualRef, is( instanceOf( QualifiedNameNode.class ) ) ); assertThat( qualRef.getResultType(), is( BuiltInType.STRING ) ); List<NameRefNode> parts = ((QualifiedNameNode) qualRef).getParts(); // `My Person` ... assertThat( parts.get(0), is( instanceOf( NameRefNode.class ) ) ); assertThat( parts.get(0).getResultType(), is( personType ) ); // ... `.Full Name` assertThat( parts.get(1), is( instanceOf( NameRefNode.class ) ) ); assertThat( parts.get(1).getResultType(), is( BuiltInType.STRING ) ); assertLocation( inputExpression, qualRef ); }