public void AcceptCorrectLiterals() { var input = new[] { "true", "false", "none" }; foreach (var i in input) { var l = new Lexer(new StringReader(i)); Assert.AreEqual(TokenType.Literal, l.GetCurrentToken().TokenType); Assert.AreEqual(i, l.GetCurrentToken().Value); } }
public void AcceptCorrectStrings() { foreach (var i in EnumerateCorrectStrings()) { var l = new Lexer(new StringReader(i)); Assert.AreEqual(TokenType.String, l.GetCurrentToken().TokenType); if (i != l.GetCurrentToken().Value) { l = new Lexer(new StringReader(i)); l.GetCurrentToken(); } Assert.AreEqual(i, l.GetCurrentToken().Value); } }
public void ThrowIncorrectLiterals() { var input = new[] { "True", "Yes", "yes", "False", "No", "no", "None", "Null", "null", "abc" }; foreach (var i in input) { Exception ee = null; try { var l = new Lexer(new StringReader(i)); l.GetCurrentToken(); } catch (Exception e) { ee = e; } Assert.IsNotNull(ee); } }
public Parser(TextReader textReader) { lexer = new Lexer(textReader); }
public void ThrowIncorrectNumbers() { var input = new[] { "a", "%10", "+", "+1", "+a", "-", "--", "-.5", "-e2", "-E2", "-a", ".", ".7", ".+", ".-", "e5", "E5", ".e5", ".E5", ".a", "ae5", "0.e4", "0.E4", "0.", "0.+", "0.-", "0.a", "0e", "0E", "0e+", "0E-", "0ec", "0Ec", "0.1e", "0.1E", "0.1e+", "0.1e-", "0.1ea" }; foreach (var i in input) { Exception ee = null; try { var l = new Lexer(new StringReader(i)); l.GetCurrentToken(); } catch (Exception e) { ee = e; } Assert.IsNotNull(ee); } }
private void CheckLexerOutput(IEnumerable<Token> expected, Lexer lexer) { foreach (var t in expected) { Assert.AreEqual(t.TokenType, lexer.GetCurrentToken().TokenType); Assert.AreEqual(t.Value, lexer.GetCurrentToken().Value); lexer.NextToken(); } }
public void ThrowIncorrectStrings() { var input = new List<string>(); input.AddRange(new[] { @"""", @"""\""", @"""\u0022", @"""abc" }); input.AddRange(Quote(@"\B", @"\F", @"\N", @"\R", @"\T", @"\a", @"\#")); input.AddRange(Quote(@"\U0012", @"\u0", @"\u01", @"\u012", @"\u000G", @"\u000g")); input.AddRange(Quote("\u0011\u0000")); foreach (var i in input) { Exception ee = null; try { var l = new Lexer(new StringReader(i)); l.GetCurrentToken(); } catch (Exception e) { ee = e; } Assert.IsNotNull(ee); } }