#include <adio/value.hpp> #include <catch/catch.hpp> using adio::value; TEST_CASE("Null values") { value v; auto b = v == nullptr; CHECK(b); auto b2 = v.get_type() == adio::type::null_t; CHECK(b2); CHECK(v == v); CHECK_FALSE(v != v); CHECK_FALSE(v < v); CHECK(v <= v); CHECK(v >= v); CHECK_FALSE(v > v); } TEST_CASE("Integer values") { value v{value::integer{12}}; CHECK(v == 12); CHECK(v < 14); CHECK(v != 13); CHECK(v > 9); CHECK(v != "Dogs"); }
value::ptr_type value::binary_operator(const value& rhs, binary_op op) const { ASL_ASSERT(get_type() == rhs.get_type()); #define TEST_OP(in_type, out_type, symbol) \ if (is_##in_type() == true) \ { \ value::ptr_type result = get_type().get_type_manager().create_value_##out_type(get_##in_type() symbol rhs.get_##in_type()); \ return (result); \ } switch (op) { case OP_EQUAL: { TEST_OP(bool, bool, ==) TEST_OP(uint, bool, ==) break; } case OP_NOT_EQUAL: { TEST_OP(bool, bool, !=) TEST_OP(uint, bool, !=) break; } case OP_GREATER: { TEST_OP(uint, bool, >) break; } case OP_GREATER_EQUAL: { TEST_OP(uint, bool, >=) break; } case OP_LESSER: { TEST_OP(uint, bool, <) break; } case OP_LESSER_EQUAL: { TEST_OP(uint, bool, <=) break; } case OP_ADD: { TEST_OP(uint, uint, +) break; } case OP_SUB: { TEST_OP(uint, uint, -) break; } case OP_MUL: { TEST_OP(uint, uint, *) break; } case OP_DIV: { TEST_OP(uint, uint, /) break; } } #undef TEST_OP ASL_ASSERT(false); return (NULL); }