## Simply run:
## $ cmake -P tests/NuGetTools.helper.test.cmake
cmake_minimum_required(VERSION 3.8.2 FATAL_ERROR)
set(PROJECT_ROOT "${CMAKE_CURRENT_LIST_DIR}/..")
include("${PROJECT_ROOT}/cmake/internal/NuGetTools.helper.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/TestHelpers.cmake")

## Test input
set(TEST_PACKAGE_LIST_HEAD PACKAGE flatbuffers VERSION 1.11.0)
set(TEST_PACKAGE_LIST_TAIL PACKAGE icu VERSION 65.1)
set(TEST_PACKAGE_LIST "${TEST_PACKAGE_LIST_HEAD};${TEST_PACKAGE_LIST_TAIL}")

## Test cases
function(test_nuget_internal_helper_cut_arg_list_1)
    nuget_internal_helper_cut_arg_list(PACKAGE "${TEST_PACKAGE_LIST}" HEAD TAIL)
    message("test_nuget_internal_helper_cut_arg_list_1(PACKAGE \"${TEST_PACKAGE_LIST}\" \"${HEAD}\" \"${TAIL}\")")
    assert("${TEST_PACKAGE_LIST_HEAD}" STREQUAL "${HEAD}")
    assert("${TEST_PACKAGE_LIST_TAIL}" STREQUAL "${TAIL}")
endfunction()

function(test_nuget_internal_helper_cut_arg_list_2)
    list(JOIN TEST_PACKAGE_LIST " " TEST_PACKAGE_STRING)
    nuget_internal_helper_cut_arg_list(PACKAGE ${TEST_PACKAGE_STRING} HEAD TAIL)
    message("test_nuget_internal_helper_cut_arg_list_2(PACKAGE \"${TEST_PACKAGE_STRING}\" \"${HEAD}\" \"${TAIL}\")")
    assert("${TEST_PACKAGE_STRING}" STREQUAL "${HEAD}")
    assert("" STREQUAL "${TAIL}")
endfunction()

function(test_nuget_internal_helper_cut_arg_list_3)
    set(TEST_LIST_GARBAGE CONFIG MODULE)
    set(TAIL "${TEST_PACKAGE_LIST_HEAD};${TEST_PACKAGE_LIST_TAIL};${TEST_LIST_GARBAGE}")
    nuget_internal_helper_cut_arg_list(PACKAGE "${TAIL}" HEAD TAIL)
    message("test_nuget_internal_helper_cut_arg_list_3(PACKAGE _ \"${HEAD}\" \"${TAIL}\")")
    assert("${TEST_PACKAGE_LIST_HEAD}" STREQUAL "${HEAD}")
    assert("${TEST_PACKAGE_LIST_TAIL};${TEST_LIST_GARBAGE}" STREQUAL "${TAIL}")
    nuget_internal_helper_cut_arg_list(PACKAGE "${TAIL}" HEAD TAIL)
    message("test_nuget_internal_helper_cut_arg_list_3(PACKAGE _ \"${HEAD}\" \"${TAIL}\")")
    assert("${TEST_PACKAGE_LIST_TAIL};${TEST_LIST_GARBAGE}" STREQUAL "${HEAD}")
    assert("" STREQUAL "${TAIL}")
    nuget_internal_helper_cut_arg_list(PACKAGE "${TAIL}" HEAD TAIL)
    message("test_nuget_internal_helper_cut_arg_list_3(PACKAGE _ \"${HEAD}\" \"${TAIL}\")")
    assert("" STREQUAL "${HEAD}")
    assert("" STREQUAL "${TAIL}")
    message("test_nuget_internal_helper_cut_arg_list_3(PACKAGE _ \"${HEAD}\" \"${TAIL}\")")
    assert("" STREQUAL "${HEAD}")
    assert("" STREQUAL "${TAIL}")
endfunction()

function(test_nuget_internal_helper_list_transform_prepend_1)
    set(LIST "")
    nuget_internal_helper_list_transform_prepend("${LIST}" "joe" LIST)
    assert("" STREQUAL "${LIST}")
endfunction()

function(test_nuget_internal_helper_list_transform_prepend_2)
    set(LIST "/postfix")
    nuget_internal_helper_list_transform_prepend("${LIST}" "joe" LIST)
    assert("joe/postfix" STREQUAL "${LIST}")
endfunction()

function(test_nuget_internal_helper_list_transform_prepend_3)
    set(LIST "/postfix1" "/postfix2")
    nuget_internal_helper_list_transform_prepend("${LIST}" "joe" LIST)
    assert("joe/postfix1;joe/postfix2" STREQUAL "${LIST}")
endfunction()

## Invoke test cases
test_nuget_internal_helper_cut_arg_list_1()
test_nuget_internal_helper_cut_arg_list_2()
test_nuget_internal_helper_cut_arg_list_3()
test_nuget_internal_helper_list_transform_prepend_1()
test_nuget_internal_helper_list_transform_prepend_2()
test_nuget_internal_helper_list_transform_prepend_3()
