Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DONT REVIEW Testing the conversion to text first #2262

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// Licensed under the MIT license.

using System.Globalization;
using System.IO;
using System.Threading;
using Microsoft.PowerFx.Core.Tests.Helpers;
using Microsoft.PowerFx.Core.Tests;
using Microsoft.PowerFx.Types;
using Xunit;

Expand All @@ -25,5 +26,41 @@ public async void EmptyExpressionTest()

Assert.Equal(string.Empty, result.Value);
}

[Theory]

// Just some string text test files. No much thought has been put into this selection.
[InlineData("StringInterpolate.txt")]
[InlineData("TableStringfuncs.txt")]
[InlineData("string.txt")]
public void TextFirstRewriterTest(string fileName)
{
var curDir = Path.GetDirectoryName(typeof(TestRunner).Assembly.Location);
var fileDir = Path.Combine(curDir, "ExpressionTestCases", fileName);

var engine = new RecalcEngine();

var testRunner = new TestRunner();
testRunner.AddFile(TestRunner.ParseSetupString(string.Empty), fileDir);

foreach (var testCase in testRunner.Tests)
{
// Is it that easy?
var textFirstExpression = $"={testCase.Input}";

var check = engine.Check(testCase.Input);
var checkTextFirst = engine.Check(textFirstExpression, options: new ParserOptions() { TextFirst = true });

Assert.True(check.IsSuccess == checkTextFirst.IsSuccess, $"Failed: {testCase.Input} ===> {textFirstExpression}");

if (check.IsSuccess)
{
var result = check.GetEvaluator().Eval();
var resultTextFirst = checkTextFirst.GetEvaluator().Eval();

Assert.Equal(result.ToExpression(), resultTextFirst.ToExpression());
}
}
}
}
}