.
This commit is contained in:
@@ -27,6 +27,8 @@ public:
|
|||||||
|
|
||||||
// TODO - debugging info
|
// TODO - debugging info
|
||||||
|
|
||||||
|
[[nodiscard]] std::vector<uint8_t> const& data() const { return byte_array_.data(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ByteArray byte_array_;
|
ByteArray byte_array_;
|
||||||
static constexpr uint8_t VERSION = 1;
|
static constexpr uint8_t VERSION = 1;
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "bytearray.hh"
|
#include "bytearray.hh"
|
||||||
|
#include "bytecodeprototype.hh"
|
||||||
|
#include "bytecode.hh"
|
||||||
|
|
||||||
using namespace tyche;
|
using namespace tyche;
|
||||||
|
|
||||||
@@ -38,6 +41,45 @@ TEST(ByteArray, ByteArray)
|
|||||||
#undef TESTX
|
#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)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
|||||||
Reference in New Issue
Block a user