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

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

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

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

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

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

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

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

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

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

            Assert.Throws <UnrecognizedEscapeException>(() => tokenizer.EnumerateTokens(code.AsSpan()));
        }
예제 #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]);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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));
            }
        }
예제 #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));
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #16
0
        public void TestTokenizerInvalidSingleCharTokenFails()
        {
            var tokenizer = new Compiler.Tokenizer.SimpleTokenizer();

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