-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: DebugTransformer file info output
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
namespace RobloxCS.Tests | ||
{ | ||
public class DebugTransformer_Should | ||
{ | ||
[Theory] | ||
[InlineData("Console.WriteLine(\"hello baby\")")] | ||
[InlineData("Console.Write(\"hello baby\")")] | ||
[InlineData("warn(\"hello baby\")")] | ||
public void FileInfo_PrependsArgument(string input) | ||
{ | ||
var cleanTree = TranspilerUtility.ParseTree(input); | ||
var transformedTree = TranspilerUtility.TransformTree(cleanTree, [TransformFactory.Main(), TransformFactory.Debug()]); | ||
var cleanRoot = cleanTree.GetRoot(); | ||
var cleanInvocation = cleanRoot.DescendantNodes().OfType<InvocationExpressionSyntax>().First(); | ||
var transformedRoot = transformedTree.GetRoot(); | ||
var transformedInvocation = transformedRoot.DescendantNodes().OfType<InvocationExpressionSyntax>().First(); | ||
var cleanArgs = cleanInvocation.ArgumentList.Arguments; | ||
var transformedArgs = transformedInvocation.ArgumentList.Arguments; | ||
var fileInfoArg = transformedArgs.FirstOrDefault(); | ||
Assert.True(cleanArgs.Count == 1); | ||
Assert.True(transformedArgs.Count == 2); | ||
Assert.NotNull(fileInfoArg); | ||
|
||
var fileInfoLiteral = (LiteralExpressionSyntax)fileInfoArg.Expression; | ||
Assert.Equal($"[TestFile.cs:1:13]:", fileInfoLiteral.Token.ValueText); | ||
} | ||
|
||
[Theory] | ||
[InlineData("error(\"hello baby\")")] | ||
public void FileInfo_ConcatenatesLiteral(string input) | ||
{ | ||
var cleanTree = TranspilerUtility.ParseTree(input); | ||
var transformedTree = TranspilerUtility.TransformTree(cleanTree, [TransformFactory.Main(), TransformFactory.Debug()]); | ||
var cleanRoot = cleanTree.GetRoot(); | ||
var cleanInvocation = cleanRoot.DescendantNodes().OfType<InvocationExpressionSyntax>().First(); | ||
var transformedRoot = transformedTree.GetRoot(); | ||
var transformedInvocation = transformedRoot.DescendantNodes().OfType<InvocationExpressionSyntax>().First(); | ||
var cleanArgs = cleanInvocation.ArgumentList.Arguments; | ||
var transformedArgs = transformedInvocation.ArgumentList.Arguments; | ||
var fullMessageArg = transformedArgs.FirstOrDefault(); | ||
Assert.True(cleanArgs.Count == 1); | ||
Assert.True(transformedArgs.Count == 1); | ||
Assert.NotNull(fullMessageArg); | ||
|
||
var fullMessageBinary= (BinaryExpressionSyntax)fullMessageArg.Expression; | ||
var fileInfoLiteral = (LiteralExpressionSyntax)fullMessageBinary.Left; | ||
Assert.Equal("[TestFile.cs:1:13]: ", fileInfoLiteral.Token.ValueText); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters