include(cmake_test/cmake_test)

ct_add_test("cpp_equal")
    include(cmakepp_core/algorithm/equal)

    ct_add_section("Signature")
        set(CMAKEPP_CORE_DEBUG_MODE ON)

        ct_add_section("0th argument must be desc")
            cpp_equal(TRUE lhs rhs)
            ct_assert_fails_as("Assertion: bool is convertible to desc failed.")
        ct_end_section()

        ct_add_section("Accepts exactly 3 arguments")
            cpp_equal(result lhs rhs hello)
            ct_assert_fails_as("Function takes 3 argument(s), but 4 was/were")
        ct_end_section()
    ct_end_section()

    ct_add_section("Different Types")
        cpp_equal(result TRUE 1)
        ct_assert_equal(result FALSE)
    ct_end_section()

    ct_add_section("bool")
        ct_add_section("LHS == RHS")
            cpp_equal(result TRUE TRUE)
            ct_assert_equal(result TRUE)
        ct_end_section()

        ct_add_section("LHS != RHS")
            cpp_equal(result TRUE FALSE)
            ct_assert_equal(result FALSE)
        ct_end_section()
    ct_end_section()

    ct_add_section("descriptions")
        ct_add_section("LHS == RHS")
            cpp_equal(result "Hello World" "Hello World")
            ct_assert_equal(result TRUE)
        ct_end_section()

        ct_add_section("LHS != RHS")
            cpp_equal(result "Hello World" "foo bar")
            ct_assert_equal(result FALSE)
        ct_end_section()
    ct_end_section()

    ct_add_section("floats")
        ct_add_section("LHS == RHS")
            cpp_equal(result "3.14" "3.14")
            ct_assert_equal(result TRUE)
        ct_end_section()

        ct_add_section("LHS != RHS")
            cpp_equal(result "3.14" "1.23")
            ct_assert_equal(result FALSE)
        ct_end_section()
    ct_end_section()

    ct_add_section("ints")
        ct_add_section("LHS == RHS")
            cpp_equal(result 42 42)
            ct_assert_equal(result TRUE)
        ct_end_section()

        ct_add_section("LHS != RHS")
            cpp_equal(result 42 84)
            ct_assert_equal(result FALSE)
        ct_end_section()
    ct_end_section()

    ct_add_section("lists")
        ct_add_section("LHS == RHS")
            cpp_equal(result "Hello;World" "Hello;World")
            ct_assert_equal(result TRUE)
        ct_end_section()

        ct_add_section("LHS != RHS")
            cpp_equal(result "Hello;World" "Hello;bar")
            ct_assert_equal(result FALSE)
        ct_end_section()
    ct_end_section()

    ct_add_section("map")
        cpp_map(CTOR LHS foo bar hello world)

        ct_add_section("LHS == RHS")
            cpp_map(CTOR RHS foo bar hello world)
            cpp_equal(result "${LHS}" "${RHS}")
            ct_assert_equal(result TRUE)
        ct_end_section()

        ct_add_section("LHS != RHS")
            cpp_map(CTOR RHS foo bar)
            cpp_equal(result "${LHS}" "${RHS}")
            ct_assert_equal(result FALSE)
        ct_end_section()
    ct_end_section()

    ct_add_section("objects")
        include(cmakepp_core/class/class)

        cpp_class(MyClass)
            cpp_attr(MyClass foo bar)
        cpp_end_class()

        MyClass(ctor LHS)
        MyClass(ctor RHS)

        ct_add_section("LHS == RHS")
            cpp_equal(result "${LHS}" "${RHS}")
            ct_assert_equal(result TRUE)
        ct_end_section()

        ct_add_section("LHS != RHS")
            MyClass(SET "${RHS}" foo 42)
            cpp_equal(result "${LHS}" "${RHS}")
            ct_assert_equal(result FALSE)
        ct_end_section()
    ct_end_section()

    ct_add_section("targets")
        ct_add_section("LHS == RHS")
            add_library(a_lib STATIC IMPORTED)
            cpp_equal(result a_lib a_lib)
            ct_assert_equal(result TRUE)
        ct_end_section()

        ct_add_section("LHS != RHS")
            add_library(lhs STATIC IMPORTED)
            add_library(rhs STATIC IMPORTED)
            cpp_equal(result lhs rhs)
            ct_assert_equal(result FALSE)
        ct_end_section()
    ct_end_section()

    ct_add_section("types")
        ct_add_section("LHS == RHS")
            cpp_equal(result int int)
            ct_assert_equal(result TRUE)
        ct_end_section()

        ct_add_section("LHS != RHS")
            cpp_equal(result int bool)
            ct_assert_equal(result FALSE)
        ct_end_section()
    ct_end_section()
ct_end_test()
