.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
|
||||
#include "bytearray.hh"
|
||||
#include "bytecodeprototype.hh"
|
||||
#include "bytecode.hh"
|
||||
|
||||
using namespace tyche;
|
||||
|
||||
@@ -38,6 +41,45 @@ TEST(ByteArray, ByteArray)
|
||||
#undef TESTX
|
||||
}
|
||||
|
||||
TEST(Bytecode, Constants)
|
||||
{
|
||||
BytecodePrototype bp;
|
||||
bp.constants.emplace_back(42);
|
||||
bp.constants.emplace_back("HELLO");
|
||||
|
||||
Bytecode bc(bp);
|
||||
auto binary = bc.data();
|
||||
|
||||
ByteArray ba;
|
||||
ba.append_int(42);
|
||||
|
||||
std::vector<uint8_t> expected = {
|
||||
// header
|
||||
0x38, 0xc1, 0xb3, 0x74, // magic
|
||||
0x01, 0x00, 0x00, 0x00, // version
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
// index
|
||||
0x30, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
// constant indexes
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00,
|
||||
|
||||
// constant values
|
||||
0x54, 'H', 'e', 'l', 'l', 'o', 0x00
|
||||
};
|
||||
|
||||
ASSERT_EQ(binary, expected);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
Reference in New Issue
Block a user