This commit is contained in:
2026-04-27 15:54:31 -05:00
parent 3313b89771
commit 7b39a40a32
2 changed files with 44 additions and 0 deletions

View File

@@ -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);