diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-23 00:32:38 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-23 00:32:38 +0100 |
| commit | 0fa623093366351ad47583f47add6e51f56a56d8 (patch) | |
| tree | 3eaaa64f5c9b88798d2b971d2810f85cc3e06cd6 /nihil.ucl/tests/array.cc | |
| parent | 8cbb82a1f6eb6605a4615d30922b777e7bf1e4d8 (diff) | |
| download | nihil-0fa623093366351ad47583f47add6e51f56a56d8.tar.gz nihil-0fa623093366351ad47583f47add6e51f56a56d8.tar.bz2 | |
nihil.ucl: improve tests
Diffstat (limited to 'nihil.ucl/tests/array.cc')
| -rw-r--r-- | nihil.ucl/tests/array.cc | 78 |
1 files changed, 67 insertions, 11 deletions
diff --git a/nihil.ucl/tests/array.cc b/nihil.ucl/tests/array.cc index 023b3bf..ce0976f 100644 --- a/nihil.ucl/tests/array.cc +++ b/nihil.ucl/tests/array.cc @@ -3,14 +3,36 @@ */ #include <algorithm> +#include <concepts> #include <ranges> #include <string> #include <catch2/catch_test_macros.hpp> +#include <ucl.h> import nihil.ucl; -TEST_CASE("ucl: array: construct", "[ucl]") +TEST_CASE("ucl: array: invariants", "[ucl]") +{ + using namespace nihil::ucl; + + REQUIRE(array<>::ucl_type == object_type::array); + REQUIRE(static_cast<::ucl_type>(array<>::ucl_type) == UCL_ARRAY); + + static_assert(std::destructible<array<>>); + static_assert(std::default_initializable<array<>>); + static_assert(std::move_constructible<array<>>); + static_assert(std::copy_constructible<array<>>); + static_assert(std::equality_comparable<array<>>); + static_assert(std::totally_ordered<array<>>); + static_assert(std::swappable<array<>>); + + static_assert(std::ranges::sized_range<array<integer>>); + static_assert(std::same_as<std::ranges::range_value_t<array<integer>>, + integer>); +} + +TEST_CASE("ucl: array: default construct", "[ucl]") { using namespace nihil::ucl; @@ -19,6 +41,42 @@ TEST_CASE("ucl: array: construct", "[ucl]") REQUIRE(str(arr.type()) == "array"); } +TEST_CASE("ucl: array: construct from range", "[ucl]") +{ + using namespace nihil::ucl; + + auto vec = std::vector{integer(1), integer(42)}; + auto arr = array<integer>(std::from_range, vec); + + REQUIRE(arr.size() == 2); + REQUIRE(arr[0] == 1); + REQUIRE(arr[1] == 42); +} + +TEST_CASE("ucl: array: construct from iterator pair", "[ucl]") +{ + using namespace nihil::ucl; + + auto vec = std::vector{integer(1), integer(42)}; + auto arr = array<integer>(std::ranges::begin(vec), + std::ranges::end(vec)); + + REQUIRE(arr.size() == 2); + REQUIRE(arr[0] == 1); + REQUIRE(arr[1] == 42); +} + +TEST_CASE("ucl: array: construct from initializer_list", "[ucl]") +{ + using namespace nihil::ucl; + + auto arr = array<integer>{integer(1), integer(42)}; + + REQUIRE(arr.size() == 2); + REQUIRE(arr[0] == 1); + REQUIRE(arr[1] == 42); +} + TEST_CASE("ucl: array: push_back", "[ucl]") { using namespace nihil::ucl; @@ -45,10 +103,9 @@ TEST_CASE("ucl: array: compare", "[ucl]") { using namespace nihil::ucl; - auto arr = array<integer>(); - arr.push_back(integer(1)); - arr.push_back(integer(42)); - arr.push_back(integer(666)); + auto arr = array<integer>{ + integer(1), integer(42), integer(666) + }; auto arr2 = array<integer>(); REQUIRE(arr != arr2); @@ -58,10 +115,10 @@ TEST_CASE("ucl: array: compare", "[ucl]") arr2.push_back(integer(666)); REQUIRE(arr == arr2); - auto arr3 = array<integer>(); - arr3.push_back(integer(1)); - arr3.push_back(integer(1)); - arr3.push_back(integer(1)); + auto arr3 = array<integer>{ + integer(1), integer(1), integer(1) + }; + REQUIRE(arr != arr3); } @@ -124,7 +181,6 @@ TEST_CASE("ucl: array is a sized_range", "[ucl]") using namespace nihil::ucl; auto arr = array<integer>{integer(1), integer(42), integer(666)}; - static_assert(std::ranges::sized_range<decltype(arr)>); auto size = std::ranges::size(arr); REQUIRE(size == 3); @@ -143,7 +199,7 @@ TEST_CASE("ucl: array is a sized_range", "[ucl]") auto arr_as_ints = arr | std::views::transform(&integer::value); - auto int_vec = std::vector<integer::value_type>(); + auto int_vec = std::vector<integer::contained_type>(); std::ranges::copy(arr_as_ints, std::back_inserter(int_vec)); REQUIRE(int_vec == std::vector<std::int64_t>{1, 42, 666}); |
