public void TokenDefinition_IsInteger3() { var input = "619949104146091346013403410946"; var tokenDefinition = new TokenDefinition(TokenType.Integer, IntegerRegex); var match = tokenDefinition.Match(input); Assert.IsTrue(match.IsMatch); Assert.AreEqual("619949104146091346013403410946", match.Value); Assert.AreEqual(string.Empty, match.RemainingText); Assert.AreEqual(TokenType.Integer, match.TokenType); }
public void TokenDefinition_IsInteger2() { var input = "0115 -1"; var tokenDefinition = new TokenDefinition(TokenType.Integer, IntegerRegex); var match = tokenDefinition.Match(input); Assert.IsTrue(match.IsMatch); Assert.AreEqual("0115", match.Value); Assert.AreEqual(" -1", match.RemainingText); Assert.AreEqual(TokenType.Integer, match.TokenType); }
public void TokenDefinition_IsString1() { var input = "\"asdf\\n\""; var tokenDefinition = new TokenDefinition(TokenType.String, StringRegex); var match = tokenDefinition.Match(input); Assert.IsTrue(match.IsMatch); Assert.AreEqual("\"asdf\\n\"", match.Value); Assert.AreEqual(string.Empty, match.RemainingText); Assert.AreEqual(TokenType.String, match.TokenType); }
public void TokenDefinition_IsString1() { var input = "_asdf123"; var tokenDefinition = new TokenDefinition(TokenType.Identifier, IdentifierRegex); var match = tokenDefinition.Match(input); Assert.IsTrue(match.IsMatch); Assert.AreEqual("_asdf123", match.Value); Assert.AreEqual(string.Empty, match.RemainingText); Assert.AreEqual(TokenType.Identifier, match.TokenType); }
public void TokenDefinition_IsInvalid1() { var input = "fake_int a=32;"; var reservedRegex = RegexWrapper.DefaultWrap(ReservedProvider.GetPattern()); var tokenDefinition = new TokenDefinition(TokenType.Reserved, reservedRegex); var match = tokenDefinition.Match(input); Assert.IsFalse(match.IsMatch); Assert.IsNull(match.Value); Assert.IsNull(match.RemainingText); Assert.AreEqual(TokenType.Invalid, match.TokenType); }
public void SpecialCharacterTokenDefinitionMatch() { var previousTokenType = TokenType.NotDefined; var definition = new TokenDefinition(TokenType.Comma, ",", false); var lexer = new BaZicLexer(); lexer.InputCode = "Identifier, Id2"; Assert.IsFalse(definition.Match(lexer, 0, previousTokenType).IsMatch); lexer.InputCode = ", Identifier"; var match = definition.Match(lexer, 0, previousTokenType); Assert.IsTrue(match.IsMatch); Assert.AreEqual(TokenType.Comma, match.TokenType); Assert.AreEqual(",", match.Value); lexer.InputCode = ",Identifier"; match = definition.Match(lexer, 0, previousTokenType); Assert.IsTrue(match.IsMatch); Assert.AreEqual(",", match.Value); }
public void TokenDefinition_IsReserved_Integer() { var input = "int a=32;"; var reservedRegex = RegexWrapper.DefaultWrap(ReservedProvider.GetPattern()); var tokenDefinition = new TokenDefinition(TokenType.Reserved, reservedRegex); var match = tokenDefinition.Match(input); Assert.IsTrue(match.IsMatch); Assert.AreEqual("int", match.Value); Assert.AreEqual(" a=32;", match.RemainingText); Assert.AreEqual(TokenType.Reserved, match.TokenType); }
public void TokenDefinition_IsReserved_ReturnWithNewline() { var input = "return\nasdf"; var reservedRegex = RegexWrapper.DefaultWrap(ReservedProvider.GetPattern()); var tokenDefinition = new TokenDefinition(TokenType.Reserved, reservedRegex); var match = tokenDefinition.Match(input); Assert.IsTrue(match.IsMatch); Assert.AreEqual("return", match.Value); Assert.AreEqual("\nasdf", match.RemainingText); Assert.AreEqual(TokenType.Reserved, match.TokenType); }