aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.ucl/tests/integer.cc
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-22 14:46:53 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-22 14:46:53 +0100
commitf41970666675f873d7c1075efd192f22df8d17fe (patch)
tree09b8c4da91a7efeb37a92d322d3e729e4dbde659 /nihil.ucl/tests/integer.cc
parentd27d1302d1fa1b96bf8f53f17fce947f19d21330 (diff)
downloadnihil-f41970666675f873d7c1075efd192f22df8d17fe.tar.gz
nihil-f41970666675f873d7c1075efd192f22df8d17fe.tar.bz2
add nihil.ucl (incomplete)
Diffstat (limited to 'nihil.ucl/tests/integer.cc')
-rw-r--r--nihil.ucl/tests/integer.cc50
1 files changed, 50 insertions, 0 deletions
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 <string>
+
+#include <catch2/catch_test_macros.hpp>
+
+import nihil.ucl;
+
+TEST_CASE("ucl: integer: construct", "[ucl]")
+{
+ auto obj = nihil::ucl::integer(42);
+ REQUIRE(object_cast<nihil::ucl::integer>(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<nihil::ucl::integer>(*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");
+}