public void Lexize_WrongSingleCharEscape_ThrowsLexingException(string input) { // Arrange ILexer lexer = new MyStringLexer(); // Act var ex = Assert.Throws <LexingException>(() => lexer.Lexize(input)); // Assert Assert.That(ex.Message, Is.EqualTo("Bad escape.")); Assert.That(ex.Position, Is.EqualTo(new Position(0, 4))); }
public void Lexize_EndAfterEscape_ThrowsLexingException(string input) { // Arrange ILexer lexer = new MyStringLexer(); // Act var ex = Assert.Throws <LexingException>(() => lexer.Lexize(input)); // Assert Assert.That(ex.Message, Is.EqualTo("Unclosed string.")); Assert.That(ex.Position, Is.EqualTo(new Position(0, 18))); }
public void Lexize_NewLineInString_ThrowsLexingException(string input) { // Arrange ILexer lexer = new MyStringLexer(); // Act var ex = Assert.Throws <LexingException>(() => lexer.Lexize(input)); // Assert Assert.That(ex.Message, Is.EqualTo("Newline in string constant.")); Assert.That(ex.Position, Is.EqualTo(new Position(0, 14))); }
public void Lexize_UnclosedString_ThrowsLexingException() { // Arrange var input = " \"Unclosed string"; ILexer lexer = new MyStringLexer(); // Act var ex = Assert.Throws <LexingException>(() => lexer.Lexize(input)); // Assert Assert.That(ex.Message, Is.EqualTo("Unclosed string.")); Assert.That(ex.Position, Is.EqualTo(new Position(0, 17))); }
public void EscapeString_MixedEscapes_EscapesCorrectly() { // Arrange var input = "\"\\n\\v\\t\\r\\a\\b\\0\\t\\f\\\\\\u1488\""; ILexer lexer = new MyStringLexer(); // Act var tokens = lexer.Lexize(input); // Assert var textToken = (TextToken)tokens.Single(); Assert.That(textToken.Text, Is.EqualTo("\n\v\t\r\a\b\0\t\f\\\u1488")); }