From f41970666675f873d7c1075efd192f22df8d17fe Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Sun, 22 Jun 2025 14:46:53 +0100 Subject: add nihil.ucl (incomplete) --- nihil.ucl/tests/integer.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 nihil.ucl/tests/integer.cc (limited to 'nihil.ucl/tests/integer.cc') diff --git a/nihil.ucl/tests/integer.cc b/nihil.ucl/tests/integer.cc new file mode 100644 index 0000000..da119e6 --- /dev/null +++ b/nihil.ucl/tests/integer.cc @@ -0,0 +1,50 @@ +/* + * This source code is released into the public domain. + */ + +#include + +#include + +import nihil.ucl; + +TEST_CASE("ucl: integer: construct", "[ucl]") +{ + auto obj = nihil::ucl::integer(42); + REQUIRE(object_cast(obj).value() == 42); +} + +TEST_CASE("ucl: integer: compare", "[ucl]") +{ + auto i = nihil::ucl::integer(42); + + REQUIRE(i == nihil::ucl::integer(42)); + REQUIRE(i != nihil::ucl::integer(1)); + REQUIRE((i == 42) == true); + + REQUIRE(i > nihil::ucl::integer(40)); + REQUIRE(i > 40); +} + +TEST_CASE("ucl: parse: integer", "[ucl]") +{ + using namespace std::literals; + + auto input = "value = 42"sv; + auto obj = nihil::ucl::parse(input); + auto v = obj.lookup("value"); + REQUIRE(v); + REQUIRE(v->key() == "value"); + REQUIRE(object_cast(*v).value() == 42); +} + +TEST_CASE("ucl: integer: emit", "[ucl]") +{ + auto ucl = nihil::ucl::parse("int = 42;"); + + auto output = std::string(); + emit(ucl, nihil::ucl::emitter::configuration, + std::back_inserter(output)); + + REQUIRE(output == "int = 42;\n"); +} -- cgit v1.2.3