diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-22 14:46:53 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-22 14:46:53 +0100 |
| commit | f41970666675f873d7c1075efd192f22df8d17fe (patch) | |
| tree | 09b8c4da91a7efeb37a92d322d3e729e4dbde659 /nihil.ucl/tests/parse.cc | |
| parent | d27d1302d1fa1b96bf8f53f17fce947f19d21330 (diff) | |
| download | nihil-f41970666675f873d7c1075efd192f22df8d17fe.tar.gz nihil-f41970666675f873d7c1075efd192f22df8d17fe.tar.bz2 | |
add nihil.ucl (incomplete)
Diffstat (limited to 'nihil.ucl/tests/parse.cc')
| -rw-r--r-- | nihil.ucl/tests/parse.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/nihil.ucl/tests/parse.cc b/nihil.ucl/tests/parse.cc new file mode 100644 index 0000000..3a4f061 --- /dev/null +++ b/nihil.ucl/tests/parse.cc @@ -0,0 +1,50 @@ +/* + * This source code is released into the public domain. + */ + +#include <string> + +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_floating_point.hpp> + +import nihil; +import nihil.ucl; + +TEST_CASE("ucl parse: iterate array", "[ucl]") +{ + using namespace std::literals; + + auto input = "value = [1, 42, 666];"sv; + auto obj = nihil::ucl::parse(input); + + auto array = obj.lookup("value"); + REQUIRE(array); + REQUIRE(array->key() == "value"); + + auto vec = std::vector<nihil::ucl::object>(); + std::ranges::copy(*array, std::back_inserter(vec)); + REQUIRE(vec.size() == 3); + REQUIRE(object_cast<nihil::ucl::integer>(vec[0]).value() == 1); + REQUIRE(object_cast<nihil::ucl::integer>(vec[1]).value() == 42); + REQUIRE(object_cast<nihil::ucl::integer>(vec[2]).value() == 666); +} + +TEST_CASE("ucl parse: iterate hash", "[ucl]") +{ + using namespace std::literals; + + auto input = "int = 42; bool = true; str = \"test\";"sv; + auto obj = nihil::ucl::parse(input); + + for (auto &&value : obj) { + if (value.key() == "int") + REQUIRE(object_cast<nihil::ucl::integer>(value).value() + == 42); + else if (value.key() == "bool") + REQUIRE(object_cast<nihil::ucl::boolean>(value).value() + == true); + else if (value.key() == "str") + REQUIRE(object_cast<nihil::ucl::string>(value).value() + == "test"); + } +} |
