Skip to content

Commit

Permalink
test: rendering nodes inheriting from Name
Browse files Browse the repository at this point in the history
  • Loading branch information
R-unic committed Jan 7, 2025
1 parent d250ce5 commit 0755d94
Showing 1 changed file with 55 additions and 15 deletions.
70 changes: 55 additions & 15 deletions RobloxCS.Tests/RenderingTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using RobloxCS.Luau;
using RobloxCS.Shared;

namespace RobloxCS.Tests;

Expand All @@ -11,11 +10,13 @@ public void Renders_AST()
var statement = new ExpressionStatement(AstUtility.PrintCall(AstUtility.String("bruh")));
var ast = new AST([statement]);
var output = Render(ast);
var expectedOutput = $"""
print("bruh")
return nil
const string expectedOutput = """
print("bruh")
return nil
""";
""";

Assert.Equal(expectedOutput.Replace("\r", ""), output.Replace("\r", ""));
}

[Fact]
Expand All @@ -24,14 +25,16 @@ public void Renders_Block()
var statements = Enumerable.Repeat(new ExpressionStatement(AstUtility.PrintCall(AstUtility.String("bruh"))), 5).ToList<Statement>();
var block = new Block(statements);
var output = Render(block);
var expectedOutput = $"""
print("bruh")
print("bruh")
print("bruh")
print("bruh")
print("bruh")
const string expectedOutput = """
print("bruh")
print("bruh")
print("bruh")
print("bruh")
print("bruh")
""";
""";

Assert.Equal(expectedOutput.Replace("\r", ""), output.Replace("\r", ""));
}

[Fact]
Expand All @@ -40,7 +43,7 @@ public void Renders_ScopedBlock()
var statements = Enumerable.Repeat(new ExpressionStatement(AstUtility.PrintCall(AstUtility.String("bruh"))), 5).ToList<Statement>();
var block = new ScopedBlock(statements);
var output = Render(block);
var expectedOutput = $"""
var expectedOutput = """

Check warning on line 46 in RobloxCS.Tests/RenderingTest.cs

View workflow job for this annotation

GitHub Actions / test

The variable 'expectedOutput' is assigned but its value is never used
do
print("bruh")
print("bruh")
Expand Down Expand Up @@ -299,6 +302,42 @@ public void Renders_Assignment()
Assert.Equal("a[69] = 420", output);
}

[Fact]
public void Renders_AssignmentFunctionName()
{
var functionName = new AssignmentFunctionName(new IdentifierName("Abc"), new IdentifierName("myMethod"), ':');
var output = Render(functionName);

Assert.Equal("Abc:myMethod", output);
}

[Fact]
public void Renders_QualifiedName()
{
var name = new QualifiedName(new IdentifierName("Abc"), new IdentifierName("myMethod"));
var output = Render(name);

Assert.Equal("Abc.myMethod", output);
}

[Fact]
public void Renders_GenericName()
{
var name = new GenericName("Abc", ["T", "U"]);
var output = Render(name);

Assert.Equal("Abc<T, U>", output);
}

[Fact]
public void Renders_IdentifierName()
{
var name = new IdentifierName("Abc");
var output = Render(name);

Assert.Equal("Abc", output);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down Expand Up @@ -383,12 +422,13 @@ public void Renders_AnonymousFunctions()
var body = new Block([new Return(new Literal("69"))]);
var function = new AnonymousFunction(new ParameterList([]), new TypeRef("number"), body);
var output = Render(function);
var expectedOutput = $"""
const string expectedOutput = """
function(): number
return 69
end
""";

Assert.Equal(expectedOutput.Replace("\r", ""), output.Replace("\r", ""));
}

[Theory]
Expand Down

0 comments on commit 0755d94

Please sign in to comment.