diff --git a/src/unitTests/TrivialMethodTest.cpp b/src/unitTests/TrivialMethodTest.cpp index 4025ac36..4e5173f1 100644 --- a/src/unitTests/TrivialMethodTest.cpp +++ b/src/unitTests/TrivialMethodTest.cpp @@ -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"]) @@ -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") @@ -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) - */ diff --git a/src/unitTests/TrivialMethodTest.h b/src/unitTests/TrivialMethodTest.h index 0cecbba6..6eebf049 100644 --- a/src/unitTests/TrivialMethodTest.h +++ b/src/unitTests/TrivialMethodTest.h @@ -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: @@ -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); };