blob: 3a4f061c539462f8a034201553255fbccbda9f7b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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");
}
}
|