Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anhnguyenct committed Sep 21, 2023
1 parent 8e8cd13 commit e532658
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Cimpress.Cimbol/Cimpress.Cimbol.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,50 @@ public void Should_Default_When_IdentifierIsNull(CompilationProfile compilationP

Assert.That(result.Modules["Main"].Value["Formula1"], Has.Property("Value").EqualTo(1));
}

[Test]
[TestCase(CompilationProfile.Minimal)]
[TestCase(CompilationProfile.Trace)]
[TestCase(CompilationProfile.Verbose)]
public void Should_ReturnValue_When_MemberExistsAndContainsWhitespace(CompilationProfile compilationProfile)
{
var program = new Program();
var module = program.AddModule("Main");

var objectValue = new ObjectValue(new Dictionary<string, ILocalValue> { { "member name", new NumberValue(5) } });
var constant = program.AddConstant("something", objectValue);

module.AddImport("something", constant);
module.AddFormula("Formula1", "default(something.'member name', 1)");

var executable = program.Compile(compilationProfile);

var result = executable.Call().Result;

Assert.That(result.Modules["Main"].Value["Formula1"], Has.Property("Value").EqualTo(5));
}

[Test]
[TestCase(CompilationProfile.Minimal)]
[TestCase(CompilationProfile.Trace)]
[TestCase(CompilationProfile.Verbose)]
public void Should_ReturnValue_When_IdentifierExistsAndContainsWhitespace(CompilationProfile compilationProfile)
{
var program = new Program();
var module = program.AddModule("Main");

var objectValue = new ObjectValue(new Dictionary<string, ILocalValue> { { "member name", new NumberValue(5) } });
var constant = program.AddConstant("something with spaces", objectValue);

module.AddImport("something with spaces", constant);
module.AddFormula("Formula1", "default('something with spaces'.'member name', 1)");

var executable = program.Compile(compilationProfile);

var result = executable.Call().Result;

Assert.That(result.Modules["Main"].Value["Formula1"], Has.Property("Value").EqualTo(5));
}

private static ILocalValue MockNestedObject(string[] path, ILocalValue value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,47 @@ NumberValue Function()

Assert.That(result.Modules["Main"].Value["Formula1"], Has.Property("Value").EqualTo(false));
}

[Test]
[TestCase(CompilationProfile.Minimal)]
[TestCase(CompilationProfile.Trace)]
[TestCase(CompilationProfile.Verbose)]
public async Task Should_ReturnTrue_When_ObjectMemberNameContainsWhitespace(CompilationProfile compilationProfile)
{
var program = new Program();
var objectValue = new ObjectValue(new Dictionary<string, ILocalValue> { { "member name", new StringValue("1") } });
var constant = program.AddConstant("something", objectValue);

var module = program.AddModule("Main");
module.AddImport("something", constant);
module.AddFormula("Formula1", "exists(something.'member name')");

var executable = program.Compile(compilationProfile);

var result = await executable.Call();

Assert.That(result.Modules["Main"].Value["Formula1"], Has.Property("Value").EqualTo(true));
}

[Test]
[TestCase(CompilationProfile.Minimal)]
[TestCase(CompilationProfile.Trace)]
[TestCase(CompilationProfile.Verbose)]
public async Task Should_ReturnTrue_When_ImportNameContainsWhitespace(CompilationProfile compilationProfile)
{
var program = new Program();
var objectValue = new ObjectValue(new Dictionary<string, ILocalValue> { { "member name", new StringValue("1") } });
var constant = program.AddConstant("something with spaces", objectValue);

var module = program.AddModule("Main");
module.AddImport("something with spaces", constant);
module.AddFormula("Formula1", "exists('something with spaces'.'member name')");

var executable = program.Compile(compilationProfile);

var result = await executable.Call();

Assert.That(result.Modules["Main"].Value["Formula1"], Has.Property("Value").EqualTo(true));
}
}
}

0 comments on commit e532658

Please sign in to comment.