public void TestIdParse() { IdentLexer l = new IdentLexer("abc22"); Assert.IsTrue(l.Parse(), "Не разбирает аbc22"); l = new IdentLexer("a"); Assert.IsTrue(l.Parse(), "Не разбирает а"); }
public static void Main() { //ints string intPos = "154216"; string intNeg = "-154216"; Lexer L1 = new IntLexer(intPos); Lexer L3 = new IntLexer("12x3"); Lexer L2 = new IntLexer(intNeg); System.Console.WriteLine("task 1:"); try { L1.Parse(); L2.Parse(); L3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //idents string goodIdent = "abc_23d"; string badIdent = "123a"; Lexer LId1 = new IdentLexer(goodIdent); Lexer LId2 = new IdentLexer(badIdent); System.Console.WriteLine("task 2:"); try { LId1.Parse(); LId2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //not zeros string goodInt = "154216"; string badInt = "054216"; Lexer NotZeroL1 = new IntNotZeroLexer(goodInt); Lexer NotZeroL2 = new IntNotZeroLexer(badInt); System.Console.WriteLine("task 3:"); try { NotZeroL1.Parse(); NotZeroL2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //interleaved Lexer Interleave1 = new LetterDigitInterleave("a1b2c3"); Lexer Interleave2 = new LetterDigitInterleave("a1b2c33"); Lexer Interleave3 = new LetterDigitInterleave("a1b2c"); System.Console.WriteLine("task 4:"); try { Interleave1.Parse(); Interleave3.Parse(); Interleave2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //letters separated Lexer Separated1 = new LettersSeparated("a,b;c"); Lexer Separated2 = new LettersSeparated("abc"); Lexer Separated3 = new LettersSeparated("a;bc,"); System.Console.WriteLine("task 4:"); try { Separated1.Parse(); Separated2.Parse(); Separated3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //extra 1 Lexer SpaceDigits1 = new DigitsSepBySpaces("1 2 3"); Lexer SpaceDigits2 = new DigitsSepBySpaces("1 2 3"); Lexer SpaceDigits3 = new DigitsSepBySpaces("1 "); System.Console.WriteLine("extra task 1:"); try { SpaceDigits1.Parse(); SpaceDigits2.Parse(); SpaceDigits3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //extra 2 Lexer LettersDigitsInterleaved1 = new Lexem2("aa11bb34cc"); Lexer LettersDigitsInterleaved2 = new Lexem2("aa11bb3cc"); Lexer LettersDigitsInterleaved3 = new Lexem2("aa11bb345"); System.Console.WriteLine("extra task 2:"); try { LettersDigitsInterleaved1.Parse(); LettersDigitsInterleaved2.Parse(); LettersDigitsInterleaved3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //extra 3 Lexer Real1 = new RealLexer("123.54"); Lexer Real2 = new RealLexer("-15.2"); Lexer Real3 = new RealLexer("11.."); System.Console.WriteLine("extra task 3:"); try { Real1.Parse(); Real2.Parse(); Real3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //extra 4 Lexer Apostrophies1 = new ApostrophiesLexer("'Hello, world!'"); Lexer Apostrophies2 = new ApostrophiesLexer("'Howdy"); Lexer Apostrophies3 = new ApostrophiesLexer("'Hey, Hey!'blablabla"); System.Console.WriteLine("extra task 4:"); try { Apostrophies1.Parse(); Apostrophies2.Parse(); Apostrophies3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //extra 5 Lexer Comment1 = new CommentLexer("/*hello there*/"); Lexer Comment2 = new CommentLexer("/*hello * there */"); Lexer Comment3 = new CommentLexer("/*hello * there */, General Kenobi"); System.Console.WriteLine("extra task 5:"); try { Comment1.Parse(); Comment2.Parse(); Comment3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } }
public void TestIdEmpty() { IdentLexer l = new IdentLexer(""); Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает пустую строку"); }
public void TestIdDollar() { IdentLexer l = new IdentLexer("f67$3"); Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает $"); }
public void TestIdDot() { IdentLexer l = new IdentLexer("f67.3"); Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает точку"); }
public void TestIdUnderscore() { IdentLexer l = new IdentLexer("a12_5"); Assert.IsTrue(l.Parse(), "Не разбирает _"); }
public void TestIdNumbers() { IdentLexer l = new IdentLexer("a12345"); Assert.IsTrue(l.Parse(), "Не разбирает цифры в конце"); }
public void TestIdCaps() { IdentLexer l = new IdentLexer("AAAAA"); Assert.IsTrue(l.Parse(), "Не разбирает заглавные буквы"); }