// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details #include #include "Luau/Slice.h" #include using namespace Luau; TEST_SUITE_BEGIN("EqSatSlice"); TEST_CASE("slice_is_a_view_over_array") { std::array a{1, 2, 3, 4, 5, 6, 7, 8}; EqSat::Slice slice{a}; CHECK(slice.data() == a.data()); CHECK(slice.size() == a.size()); for (size_t i = 0; i < a.size(); ++i) { CHECK(slice[i] == a[i]); CHECK(&slice[i] == &a[i]); } } TEST_CASE("slice_is_a_view_over_vector") { std::vector vector{1, 2, 3, 4, 5, 6, 7, 8}; EqSat::Slice slice{vector.data(), vector.size()}; CHECK(slice.data() == vector.data()); CHECK(slice.size() == vector.size()); for (size_t i = 0; i < vector.size(); ++i) { CHECK(slice[i] == vector[i]); CHECK(&slice[i] == &vector[i]); } } TEST_CASE("mutate_via_slice") { std::array a{1, 2}; CHECK(a[0] == 1); CHECK(a[1] == 2); EqSat::Slice slice{a}; slice[0] = 42; slice[1] = 37; CHECK(a[0] == 42); CHECK(a[1] == 37); } TEST_SUITE_END();