public void ShouldIdentifyRightParentheseAsToken()
            {
                const string Code = " ) ";

                var lexer = new ScriptLexer(Code);
                var token = lexer.GetToken();

                token.Token.ShouldEqual(Token.RightParenthese);
            }
            public void ShouldIdentifySemiColonAsToken()
            {
                const string Code = " ; ";

                var lexer = new ScriptLexer(Code);
                var token = lexer.GetToken();

                token.Token.ShouldEqual(Token.SemiColon);
            }
            public void ShouldIdentifyRightBracketAsToken()
            {
                const string Code = " } ";

                var lexer = new ScriptLexer(Code);
                var token = lexer.GetToken();

                token.Token.ShouldEqual(Token.RightBracket);
            }
            public void ShouldIdentifyIdentifiersAsToken()
            {
                const string Code = " id ";

                var lexer = new ScriptLexer(Code);
                var token = lexer.GetToken();

                token.Token.ShouldEqual(Token.Identifier);
                token.TokenValue.ShouldEqual("id");
            }
            public void ShouldIdentifyStringsAsToken()
            {
                const string Code = "\"This is a string\"";

                var lexer = new ScriptLexer(Code);
                var token = lexer.GetToken();

                token.Token.ShouldEqual(Token.String);
                token.Start.ShouldEqual(0);
                token.End.ShouldEqual(18);
                token.TokenValue.ShouldEqual(Code);
            }
Beispiel #6
0
 public List<RegionResult> Parse(string code)
 {
     _lexer = new ScriptLexer(code);
     _current = _lexer.GetToken();
     return GetRegionBlocks();
 }
            public void ShouldIdentifyWhileAsToken()
            {
                const string Code = "while(true); ";

                var lexer = new ScriptLexer(Code);
                var token = lexer.GetToken();

                token.Token.ShouldEqual(Token.While);
                token.TokenValue.ShouldEqual("while");
            }
            public void ShouldReturnTokenRegion()
            {
                const string Code = " id<T> ";

                var lexer = new ScriptLexer(Code);
                var result = lexer.GetToken();

                result.Start.ShouldEqual(1);
                result.End.ShouldEqual(3);

                result = lexer.GetToken();   //<
                result.Start.ShouldEqual(3);
                result.End.ShouldEqual(4);
            }
            public void ShouldRemoveMultiLineComments()
            {
                const string Code = " { /* This is \n removed */ } ";

                var lexer = new ScriptLexer(Code);

                var token = lexer.GetToken();
                token.Token.ShouldEqual('{');

                token = lexer.GetToken();
                token.Token.ShouldEqual('}');

                token = lexer.GetToken();
                token.Token.ShouldEqual(Token.Eof);
            }
Beispiel #10
0
            public void ShouldRemoveSingleLineComments()
            {
                const string Code = " { // This is removed \n } ";

                var lexer = new ScriptLexer(Code);

                var token = lexer.GetToken();
                token.Token.ShouldEqual('{');

                token = lexer.GetToken();
                token.Token.ShouldEqual('}');

                token = lexer.GetToken();
                token.Token.ShouldEqual(Token.Eof);
            }
Beispiel #11
0
            public void ShouldIdentifyUnlexedAsThemselves()
            {
                const string Code = " < ";

                var lexer = new ScriptLexer(Code);
                var token = lexer.GetToken();

                token.Token.ShouldEqual('<');
            }
Beispiel #12
0
            public void ShouldNotFailOnIdentifyingCharactersAsToken()
            {
                const string Code = "\'A";

                var lexer = new ScriptLexer(Code);
                var token = lexer.GetToken();

                token.Token.ShouldEqual(Token.Character);
                token.Start.ShouldEqual(0);
                token.End.ShouldEqual(2);
                token.TokenValue.ShouldEqual(Code);
            }
Beispiel #13
0
            public void ShouldIdenityCharactersAsToken()
            {
                const string Code = "\'A\'";

                var lexer = new ScriptLexer(Code);
                var token = lexer.GetToken();

                token.Token.ShouldEqual(Token.Character);
                token.Start.ShouldEqual(0);
                token.End.ShouldEqual(3);
                token.TokenValue.ShouldEqual(Code);
            }
Beispiel #14
0
            public void ShouldIdentifyStringsWithEscapeChars()
            {
                const string Code = "\"AssemblyInformationalVersion(\\\"\"";

                var lexer = new ScriptLexer(Code);
                var token = lexer.GetToken();

                token.Token.ShouldEqual(Token.String);
                token.TokenValue.ShouldEqual(Code);
            }