From 09e59ae226f2fcb469b944c815b1e1bf46d4c569 Mon Sep 17 00:00:00 2001 From: ValeriHristov Date: Sun, 25 Nov 2018 17:49:14 +0200 Subject: Implement comparison operators (#71) * Implement comparison operators. * Remove debug code. * Undo test code. --- JSImpl/test/sprtTests.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'JSImpl/test/sprtTests.cpp') diff --git a/JSImpl/test/sprtTests.cpp b/JSImpl/test/sprtTests.cpp index 8480554..a7b9e3b 100644 --- a/JSImpl/test/sprtTests.cpp +++ b/JSImpl/test/sprtTests.cpp @@ -127,7 +127,6 @@ TEST_F(SPRTTest, Less) ASSERT_EQ(Output.str(), "100"); } - TEST_F(SPRTTest, LessEq) { Spasm::byte bytecode[] = { @@ -145,6 +144,76 @@ TEST_F(SPRTTest, LessEq) ASSERT_EQ(Output.str(), "101"); } +TEST_F(SPRTTest, Greater) +{ + Spasm::byte bytecode[] = { + OpCodes::Const, 1, 6, + OpCodes::Const, 2, 7, + OpCodes::Greater, 3, 1, 2, + OpCodes::Greater, 4, 2, 1, + OpCodes::Greater, 5, 2, 2, + OpCodes::Print, 3, + OpCodes::Print, 4, + OpCodes::Print, 5, + }; + + Run(bytecode, sizeof(bytecode)); + ASSERT_EQ(Output.str(), "010"); +} + +TEST_F(SPRTTest, GreaterEq) +{ + Spasm::byte bytecode[] = { + OpCodes::Const, 1, 6, + OpCodes::Const, 2, 7, + OpCodes::GreaterEq, 3, 1, 2, + OpCodes::GreaterEq, 4, 2, 1, + OpCodes::GreaterEq, 5, 2, 2, + OpCodes::Print, 3, + OpCodes::Print, 4, + OpCodes::Print, 5, + }; + + Run(bytecode, sizeof(bytecode)); + ASSERT_EQ(Output.str(), "011"); +} + +TEST_F(SPRTTest, Equal) +{ + Spasm::byte bytecode[] = { + OpCodes::Const, 1, 6, + OpCodes::Const, 2, 7, + OpCodes::Const, 3, 6, + OpCodes::Equal, 4, 2, 1, + OpCodes::Equal, 5, 2, 2, + OpCodes::Equal, 6, 1, 3, + OpCodes::Print, 4, + OpCodes::Print, 5, + OpCodes::Print, 6, + }; + + Run(bytecode, sizeof(bytecode)); + ASSERT_EQ(Output.str(), "011"); +} + +TEST_F(SPRTTest, NotEqual) +{ + Spasm::byte bytecode[] = { + OpCodes::Const, 1, 6, + OpCodes::Const, 2, 7, + OpCodes::Const, 3, 6, + OpCodes::NotEqual, 4, 2, 1, + OpCodes::NotEqual, 5, 2, 2, + OpCodes::NotEqual, 6, 1, 3, + OpCodes::Print, 4, + OpCodes::Print, 5, + OpCodes::Print, 6, + }; + + Run(bytecode, sizeof(bytecode)); + ASSERT_EQ(Output.str(), "100"); +} + TEST_F(SPRTTest, Jump) { Spasm::byte bytecode[] = { -- cgit v1.3.1-23-gd82d