Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MerijnHendriks committed Apr 8, 2024
1 parent ea55408 commit d808657
Show file tree
Hide file tree
Showing 16 changed files with 864 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Lox.Compiler.Tests/Integration/Lexing/Patterns/CommaPatternTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Lox.Compiler.Lexing;
using Lox.Compiler.Tests.Common;

namespace Lox.Compiler.Tests.Integration.Lexing.Patterns
{
[TestClass]
public sealed class CommaPatternTest
{
[TestMethod]
public void TestSingle()
{
var file = string.Empty;
var source = ",";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.COMMA, string.Empty),
new Token(file, 1, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}

[TestMethod]
public void TestSurrounded()
{
var file = string.Empty;
var source = " , ";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.WHITESPACE, string.Empty),
new Token(file, 1, TokenType.COMMA, string.Empty),
new Token(file, 2, TokenType.WHITESPACE, string.Empty),
new Token(file, 3, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2),
new SourcePosition(file, 2, 1, 3),
new SourcePosition(file, 3, 1, 4)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}
}
}
54 changes: 54 additions & 0 deletions Lox.Compiler.Tests/Integration/Lexing/Patterns/DotPatternTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Lox.Compiler.Lexing;
using Lox.Compiler.Tests.Common;

namespace Lox.Compiler.Tests.Integration.Lexing.Patterns
{
[TestClass]
public sealed class DotPatternTest
{
[TestMethod]
public void TestSingle()
{
var file = string.Empty;
var source = ".";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.DOT, string.Empty),
new Token(file, 1, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}

[TestMethod]
public void TestSurrounded()
{
var file = string.Empty;
var source = " . ";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.WHITESPACE, string.Empty),
new Token(file, 1, TokenType.DOT, string.Empty),
new Token(file, 2, TokenType.WHITESPACE, string.Empty),
new Token(file, 3, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2),
new SourcePosition(file, 2, 1, 3),
new SourcePosition(file, 3, 1, 4)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Lox.Compiler.Lexing;
using Lox.Compiler.Tests.Common;

namespace Lox.Compiler.Tests.Integration.Lexing.Patterns
{
[TestClass]
public sealed class LeftArrowPatternTest
{
[TestMethod]
public void TestSingle()
{
var file = string.Empty;
var source = "<";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.LEFT_ARROW, string.Empty),
new Token(file, 1, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}

[TestMethod]
public void TestSurrounded()
{
var file = string.Empty;
var source = " < ";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.WHITESPACE, string.Empty),
new Token(file, 1, TokenType.LEFT_ARROW, string.Empty),
new Token(file, 2, TokenType.WHITESPACE, string.Empty),
new Token(file, 3, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2),
new SourcePosition(file, 2, 1, 3),
new SourcePosition(file, 3, 1, 4)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Lox.Compiler.Lexing;
using Lox.Compiler.Tests.Common;

namespace Lox.Compiler.Tests.Integration.Lexing.Patterns
{
[TestClass]
public sealed class LeftCirclePatternTest
{
[TestMethod]
public void TestSingle()
{
var file = string.Empty;
var source = "(";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.LEFT_CIRCLE, string.Empty),
new Token(file, 1, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}

[TestMethod]
public void TestSurrounded()
{
var file = string.Empty;
var source = " ( ";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.WHITESPACE, string.Empty),
new Token(file, 1, TokenType.LEFT_CIRCLE, string.Empty),
new Token(file, 2, TokenType.WHITESPACE, string.Empty),
new Token(file, 3, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2),
new SourcePosition(file, 2, 1, 3),
new SourcePosition(file, 3, 1, 4)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Lox.Compiler.Lexing;
using Lox.Compiler.Tests.Common;

namespace Lox.Compiler.Tests.Integration.Lexing.Patterns
{
[TestClass]
public sealed class LeftCurlyePatternTest
{
[TestMethod]
public void TestSingle()
{
var file = string.Empty;
var source = "{";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.LEFT_CURLY, string.Empty),
new Token(file, 1, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}

[TestMethod]
public void TestSurrounded()
{
var file = string.Empty;
var source = " { ";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.WHITESPACE, string.Empty),
new Token(file, 1, TokenType.LEFT_CURLY, string.Empty),
new Token(file, 2, TokenType.WHITESPACE, string.Empty),
new Token(file, 3, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2),
new SourcePosition(file, 2, 1, 3),
new SourcePosition(file, 3, 1, 4)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}
}
}
54 changes: 54 additions & 0 deletions Lox.Compiler.Tests/Integration/Lexing/Patterns/MinusPatternTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Lox.Compiler.Lexing;
using Lox.Compiler.Tests.Common;

namespace Lox.Compiler.Tests.Integration.Lexing.Patterns
{
[TestClass]
public sealed class MinusPatternTest
{
[TestMethod]
public void TestSingle()
{
var file = string.Empty;
var source = "-";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.MINUS, string.Empty),
new Token(file, 1, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}

[TestMethod]
public void TestSurrounded()
{
var file = string.Empty;
var source = " - ";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.WHITESPACE, string.Empty),
new Token(file, 1, TokenType.MINUS, string.Empty),
new Token(file, 2, TokenType.WHITESPACE, string.Empty),
new Token(file, 3, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2),
new SourcePosition(file, 2, 1, 3),
new SourcePosition(file, 3, 1, 4)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}
}
}
54 changes: 54 additions & 0 deletions Lox.Compiler.Tests/Integration/Lexing/Patterns/NotPatternTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Lox.Compiler.Lexing;
using Lox.Compiler.Tests.Common;

namespace Lox.Compiler.Tests.Integration.Lexing.Patterns
{
[TestClass]
public sealed class NotPatternTest
{
[TestMethod]
public void TestSingle()
{
var file = string.Empty;
var source = "!";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.NOT, string.Empty),
new Token(file, 1, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}

[TestMethod]
public void TestSurrounded()
{
var file = string.Empty;
var source = " ! ";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.WHITESPACE, string.Empty),
new Token(file, 1, TokenType.NOT, string.Empty),
new Token(file, 2, TokenType.WHITESPACE, string.Empty),
new Token(file, 3, TokenType.END_OF_FILE, string.Empty)
};
var truthSourcemap = new SourcePosition[]
{
new SourcePosition(file, 0, 1, 1),
new SourcePosition(file, 1, 1, 2),
new SourcePosition(file, 2, 1, 3),
new SourcePosition(file, 3, 1, 4)
};

LexingTestHelper.AssertScanner(source, truthTokens, truthSourcemap);
}
}
}
Loading

0 comments on commit d808657

Please sign in to comment.