using Microsoft.VisualStudio.TestTools.UnitTesting; using ShintenScript; using System; using System.Linq; namespace ShintenScriptTest { [TestClass] public class LexerTests { [TestMethod] public void TestAllTokens() { Lexer lexer = new Lexer(@" hello 5 0.5 0xCafeBabe 1.5e6 2.4e-6 ; ( ) { } + - * / > < == >= <= != = += -= *= /= if while fn "); Assert.IsTrue(lexer.TokenStream().SequenceEqual(new Token[] { new Token { type = Token.Type.IDENTIFIER, data = "hello" }, new Token { type = Token.Type.NUMBER, data = 5f }, new Token { type = Token.Type.NUMBER, data = 0.5f }, new Token { type = Token.Type.NUMBER, data = 3405691582f }, new Token { type = Token.Type.NUMBER, data = 1.5e6f }, new Token { type = Token.Type.NUMBER, data = 2.4e-6f }, new Token { type = Token.Type.SEMICOLON }, new Token { type = Token.Type.LPAREN }, new Token { type = Token.Type.RPAREN }, new Token { type = Token.Type.LBRACE }, new Token { type = Token.Type.RBRACE }, new Token { type = Token.Type.PLUS }, new Token { type = Token.Type.MINUS }, new Token { type = Token.Type.ASTERISK }, new Token { type = Token.Type.SLASH }, new Token { type = Token.Type.GT }, new Token { type = Token.Type.LT }, new Token { type = Token.Type.EQ }, new Token { type = Token.Type.GE }, new Token { type = Token.Type.LE }, new Token { type = Token.Type.NE }, new Token { type = Token.Type.ASSIGN }, new Token { type = Token.Type.PLUSASSIGN }, new Token { type = Token.Type.MINUSASSIGN }, new Token { type = Token.Type.ASTERISKASSIGN }, new Token { type = Token.Type.SLASHASSIGN }, new Token { type = Token.Type.IF }, new Token { type = Token.Type.WHILE }, new Token { type = Token.Type.FN }, })); } [TestMethod] public void TestHexExponent() { Lexer lexer = new Lexer(@"0xcafe-1337"); Assert.IsTrue(lexer.TokenStream().SequenceEqual(new Token[] { new Token { type = Token.Type.NUMBER, data = 51966f }, new Token { type = Token.Type.MINUS }, new Token { type = Token.Type.NUMBER, data = 1337f }, })); } } }