2024-04-04 21:25:11 +08:00
|
|
|
|
using Canon.Core.LexicalParser;
|
|
|
|
|
using Canon.Core.Exceptions;
|
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
using Canon.Core.Enums;
|
2024-04-18 16:34:32 +08:00
|
|
|
|
using Canon.Core.Abstractions;
|
|
|
|
|
using Canon.Tests.Utils;
|
2024-04-04 21:25:11 +08:00
|
|
|
|
|
|
|
|
|
namespace Canon.Tests.LexicalParserTests
|
|
|
|
|
{
|
|
|
|
|
public class ErrorSingleTests
|
|
|
|
|
{
|
2024-04-18 16:34:32 +08:00
|
|
|
|
private readonly ILexer _lexer = new Lexer();
|
2024-04-04 21:25:11 +08:00
|
|
|
|
private readonly ITestOutputHelper _testOutputHelper;
|
|
|
|
|
public ErrorSingleTests(ITestOutputHelper testOutputHelper)
|
|
|
|
|
{
|
|
|
|
|
_testOutputHelper = testOutputHelper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("program main; var a: integer; begin a := 3#; end.", 1, 43, LexemeErrorType.IllegalNumberFormat)]
|
2024-04-24 11:01:45 +08:00
|
|
|
|
[InlineData("char c = 'abc;", 1, 14, LexemeErrorType.UnclosedStringLiteral)]
|
2024-04-04 21:25:11 +08:00
|
|
|
|
[InlineData("x := 10 @;", 1, 9, LexemeErrorType.UnknownCharacterOrString)]
|
|
|
|
|
[InlineData("identifier_with_special_chars@#",1, 30, LexemeErrorType.UnknownCharacterOrString)]
|
|
|
|
|
public void TestUnknownCharacterError(string pascalProgram, uint expectedLine, uint expectedCharPosition, LexemeErrorType expectedErrorType)
|
|
|
|
|
{
|
2024-04-18 16:34:32 +08:00
|
|
|
|
var ex = Assert.Throws<LexemeException>(() => _lexer.Tokenize(new StringSourceReader(pascalProgram)).ToList());
|
2024-04-04 21:25:11 +08:00
|
|
|
|
_testOutputHelper.WriteLine(ex.ToString());
|
|
|
|
|
Assert.Equal(expectedErrorType, ex.ErrorType);
|
|
|
|
|
Assert.Equal(expectedLine, ex.Line);
|
|
|
|
|
Assert.Equal(expectedCharPosition, ex.CharPosition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|