
include ("${RunCMake_SOURCE_DIR}/check_errors.cmake")
unset (errors)

set(source_unsorted c/B.h a/c.h B/a.h)

set(listvar ${source_unsorted})
list(SORT listvar)
set (output "$<LIST:SORT,c/B.h;a/c.h;B/a.h>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()

set(listvar ${source_unsorted})
list(SORT listvar CASE INSENSITIVE ORDER ASCENDING COMPARE STRING)
set (output "$<LIST:SORT,c/B.h;a/c.h;B/a.h,CASE:INSENSITIVE,ORDER:ASCENDING,COMPARE:STRING>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()

set(listvar ${source_unsorted})
list(SORT listvar CASE INSENSITIVE ORDER DESCENDING COMPARE STRING)
set (output "$<LIST:SORT,c/B.h;a/c.h;B/a.h,CASE:INSENSITIVE,ORDER:DESCENDING,COMPARE:STRING>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()

set(listvar ${source_unsorted})
list(SORT listvar CASE SENSITIVE ORDER ASCENDING COMPARE STRING)
set (output "$<LIST:SORT,c/B.h;a/c.h;B/a.h,CASE:SENSITIVE,ORDER:ASCENDING,COMPARE:STRING>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()

set(listvar ${source_unsorted})
list(SORT listvar CASE SENSITIVE ORDER DESCENDING COMPARE STRING)
set (output "$<LIST:SORT,c/B.h;a/c.h;B/a.h,CASE:SENSITIVE,ORDER:DESCENDING,COMPARE:STRING>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()

set(listvar ${source_unsorted})
list(SORT listvar CASE INSENSITIVE ORDER ASCENDING COMPARE FILE_BASENAME)
set (output "$<LIST:SORT,c/B.h;a/c.h;B/a.h,CASE:INSENSITIVE,ORDER:ASCENDING,COMPARE:FILE_BASENAME>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()

set(listvar ${source_unsorted})
list(SORT listvar CASE INSENSITIVE ORDER DESCENDING COMPARE FILE_BASENAME)
set (output "$<LIST:SORT,c/B.h;a/c.h;B/a.h,CASE:INSENSITIVE,ORDER:DESCENDING,COMPARE:FILE_BASENAME>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()

set(listvar ${source_unsorted})
list(SORT listvar CASE SENSITIVE ORDER ASCENDING COMPARE FILE_BASENAME)
set (output "$<LIST:SORT,c/B.h;a/c.h;B/a.h,CASE:SENSITIVE,ORDER:ASCENDING,COMPARE:FILE_BASENAME>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()

set(listvar ${source_unsorted})
list(SORT listvar CASE SENSITIVE ORDER DESCENDING COMPARE FILE_BASENAME)
set (output "$<LIST:SORT,c/B.h;a/c.h;B/a.h,CASE:SENSITIVE,ORDER:DESCENDING,COMPARE:FILE_BASENAME>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()

set(listvar 10.0 1.1 2.1 8.0 2.0 3.1)
list(SORT listvar CASE SENSITIVE ORDER DESCENDING COMPARE STRING)
set (output "$<LIST:SORT,10.0;1.1;2.1;8.0;2.0;3.1,CASE:SENSITIVE,ORDER:DESCENDING,COMPARE:STRING>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()

set(listvar 10.0 1.1 2.1 8.0 2.0 3.1)
list(SORT listvar CASE SENSITIVE ORDER DESCENDING COMPARE NATURAL)
set (output "$<LIST:SORT,10.0;1.1;2.1;8.0;2.0;3.1,CASE:SENSITIVE,ORDER:DESCENDING,COMPARE:NATURAL>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()

set(listvar 10.0 1.1 2.1 8.0 2.0 3.1)
list(SORT listvar CASE SENSITIVE ORDER ASCENDING COMPARE NATURAL)
set (output "$<LIST:SORT,10.0;1.1;2.1;8.0;2.0;3.1,CASE:SENSITIVE,ORDER:ASCENDING,COMPARE:NATURAL>")
if (NOT output STREQUAL listvar)
  list (APPEND errors "returns bad value: ${output}")
endif()


check_errors("LIST:SORT..." ${errors})
