Skip to content

Commit

Permalink
test: nameof() parsing & evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
R-unic committed Jan 25, 2025
1 parent 717e909 commit 51ef07d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Heir.Tests/ParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ public void DoesNotThrowWith(string input)
var tree = Parse(input);
Assert.Empty(tree.Diagnostics);
}

[Theory]
[InlineData("interface Abc; nameof(Abc);", "Abc")]
[InlineData("let x = 1; nameof(x);", "x")]
public void Parses_NameOf(string input, string expectedName)
{
var tree = Parse(input);
var statement = tree.Statements.Last();
Assert.IsType<ExpressionStatement>(statement);

var expressionStatement = (ExpressionStatement)statement;
Assert.IsType<Literal>(expressionStatement.Expression);

var literal = (Literal)expressionStatement.Expression;
Assert.Equal(SyntaxKind.StringLiteral, literal.Token.Kind);
Assert.Equal(expectedName, literal.Token.Value);
}

[Fact]
public void Parses_EmptyInterfaces()
Expand Down
9 changes: 9 additions & 0 deletions Heir.Tests/VirtualMachineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ public void ThrowsWith(string input, DiagnosticCode expectedDiagnosticCode)
Assert.True(vm.Diagnostics.HasErrors);
Assert.Contains(vm.Diagnostics, diagnostic => diagnostic.Code == expectedDiagnosticCode);
}

[Theory]
[InlineData("interface Abc; nameof(Abc);", "Abc")]
[InlineData("let x = 1; nameof(x);", "x")]
public void Evaluates_NameOf(string input, string expectedValue)
{
var (value, _) = Evaluate(input);
Assert.Equal(expectedValue, value);
}

[Fact]
public void Evaluates_MutableInterfaces()
Expand Down

0 comments on commit 51ef07d

Please sign in to comment.