public void TestStringEscapedConstantTooShort()
        {
            var code = "\"\\";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();

            Assert.Throws <StringConstantException>(() => tokenizer.EnumerateTokens(code.AsSpan()));
        }
Exemplo n.º 2
0
        public void TestCharConstantEmptyNotLastInFile()
        {
            var code = @"
'';";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();

            Assert.Throws <CharacterConstantException>(() => tokenizer.EnumerateTokens(code.AsSpan()));
        }
Exemplo n.º 3
0
        public void TestInvalidCharacterToken()
        {
            var code = @"
abc@";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();

            Assert.Throws <InvalidTokenParsingException>(() => tokenizer.EnumerateTokens(code.AsSpan()));
        }
Exemplo n.º 4
0
        public void TestCharConstantBadEscape3()
        {
            var code = @"
'\ab";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();

            Assert.Throws <CharacterConstantException>(() => tokenizer.EnumerateTokens(code.AsSpan()));
        }
Exemplo n.º 5
0
        public void TestCharConstantBadEscape2()
        {
            var code = @"
'\;'";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();

            Assert.Throws <UnrecognizedEscapeException>(() => tokenizer.EnumerateTokens(code.AsSpan()));
        }
Exemplo n.º 6
0
        public void TestTokenizerBeginsWithWhitespace()
        {
            var code = @"
    ;";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();
            var        tokens    = tokenizer.EnumerateTokens(code.AsSpan());

            Assert.Equal(1, tokens.Length);
            Assert.IsType <SemiColonToken>(tokens[0]);
        }
Exemplo n.º 7
0
        public void TestTokenizerEndsWithIdentifier()
        {
            var code = @"
    abc";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();
            var        tokens    = tokenizer.EnumerateTokens(code.AsSpan());

            Assert.Equal(1, tokens.Length);
            Assert.IsType <IdentifierToken>(tokens[0]);
            Assert.Equal("abc", ((IdentifierToken)tokens[0]).Name);
        }
        public void TestEscapedString(string input, string result)
        {
            var code = $@"
""{input}""";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();
            var        tokens    = tokenizer.EnumerateTokens(code.AsSpan());

            Assert.Equal(1, tokens.Length);
            var charConstToken = Assert.IsType <StringConstantToken>(tokens[0]);

            Assert.Equal(result, charConstToken.Value);
        }
        public void TestStringConstantEmptyWorks()
        {
            var code = @"
""""";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();
            var        tokens    = tokenizer.EnumerateTokens(code.AsSpan());

            Assert.Equal(1, tokens.Length);
            var charConstToken = Assert.IsType <StringConstantToken>(tokens[0]);

            Assert.Equal("", charConstToken.Value);
        }
Exemplo n.º 10
0
        public void TestTokenizerBeginsAndEndsWithWhitespace()
        {
            var code = @"
    ;   abc  ";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();
            var        tokens    = tokenizer.EnumerateTokens(code.AsSpan());

            Assert.Equal(2, tokens.Length);
            Assert.IsType <SemiColonToken>(tokens[0]);
            Assert.IsType <IdentifierToken>(tokens[1]);
            Assert.Equal("abc", ((IdentifierToken)tokens[1]).Name);
        }
Exemplo n.º 11
0
        public void VerifyAllSingleCharTokensParseCorrectly()
        {
            var tokenizer = new Compiler.Tokenizer.SimpleTokenizer();
            var singleCharTokenClasses = typeof(ISingleCharToken).Assembly.GetTypes().Where(x => !x.IsInterface).Where(x => x.GetInterfaces().Contains(typeof(ISingleCharToken)));

            foreach (var tokenClass in singleCharTokenClasses)
            {
                var  tokenCharValueField = tokenClass.GetField("CharValue", BindingFlags.Public | BindingFlags.Static);
                char c = (char)tokenCharValueField.GetValue(null);

                Assert.IsType(tokenClass, SimpleTokenizer.ParseCharacterToken(c, null));
            }
        }
Exemplo n.º 12
0
        public void VerifyAllKeywordTokensParseCorrectly()
        {
            var tokenizer    = new Compiler.Tokenizer.SimpleTokenizer();
            var tokenClasses = typeof(IKeywordToken).Assembly.GetTypes().Where(x => x.GetInterfaces().Contains(typeof(IKeywordToken)));

            foreach (var tokenClass in tokenClasses)
            {
                var    tokenCharValueField = tokenClass.GetField("KeywordValue", BindingFlags.Public | BindingFlags.Static);
                string c = (string)tokenCharValueField.GetValue(null);

                //Assert.IsType(tokenClass, SimpleTokenizer.ParseToken(c.AsSpan(), false));
            }
        }
Exemplo n.º 13
0
        public void TestPrimaryEscapeSequencesWork(string input, char output)
        {
            var        code      = $@"
'{input}'
";
            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();
            var        tokens    = tokenizer.EnumerateTokens(code.AsSpan());

            Assert.Equal(1, tokens.Length);
            var charConstToken = Assert.IsType <CharacterConstantToken>(tokens[0]);

            Assert.Equal(output, charConstToken.Value);
        }
Exemplo n.º 14
0
        public void TestCharConstantWorksAsOnlyCode()
        {
            var code = @"
'a'";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();
            var        tokens    = tokenizer.EnumerateTokens(code.AsSpan());

            Assert.Equal(1, tokens.Length);
            var charConstToken = Assert.IsType <CharacterConstantToken>(tokens[0]);

            Assert.Equal('a', charConstToken.Value);
        }
Exemplo n.º 15
0
        public void TestCharConstantWorksAfterSingleCharTokenWithWhitespace()
        {
            var code = @"
= 'a'";

            ITokenizer tokenizer = new Compiler.Tokenizer.SimpleTokenizer();
            var        tokens    = tokenizer.EnumerateTokens(code.AsSpan());

            Assert.Equal(2, tokens.Length);
            Assert.IsType <EqualsToken>(tokens[0]);
            var charConstToken = Assert.IsType <CharacterConstantToken>(tokens[1]);

            Assert.Equal('a', charConstToken.Value);
        }
Exemplo n.º 16
0
        public void TestTokenizerInvalidSingleCharTokenFails()
        {
            var tokenizer = new Compiler.Tokenizer.SimpleTokenizer();

            Assert.Throws <InvalidTokenParsingException>(() => SimpleTokenizer.ParseCharacterToken('c', null));
        }