Example #1
0
 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);
     }
 }
Example #2
0
 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);
     }
 }
Example #3
0
 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);
     }
 }
Example #4
0
 public Parser(TextReader textReader)
 {
     lexer = new Lexer(textReader);
 }
Example #5
0
 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);
     }
 }
Example #6
0
 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();
     }
 }
Example #7
0
 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);
     }
     }