Skip to content

Commit

Permalink
test: parsing nullable types
Browse files Browse the repository at this point in the history
  • Loading branch information
R-unic committed Jan 23, 2025
1 parent 4dd8b91 commit 406e49a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Heir.Tests/ParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,31 @@ public void Parses_ReturnStatements()
Assert.Equal(123L, literal.Token.Value);
}

[Fact]
public void Parses_NullableTypes()
{
var tree = Parse("let y: int? = 1");
var statement = tree.Statements.First();
Assert.IsType<VariableDeclaration>(statement);

var declaration = (VariableDeclaration)statement;
Assert.Equal("y", declaration.Name.Token.Text);
Assert.False(declaration.IsMutable);
Assert.NotNull(declaration.Initializer);
Assert.NotNull(declaration.Type);
Assert.IsType<Literal>(declaration.Initializer);
Assert.IsType<UnionType>(declaration.Type);

var unionType = (UnionType)declaration.Type;
Assert.IsType<SingularType>(unionType.Types.First());
Assert.IsType<SingularType>(unionType.Types.Last());

var intType = (SingularType)unionType.Types.First();
var noneType = (SingularType)unionType.Types.Last();
Assert.Equal("int", intType.Token.Text);
Assert.Equal("none", noneType.Token.Text);
}

[Fact]
public void Parses_FunctionTypes()
{
Expand Down

0 comments on commit 406e49a

Please sign in to comment.