aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.ucl/tests/integer.cc
blob: da119e6e871e5f86754641c0703ce2f6b4c71d41 (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>

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");
}