Exemplo n.º 1
0
        public void IfEquals()
        {
            List <List <Token> > tokens = new List <List <Token> >()
            {
                LexerTestBase.GetTokensForScript("if (a == b) {}"),
                LexerTestBase.GetTokensForScript("if(a==b){}"),
                LexerTestBase.GetTokensForScript("if(a == b){}"),
                LexerTestBase.GetTokensForScript("if (a==b) {}"),
                LexerTestBase.GetTokensForScript("if (aasdf==basdf) {}"),
                LexerTestBase.GetTokensForScript("if( aasdf == basdf ){}"),
                LexerTestBase.GetTokensForScript("if(aasdf==basdf){}"),
            };

            List <Signature> signatures = new List <Signature> {
                Signature.KW_IF,
                Signature.LPAREN,
                Signature.IDENTIFIER,
                Signature.OP_EQUALS,
                Signature.IDENTIFIER,
                Signature.RPAREN,
                Signature.LBRACE,
                Signature.RBRACE
            };

            foreach (var token in tokens)
            {
                var parsedSignatures = token.Select(a => a.Signature).ToList();
                Assert.AreEqual(signatures, parsedSignatures);
            }
        }
Exemplo n.º 2
0
        public void Assignation()
        {
            List <List <Token> > tokens = new List <List <Token> >()
            {
                LexerTestBase.GetTokensForScript("int i = 0;"),
                LexerTestBase.GetTokensForScript("float f = 1.22f;"),
                LexerTestBase.GetTokensForScript(@"string s = ""test"";")
            };

            List <List <Signature> > signatures = new List <List <Signature> >
            {
                new List <Signature>()
                {
                    TYPENAME, IDENTIFIER, OP_ASSIGN, I_CONST, END
                },
                new List <Signature>()
                {
                    TYPENAME, IDENTIFIER, OP_ASSIGN, F_CONST, END
                },
                new List <Signature>()
                {
                    TYPENAME, IDENTIFIER, OP_ASSIGN, STRINGLITTERAL, END
                }
            };

            for (int i = 0; i < tokens.Count; i++)
            {
                var parsed = tokens[i].Select(a => a.Signature).ToList();
                Assert.AreEqual(signatures[i], parsed);
            }
        }
Exemplo n.º 3
0
        public void ForBlock()
        {
            List <List <Token> > tokens = new List <List <Token> >()
            {
                LexerTestBase.GetTokensForScript("for(int i = 0; i > 0; i++)"),
            };

            List <Signature> signatures = new List <Signature> {
                Signature.KW_FOR,
                Signature.LPAREN,
                Signature.TYPENAME,
                Signature.IDENTIFIER,
                Signature.OP_ASSIGN,
                Signature.I_CONST,
                Signature.END,
                Signature.IDENTIFIER,
                Signature.OP_GREATER_THAN,
                Signature.I_CONST,
                Signature.END,
                Signature.IDENTIFIER,
                Signature.OP_INCREMENT,
                Signature.RPAREN
            };

            foreach (var token in tokens)
            {
                var parsedSignatures = token.Select(a => a.Signature).ToList();
                Assert.AreEqual(signatures, parsedSignatures);
            }
        }
Exemplo n.º 4
0
        public void ReturnNothingStatement()
        {
            List <Token>     tokens     = LexerTestBase.GetTokensForScript("return;");
            List <Signature> signatures = new List <Signature>()
            {
                Signature.KW_RETURN,
                Signature.END
            };

            var parsedSignatures = tokens.Select(a => a.Signature).ToList();

            Assert.AreEqual(signatures, parsedSignatures);
        }
Exemplo n.º 5
0
        public void ReturnStringConstStatement()
        {
            List <Token>     tokens     = LexerTestBase.GetTokensForScript(@"return ""Hello world"";");
            List <Signature> signatures = new List <Signature>()
            {
                Signature.KW_RETURN,
                Signature.STRINGLITTERAL,
                Signature.END
            };

            var parsedSignatures = tokens.Select(a => a.Signature).ToList();

            Assert.AreEqual(signatures, parsedSignatures);
        }
Exemplo n.º 6
0
        public void Increment()
        {
            List <Token> tokens = LexerTestBase.GetTokensForScript("i++");

            List <Signature> signatures = new List <Signature>
            {
                Signature.IDENTIFIER,
                Signature.OP_INCREMENT
            };

            var parsedSignatures = tokens.Select(a => a.Signature).ToList();

            Assert.AreEqual(signatures, parsedSignatures);
        }
Exemplo n.º 7
0
        public void Not()
        {
            List <List <Token> > tokens = new List <List <Token> >()
            {
                LexerTestBase.GetTokensForScript("!az"),
                LexerTestBase.GetTokensForScript("! az"),
            };

            List <Signature> signatures = new List <Signature>
            {
                Signature.OP_NOT,
                Signature.IDENTIFIER
            };

            foreach (var token in tokens)
            {
                var parsedSignatures = token.Select(a => a.Signature).ToList();
                Assert.AreEqual(signatures, parsedSignatures);
            }
        }