Esempio n. 1
0
        public void Handles_simple_unary2()
        {
            var parser = new ScriptParser("not b");
            var expr   = parser.ParseExpression();

            ScriptAssert.Nodes(expr, new TestUnary(UnaryOperator.Not, new TestIdentifier("b")));
        }
Esempio n. 2
0
        public void Handles_nested_parenthesis_precedence()
        {
            var parser = new ScriptParser("a + b * (c / (d - e))");
            var expr   = parser.ParseExpression();

            ScriptAssert.Nodes(expr,
                               new TestBinary(
                                   new TestIdentifier("a"),
                                   BinaryOperator.Add,
                                   new TestBinary(
                                       new TestIdentifier("b"),
                                       BinaryOperator.Multiply,
                                       new TestBinary(
                                           new TestIdentifier("c"),
                                           BinaryOperator.Divide,
                                           new TestBinary(
                                               new TestIdentifier("d"),
                                               BinaryOperator.Subtract,
                                               new TestIdentifier("e")
                                               )
                                           )
                                       )
                                   )
                               );
        }
Esempio n. 3
0
        public void Handles_simple_update_prefix2()
        {
            var parser = new ScriptParser("++b");
            var expr   = parser.ParseExpression();

            ScriptAssert.Nodes(expr, new TestUpdate(UpdateOperator.Increment, new TestIdentifier("b")));
        }
Esempio n. 4
0
        public void Assigns_correct_node_locations_define()
        {
            string source = "define amount-of-wood-a-woodchuck-would-chuck-if-a-woodchuck-could-chuck-wood = 0";
            var    parser = new ScriptParser(source);
            var    script = parser.Parse();

            var visitor = new FlatAstVisitor();

            visitor.Traverse(script);

            Assert.Collection(visitor.Nodes,
                              decl => ScriptAssert.NodeMatches(source, "define amount-of-wood-a-woodchuck-would-chuck-if-a-woodchuck-could-chuck-wood = 0", NodeType.Script, decl),
                              decl => ScriptAssert.NodeMatches(source, "define amount-of-wood-a-woodchuck-would-chuck-if-a-woodchuck-could-chuck-wood = 0", NodeType.DefineDeclaration, decl),
                              decl => ScriptAssert.NodeMatches(source, "amount-of-wood-a-woodchuck-would-chuck-if-a-woodchuck-could-chuck-wood", NodeType.Identifier, decl),
                              decl => ScriptAssert.NodeMatches(source, "0", NodeType.Literal, decl)
                              );
        }
Esempio n. 5
0
        public void Assigns_correct_node_locations_short_timeevent()
        {
            string source = @"on time 7.200: poke-largo";
            var    parser = new ScriptParser(source);
            var    script = parser.Parse();

            var visitor = new FlatAstVisitor();

            visitor.Traverse(script);

            Assert.Collection(visitor.Nodes,
                              decl => ScriptAssert.NodeMatches(source, source, NodeType.Script, decl),
                              decl => ScriptAssert.NodeMatches(source, source, NodeType.EventDeclaration, decl),
                              decl => ScriptAssert.NodeMatches(source, "time 7.200", NodeType.TimeEventDeclarator, decl),
                              decl => ScriptAssert.NodeMatches(source, "7.200", NodeType.Literal, decl),
                              decl => ScriptAssert.NodeMatches(source, "poke-largo", NodeType.Identifier, decl)
                              );
        }
Esempio n. 6
0
        public void Assigns_correct_node_locations_action()
        {
            string source = @"action my-action during woodtick-theme {
}".NormalizeNewLines();
            var    parser = new ScriptParser(source);
            var    script = parser.Parse();

            var visitor = new FlatAstVisitor();

            visitor.Traverse(script);

            Assert.Collection(visitor.Nodes,
                              decl => ScriptAssert.NodeMatches(source, source, NodeType.Script, decl),
                              decl => ScriptAssert.NodeMatches(source, source, NodeType.ActionDeclaration, decl),
                              decl => ScriptAssert.NodeMatches(source, "my-action", NodeType.Identifier, decl),
                              decl => ScriptAssert.NodeMatches(source, "woodtick-theme", NodeType.Identifier, decl),
                              decl => ScriptAssert.NodeMatches(source, "{\n}", NodeType.BlockStatement, decl)
                              );
        }
Esempio n. 7
0
        public void Handles_simple_precedence()
        {
            var parser = new ScriptParser("a + b * c - d");
            var expr   = parser.ParseExpression();

            ScriptAssert.Nodes(expr,
                               new TestBinary(
                                   new TestBinary(
                                       new TestIdentifier("a"),
                                       BinaryOperator.Add,
                                       new TestBinary(
                                           new TestIdentifier("b"),
                                           BinaryOperator.Multiply,
                                           new TestIdentifier("c")
                                           )
                                       ),
                                   BinaryOperator.Subtract,
                                   new TestIdentifier("d")
                                   )
                               );
        }
Esempio n. 8
0
        public void Assigns_correct_node_locations_multiline_call()
        {
            string source = @"action {
    start-music \
        woodtick-theme
}".NormalizeNewLines();
            var    parser = new ScriptParser(source);
            var    script = parser.Parse();

            var visitor = new FlatAstVisitor();

            visitor.Traverse(script);

            Assert.Collection(visitor.Nodes,
                              decl => ScriptAssert.NodeMatches(source, source, NodeType.Script, decl),
                              decl => ScriptAssert.NodeMatches(source, source, NodeType.ActionDeclaration, decl),
                              decl => ScriptAssert.NodeMatches(source, "{\n    start-music \\\n        woodtick-theme\n}", NodeType.BlockStatement, decl),
                              decl => ScriptAssert.NodeMatches(source, "start-music \\\n        woodtick-theme", NodeType.ExpressionStatement, decl),
                              decl => ScriptAssert.NodeMatches(source, "start-music \\\n        woodtick-theme", NodeType.CallExpression, decl),
                              decl => ScriptAssert.NodeMatches(source, "start-music", NodeType.Identifier, decl),
                              decl => ScriptAssert.NodeMatches(source, "woodtick-theme", NodeType.Identifier, decl)
                              );
        }
Esempio n. 9
0
        public void Assigns_correct_node_locations_sounds()
        {
            string source = @"sounds {
    'lechuck' lechuck
    'woodchuck' woodchuck
}";
            var    parser = new ScriptParser(source);
            var    script = parser.Parse();

            var visitor = new FlatAstVisitor();

            visitor.Traverse(script);

            Assert.Collection(visitor.Nodes,
                              decl => ScriptAssert.NodeMatches(source, source, NodeType.Script, decl),
                              decl => ScriptAssert.NodeMatches(source, source, NodeType.SoundsDeclaration, decl),
                              decl => ScriptAssert.NodeMatches(source, "'lechuck' lechuck", NodeType.SoundDeclarator, decl),
                              decl => ScriptAssert.NodeMatches(source, "'lechuck'", NodeType.Literal, decl),
                              decl => ScriptAssert.NodeMatches(source, "lechuck", NodeType.Identifier, decl),
                              decl => ScriptAssert.NodeMatches(source, "'woodchuck' woodchuck", NodeType.SoundDeclarator, decl),
                              decl => ScriptAssert.NodeMatches(source, "'woodchuck'", NodeType.Literal, decl),
                              decl => ScriptAssert.NodeMatches(source, "woodchuck", NodeType.Identifier, decl)
                              );
        }