Skip to content

Commit

Permalink
Added more literal return tests
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Aug 5, 2024
1 parent 43d8163 commit 1186232
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 53 deletions.
113 changes: 60 additions & 53 deletions src/unitTests/TrivialMethodTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,58 @@ void TrivialMethodTest::testBlockLiteralReturn() {
blockLiteralReturn("nil");
}

void TrivialMethodTest::literalNoReturn(std::string source) {
std::string s = "test = ( " + source + " )";
methodToBytecode(s.data());
VMInvokable* m = _mgenc->Assemble();

std::string expected = "Expected to be non-trivial: " + s;
bool result = IsLiteralReturn(m);
CPPUNIT_ASSERT_MESSAGE(expected.data(), !result);

tearDown();
}

void TrivialMethodTest::testLiteralNoReturn() {
literalNoReturn("0");
literalNoReturn("1");
literalNoReturn("-10");
literalNoReturn("3333");
literalNoReturn("'str'");
literalNoReturn("#sym");
literalNoReturn("1.1");
literalNoReturn("-2342.234");
literalNoReturn("true");
literalNoReturn("false");
literalNoReturn("nil");
}

void TrivialMethodTest::nonTrivialLiteralReturn(std::string source) {
std::string s = "test = ( 1. ^ " + source + " )";
methodToBytecode(s.data());
VMInvokable* m = _mgenc->Assemble();

std::string expected = "Expected to be non-trivial: " + s;
bool result = !IsLiteralReturn(m);
CPPUNIT_ASSERT_MESSAGE(expected.data(), result);

tearDown();
}

void TrivialMethodTest::testNonTrivialLiteralReturn() {
nonTrivialLiteralReturn("0");
nonTrivialLiteralReturn("1");
nonTrivialLiteralReturn("-10");
nonTrivialLiteralReturn("3333");
nonTrivialLiteralReturn("'str'");
nonTrivialLiteralReturn("#sym");
nonTrivialLiteralReturn("1.1");
nonTrivialLiteralReturn("-2342.234");
nonTrivialLiteralReturn("true");
nonTrivialLiteralReturn("false");
nonTrivialLiteralReturn("nil");
}

/*
@pytest.mark.parametrize("source", ["Nil", "system", "MyClassFooBar"])
Expand All @@ -73,6 +125,14 @@ void TrivialMethodTest::testBlockLiteralReturn() {
m = mgenc.assemble(body_or_none)
assert isinstance(m, AstMethod) or isinstance(m, BcMethod)
def test_unknown_global_in_block(bgenc):
"""
In PySOM we can actually support this, in TruffleSOM we can't
because of the difference in frame format.
"""
body_or_none = parse_block(bgenc, "[ UnknownGlobalSSSS ]")
m = bgenc.assemble(body_or_none)
assert isinstance(m, GlobalRead)
def test_field_getter_0(cgenc, mgenc):
add_field(cgenc, "field")
Expand Down Expand Up @@ -155,63 +215,10 @@ void TrivialMethodTest::testBlockLiteralReturn() {
m = mgenc.assemble(body_or_none)
assert isinstance(m, AstMethod) or isinstance(m, BcMethod)
@pytest.mark.parametrize(
"source",
[
"0",
"1",
"-10",
"'str'",
"#sym",
"1.1",
"-2342.234",
"true",
"false",
"nil",
],
)
def test_literal_no_return(mgenc, source):
body_or_none = parse_method(mgenc, "test = ( " + source + " )")
m = mgenc.assemble(body_or_none)
assert isinstance(m, AstMethod) or isinstance(m, BcMethod)
@pytest.mark.parametrize(
"source",
[
"0",
"1",
"-10",
"'str'",
"#sym",
"1.1",
"-2342.234",
"true",
"false",
"nil",
],
)
def test_non_trivial_literal_return(mgenc, source):
body_or_none = parse_method(mgenc, "test = ( 1. ^ " + source + " )")
m = mgenc.assemble(body_or_none)
assert isinstance(m, AstMethod) or isinstance(m, BcMethod)
def test_block_return(mgenc):
body_or_none = parse_method(mgenc, "test = ( ^ [] )")
m = mgenc.assemble(body_or_none)
assert isinstance(m, AstMethod) or isinstance(m, BcMethod)
def test_unknown_global_in_block(bgenc):
"""
In PySOM we can actually support this, in TruffleSOM we can't
because of the difference in frame format.
"""
body_or_none = parse_block(bgenc, "[ UnknownGlobalSSSS ]")
m = bgenc.assemble(body_or_none)
assert isinstance(m, GlobalRead)
*/
8 changes: 8 additions & 0 deletions src/unitTests/TrivialMethodTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
class TrivialMethodTest : public TestWithParsing {
CPPUNIT_TEST_SUITE(TrivialMethodTest);
CPPUNIT_TEST(testLiteralReturn);
CPPUNIT_TEST(testLiteralNoReturn);
CPPUNIT_TEST(testBlockLiteralReturn);
CPPUNIT_TEST(testNonTrivialLiteralReturn);
CPPUNIT_TEST_SUITE_END();

private:
Expand All @@ -16,4 +18,10 @@ class TrivialMethodTest : public TestWithParsing {

void testBlockLiteralReturn();
void blockLiteralReturn(std::string source);

void testLiteralNoReturn();
void literalNoReturn(std::string source);

void testNonTrivialLiteralReturn();
void nonTrivialLiteralReturn(std::string source);
};

0 comments on commit 1186232

Please sign in to comment.