ParserTests.cs 799 B

123456789101112131415161718192021222324252627
  1. using Lua.CodeAnalysis.Syntax;
  2. using Lua.CodeAnalysis.Syntax.Nodes;
  3. namespace Lua.Tests;
  4. // TODO: add more tests
  5. public class ParserTests
  6. {
  7. [Test]
  8. public void Test_If_ElseIf_Else_Empty()
  9. {
  10. var source =
  11. @"if true then
  12. elseif true then
  13. else
  14. end";
  15. var actual = LuaSyntaxTree.Parse(source).Nodes[0];
  16. var expected = new IfStatementNode(
  17. new() { Position = new(1, 8), ConditionNode = new BooleanLiteralNode(true, new(1, 3)), ThenNodes = [] },
  18. [new() { Position = new(2, 13), ConditionNode = new BooleanLiteralNode(true, new(2, 7)), ThenNodes = [] }],
  19. [],
  20. new(1, 0));
  21. Assert.That(actual, Is.TypeOf<IfStatementNode>());
  22. Assert.That(actual.ToString(), Is.EqualTo(expected.ToString()));
  23. }
  24. }