-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from hassansalehe/improve-test-coverage
Improve test coverage
- Loading branch information
Showing
5 changed files
with
72 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include "common/instruction.h" | ||
|
||
TEST(InstructionTests, CheckTrimHelperFunction) { | ||
std::string raw_instruction(" store balance r6 "); | ||
EXPECT_EQ(std::string("store balance r6"), Instruction::trim(raw_instruction)); | ||
|
||
EXPECT_TRUE(Instruction::trim(" ").empty()); | ||
} | ||
|
||
TEST(InstructionTests, CheckSplitInstructionFunction) { | ||
std::string raw_instruction(" store balance r6 "); | ||
Instruction instr; | ||
auto chunks = instr.splitInstruction(raw_instruction); | ||
|
||
EXPECT_EQ(3UL, chunks.size()); | ||
EXPECT_EQ("store", chunks.at(0)); | ||
EXPECT_EQ("balance", chunks.at(1)); | ||
EXPECT_EQ("r6", chunks.at(2)); | ||
} | ||
|
||
TEST(InstructionTests, CheckSplitInstructionFunctionEmptyString) { | ||
std::string raw_instruction(" "); | ||
Instruction instr; | ||
auto chunks = instr.splitInstruction(raw_instruction); | ||
EXPECT_EQ(0UL, chunks.size()); | ||
} | ||
|
||
TEST(InstructionTests, CheckInstructionForStore) { | ||
std::string raw_instruction(" store i32 %2, i32* %balance "); | ||
Instruction instr(raw_instruction); | ||
EXPECT_EQ(STORE, instr.oper); | ||
EXPECT_EQ("%balance", instr.destination); | ||
EXPECT_EQ("i32", instr.type); | ||
EXPECT_EQ("%2", instr.operand1); | ||
EXPECT_EQ("%2", instr.operand2); | ||
} | ||
|
||
TEST(InstructionTests, CheckInstructionForLoad) { | ||
std::string raw_instruction(" %1 = load i32 * %balance"); | ||
Instruction instr(raw_instruction); | ||
EXPECT_EQ(LOAD, instr.oper); | ||
EXPECT_EQ("%1", instr.destination); | ||
EXPECT_EQ("i32", instr.type); | ||
EXPECT_EQ("%balance", instr.operand1); | ||
} | ||
|
||
TEST(InstructionTests, CheckInstructionForAlloca) { | ||
std::string raw_instruction("%balance = alloca i32 , align 4 "); | ||
Instruction instr(raw_instruction); | ||
EXPECT_EQ(ALLOCA, instr.oper); | ||
EXPECT_EQ("%balance", instr.destination); | ||
EXPECT_EQ("i32", instr.type); | ||
} |
File renamed without changes.