Skip to content

Commit

Permalink
Adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pachanga committed Dec 6, 2024
1 parent ef891ff commit 3b48691
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_any.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,26 @@ func int test()
Assert.Equal(1111, num);
CommonChecks(vm);
}

[Fact]
public void TestNeedExplicitCastForAnyArray()
{
string bhl = @"
func int test()
{
[]int cs
[]any anys
cs = anys
}
";

AssertError(() => MakeVM(bhl),
"incompatible types: '[]int' and '[]any'"
);
}

[Fact]
public void TestCastUserTypeMapToAnyMap()
Expand Down Expand Up @@ -344,4 +364,24 @@ func int test()
Assert.Equal(10 + 1111, num);
CommonChecks(vm);
}

[Fact]
public void TestNeedExplicitCastForAnyMap()
{
string bhl = @"
func int test()
{
[string]int cs
[any]any anys
cs = anys
}
";

AssertError(() => MakeVM(bhl),
"incompatible types: '[string]int' and '[any]any'"
);
}
}
5 changes: 5 additions & 0 deletions tests/test_shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,11 @@ public static void AssertEqual(string a, string b)
Assert.Equal(a, b);
}

public void AssertError(Action action, string msg, PlaceAssert place_assert = null)
{
AssertError<Exception>(action, msg, place_assert);
}

public void AssertError<T>(Action action, string msg, PlaceAssert place_assert = null) where T : Exception
{
Exception err = null;
Expand Down

0 comments on commit 3b48691

Please sign in to comment.