include(cmake_test/cmake_test)

ct_add_test("_cpp_object_add_fxn")
    include(cmakepp_core/object/object)

    _cpp_object_ctor(an_object obj)
    cpp_map(CTOR corr)

    ct_add_section("Signature")
        set(CMAKEPP_CORE_DEBUG_MODE ON)

        ct_add_section("0th argument must be obj")
            _cpp_object_add_fxn(TRUE a_fxn)
            ct_assert_fails_as("Assertion: bool is convertible to obj failed.")
        ct_end_section()

        ct_add_section("1st argument must be desc")
            _cpp_object_add_fxn("${an_object}" TRUE)
            ct_assert_fails_as("Assertion: bool is convertible to desc failed.")
        ct_end_section()
    ct_end_section()

    ct_add_section("No arguments")
        _cpp_object_add_fxn("${an_object}" a_fxn)
        set(corr_mn _cpp_obj_a_fxn_)

        ct_add_section("Returns mangled name")
            ct_assert_equal(a_fxn "${corr_mn}")
        ct_end_section()

        ct_add_section("Adds correct value")
            set(args a_fxn)
            cpp_map(SET "${corr}" "${corr_mn}" "${args}")
            _cpp_object_get_meta_attr("${an_object}" fxns fxns)
            cpp_map(EQUAL "${corr}" result "${fxns}")
            ct_assert_equal(result TRUE)
        ct_end_section()
    ct_end_section()

    ct_add_section("Pure variadic")
        _cpp_object_add_fxn("${an_object}" a_fxn args)
        set(corr_mn _cpp_obj_a_fxn_args_)

        ct_add_section("Returns mangled name")
            ct_assert_equal(a_fxn "${corr_mn}")
        ct_end_section()

        ct_add_section("Adds correct value")
            set(args a_fxn args)
            cpp_map(SET "${corr}" "${corr_mn}" "${args}")
            _cpp_object_get_meta_attr("${an_object}" fxns fxns)
            cpp_map(EQUAL "${corr}" result "${fxns}")
            ct_assert_equal(result TRUE)
        ct_end_section()
    ct_end_section()

    ct_add_section("Non-variadic one argument")
        _cpp_object_add_fxn("${an_object}" a_fxn int)
        set(corr_mn _cpp_obj_a_fxn_int_)

        ct_add_section("Returns mangled name")
            ct_assert_equal(a_fxn "${corr_mn}")
        ct_end_section()

        ct_add_section("Adds correct value")
            set(args a_fxn int)
            cpp_map(SET "${corr}" "${corr_mn}" "${args}")
            _cpp_object_get_meta_attr("${an_object}" fxns fxns)
            cpp_map(EQUAL "${corr}" result "${fxns}")
            ct_assert_equal(result TRUE)
        ct_end_section()
    ct_end_section()

    ct_add_section("Variadic one argument")
        _cpp_object_add_fxn("${an_object}" a_fxn int args)
        set(corr_mn _cpp_obj_a_fxn_int_args_)

        ct_add_section("Returns mangled name")
            ct_assert_equal(a_fxn "${corr_mn}")
        ct_end_section()

        ct_add_section("Adds correct value")
            set(args a_fxn int args)
            cpp_map(SET "${corr}" "${corr_mn}" "${args}")
            _cpp_object_get_meta_attr("${an_object}" fxns fxns)
            cpp_map(EQUAL "${corr}" result "${fxns}")
            ct_assert_equal(result TRUE)
        ct_end_section()
    ct_end_section()

    ct_add_section("Non-variadic two arguments")
        _cpp_object_add_fxn("${an_object}" a_fxn int bool)
        set(corr_mn _cpp_obj_a_fxn_int_bool_)

        ct_add_section("Returns mangled name")
            ct_assert_equal(a_fxn "${corr_mn}")
        ct_end_section()

        ct_add_section("Adds correct value")
            set(args a_fxn int bool)
            cpp_map(SET "${corr}" "${corr_mn}" "${args}")
            _cpp_object_get_meta_attr("${an_object}" fxns fxns)
            cpp_map(EQUAL "${corr}" result "${fxns}")
            ct_assert_equal(result TRUE)
        ct_end_section()
    ct_end_section()

    ct_add_section("Variadic two arguments")
        _cpp_object_add_fxn("${an_object}" a_fxn int bool args)
        set(corr_mn _cpp_obj_a_fxn_int_bool_args_)

        ct_add_section("Returns mangled name")
            ct_assert_equal(a_fxn "${corr_mn}")
        ct_end_section()

        ct_add_section("Adds correct value")
            set(args a_fxn int bool args)
            cpp_map(SET "${corr}" "${corr_mn}" "${args}")
            _cpp_object_get_meta_attr("${an_object}" fxns fxns)
            cpp_map(EQUAL "${corr}" result "${fxns}")
            ct_assert_equal(result TRUE)
        ct_end_section()
    ct_end_section()
ct_end_test()
