mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 05:57:42 +00:00
LibTimeZone: Add a unit test for generated time zone data
This commit is contained in:
parent
ccce9e5c7f
commit
b493c2ca90
4 changed files with 69 additions and 0 deletions
|
@ -576,6 +576,15 @@ if (BUILD_LAGOM)
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibTLS)
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibTLS)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
# TimeZone
|
||||||
|
file(GLOB LIBTIMEZONE_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/LibTimeZone/*.cpp")
|
||||||
|
foreach(source ${LIBTIMEZONE_TEST_SOURCES})
|
||||||
|
lagom_test(${source} LIBS LagomTimeZone)
|
||||||
|
|
||||||
|
get_filename_component(target "${source}" NAME_WLE)
|
||||||
|
target_compile_definitions("${target}_lagom" PRIVATE ENABLE_TIME_ZONE_DATA=$<BOOL:${ENABLE_TIME_ZONE_DATABASE_DOWNLOAD}>)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
# Unicode
|
# Unicode
|
||||||
file(GLOB LIBUNICODE_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/LibUnicode/*.cpp")
|
file(GLOB LIBUNICODE_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/LibUnicode/*.cpp")
|
||||||
foreach(source ${LIBUNICODE_TEST_SOURCES})
|
foreach(source ${LIBUNICODE_TEST_SOURCES})
|
||||||
|
|
|
@ -17,6 +17,7 @@ add_subdirectory(LibRegex)
|
||||||
add_subdirectory(LibSQL)
|
add_subdirectory(LibSQL)
|
||||||
add_subdirectory(LibTest)
|
add_subdirectory(LibTest)
|
||||||
add_subdirectory(LibThreading)
|
add_subdirectory(LibThreading)
|
||||||
|
add_subdirectory(LibTimeZone)
|
||||||
add_subdirectory(LibUnicode)
|
add_subdirectory(LibUnicode)
|
||||||
add_subdirectory(LibWasm)
|
add_subdirectory(LibWasm)
|
||||||
add_subdirectory(LibWeb)
|
add_subdirectory(LibWeb)
|
||||||
|
|
10
Tests/LibTimeZone/CMakeLists.txt
Normal file
10
Tests/LibTimeZone/CMakeLists.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
set(TEST_SOURCES
|
||||||
|
TestTimeZone.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach(source IN LISTS TEST_SOURCES)
|
||||||
|
serenity_test("${source}" LibTimeZone LIBS LibTimeZone)
|
||||||
|
|
||||||
|
get_filename_component(target "${source}" NAME_WLE)
|
||||||
|
target_compile_definitions("${target}" PRIVATE ENABLE_TIME_ZONE_DATA=$<BOOL:${ENABLE_TIME_ZONE_DATABASE_DOWNLOAD}>)
|
||||||
|
endforeach()
|
49
Tests/LibTimeZone/TestTimeZone.cpp
Normal file
49
Tests/LibTimeZone/TestTimeZone.cpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Tim Flynn <trflynn89@pm.me>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibTest/TestCase.h>
|
||||||
|
|
||||||
|
#include <AK/StringView.h>
|
||||||
|
#include <LibTimeZone/TimeZone.h>
|
||||||
|
|
||||||
|
#if ENABLE_TIME_ZONE_DATA
|
||||||
|
|
||||||
|
# include <LibTimeZone/TimeZoneData.h>
|
||||||
|
|
||||||
|
TEST_CASE(time_zone_from_string)
|
||||||
|
{
|
||||||
|
EXPECT_EQ(TimeZone::time_zone_from_string("America/New_York"sv), TimeZone::TimeZone::America_New_York);
|
||||||
|
EXPECT_EQ(TimeZone::time_zone_from_string("Europe/Paris"sv), TimeZone::TimeZone::Europe_Paris);
|
||||||
|
EXPECT_EQ(TimeZone::time_zone_from_string("Etc/GMT+2"sv), TimeZone::TimeZone::Etc_GMT_Ahead_2);
|
||||||
|
EXPECT_EQ(TimeZone::time_zone_from_string("Etc/GMT-5"sv), TimeZone::TimeZone::Etc_GMT_Behind_5);
|
||||||
|
|
||||||
|
EXPECT(!TimeZone::time_zone_from_string("I don't exist"sv).has_value());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE(time_zone_from_string_link)
|
||||||
|
{
|
||||||
|
auto test_link = [](auto tz1, auto tz2) {
|
||||||
|
auto result1 = TimeZone::time_zone_from_string(tz1);
|
||||||
|
EXPECT(result1.has_value());
|
||||||
|
|
||||||
|
auto result2 = TimeZone::time_zone_from_string(tz2);
|
||||||
|
EXPECT(result2.has_value());
|
||||||
|
|
||||||
|
EXPECT_EQ(*result1, *result2);
|
||||||
|
};
|
||||||
|
|
||||||
|
test_link("America/New_York"sv, "US/Eastern"sv);
|
||||||
|
|
||||||
|
test_link("Etc/GMT"sv, "GMT"sv);
|
||||||
|
test_link("Etc/GMT+0"sv, "GMT"sv);
|
||||||
|
test_link("Etc/GMT-0"sv, "GMT"sv);
|
||||||
|
|
||||||
|
test_link("Etc/UTC"sv, "UTC"sv);
|
||||||
|
test_link("Etc/Universal"sv, "UTC"sv);
|
||||||
|
test_link("Universal"sv, "UTC"sv);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue