From cfefca49ee60cd255c53b1437d74bb97ba041e3d Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Fri, 4 Sep 2026 00:16:58 +0200 Subject: [PATCH] test(furvm): add array and slice tests Refs: #38 --- furvm/test/test.cpp | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/furvm/test/test.cpp b/furvm/test/test.cpp index a0aee53..8d6eea2 100644 --- a/furvm/test/test.cpp +++ b/furvm/test/test.cpp @@ -1,16 +1,14 @@ -#include "furlang/arena.hpp" #include "furvm/furvm.hpp" #include "furvm/thing.hpp" #include "gtest/gtest.h" // IWYU pragma: keep +#include namespace { // TODO: Basic program tests (e.g. for loops) -TEST(Things, Ops) { - furlang::arena arena; - +TEST(ThingOps, Add) { furvm::thing lhs{ furvm::thing_type{ furvm::thing_type::U32 } }; lhs.get() = 6; furvm::thing rhs{ furvm::thing_type{ furvm::thing_type::U32 } }; @@ -23,4 +21,37 @@ TEST(Things, Ops) { EXPECT_EQ(res.get(), 6 + 7); } +TEST(ThingOps, Array) { + furvm::thing_type innerType = { furvm::thing_type::U32 }; + + static constexpr std::size_t LENGTH = 10; + static constexpr std::array values = { 0, 1, 2, 3, 4, 5, 6, 7, 6, 7 }; + + furvm::thing array{ furvm::thing_type{ furvm::thing_type::Array, { &innerType, LENGTH } } }; + EXPECT_EQ(array.length(), LENGTH); + for (std::size_t i = 0; i < LENGTH; ++i) { + auto el = array.at(i); + el.get() = values[i]; + EXPECT_EQ(array.at(i).integer(), values[i]); + } +} + +TEST(ThingOps, Slice) { + furvm::thing_type innerType = { furvm::thing_type::U32 }; + + static constexpr std::size_t LENGTH = 10; + static constexpr std::array values = { 0, 1, 2, 3, 4, 5, 6, 7, 6, 7 }; + + furvm::thing array{ furvm::thing_type{ furvm::thing_type::Array, { &innerType, LENGTH } } }; + EXPECT_EQ(array.length(), LENGTH); + furvm::thing slice = array.slice(0, LENGTH); + EXPECT_EQ(slice.length(), LENGTH); + for (std::size_t i = 0; i < LENGTH; ++i) { + auto el = slice.at(i); + el.get() = values[i]; + EXPECT_EQ(array.at(i).integer(), values[i]); + EXPECT_EQ(slice.at(i).integer(), array.at(i).integer()); + } +} + } // namespace