Skip to content

Commit

Permalink
Add integration AssignPatternTest
Browse files Browse the repository at this point in the history
  • Loading branch information
MerijnHendriks committed Apr 8, 2024
1 parent 1be62ce commit ea55408
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
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 AssignPatternTest
{
[TestMethod]
public void TestSingle()
{
var file = string.Empty;
var source = "=";

var truthTokens = new Token[]
{
new Token(file, 0, TokenType.ASSIGN, 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.ASSIGN, 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);
}
}
}
5 changes: 5 additions & 0 deletions Lox.Compiler/Lexing/TextHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public bool IsAtEnd(string source, int index)

public bool IsMatchChar(string source, int index, char target)
{
if (this.IsAtEnd(source, index))
{
return false;
}

return source[index] == target;
}

Expand Down

0 comments on commit ea55408

Please sign in to comment.