From 1ae694ccd119839ae856b6db5c95323e723ced94 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 9 Dec 2025 19:19:00 -0600 Subject: [PATCH] chore(test): add tests for GxuDetermineQuotedCode --- test/CMakeLists.txt | 15 +++++++-- test/gx/font/GxuFont.cpp | 73 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 test/gx/font/GxuFont.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a8f0ab1..a2292d6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,11 @@ if(WHOA_SYSTEM_MAC) - file(GLOB PRIVATE_SOURCES "Test.cpp" "stub/Mac.mm" "gx/*.cpp" "util/*.cpp") + file(GLOB PRIVATE_SOURCES + "Test.cpp" + "stub/Mac.mm" + "gx/*.cpp" + "gx/font/*.cpp" + "util/*.cpp" + ) set_source_files_properties(${PRIVATE_SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c++" @@ -20,7 +26,12 @@ if(WHOA_SYSTEM_MAC) endif() if(WHOA_SYSTEM_WIN OR WHOA_SYSTEM_LINUX) - file(GLOB PRIVATE_SOURCES "Test.cpp" "gx/*.cpp" "util/*.cpp") + file(GLOB PRIVATE_SOURCES + "Test.cpp" + "gx/*.cpp" + "gx/font/*.cpp" + "util/*.cpp" + ) add_executable(WhoaTest ${PRIVATE_SOURCES}) diff --git a/test/gx/font/GxuFont.cpp b/test/gx/font/GxuFont.cpp new file mode 100644 index 0000000..5dcbbee --- /dev/null +++ b/test/gx/font/GxuFont.cpp @@ -0,0 +1,73 @@ +#include "gx/font/GxuFont.hpp" +#include +#include "catch.hpp" + +TEST_CASE("GxuDetermineQuotedCode", "[gx]") { + SECTION("does not recognize non-quoted code") { + const char* str = "test1"; + uint32_t flags = 0x0; + + int32_t advance; + uint32_t code; + QUOTEDCODE quotedCode; + + quotedCode = GxuDetermineQuotedCode(str, advance, nullptr, flags, code); + REQUIRE(quotedCode == CODE_INVALIDCODE); + REQUIRE(advance == 1); + } + + SECTION("recognizes newlines") { + const char* str = "test1\ntest2\rtest3\r\ntest4"; + uint32_t flags = 0x0; + + int32_t advance; + uint32_t code; + QUOTEDCODE quotedCode; + + // \n + str += 5; + quotedCode = GxuDetermineQuotedCode(str, advance, nullptr, flags, code); + REQUIRE(quotedCode == CODE_NEWLINE); + REQUIRE(advance == 1); + str += advance; + + // \r + str += 5; + quotedCode = GxuDetermineQuotedCode(str, advance, nullptr, flags, code); + REQUIRE(quotedCode == CODE_NEWLINE); + REQUIRE(advance == 1); + str += advance; + + // \r\n + str += 5; + quotedCode = GxuDetermineQuotedCode(str, advance, nullptr, flags, code); + REQUIRE(quotedCode == CODE_NEWLINE); + REQUIRE(advance == 2); + } + + SECTION("recognizes quoted newlines") { + const char* str = "test1|ntest2|n|ntest3"; + uint32_t flags = 0x0; + + int32_t advance; + uint32_t code; + QUOTEDCODE quotedCode; + + // |n + str += 5; + quotedCode = GxuDetermineQuotedCode(str, advance, nullptr, flags, code); + REQUIRE(quotedCode == CODE_NEWLINE); + REQUIRE(advance == 2); + str += advance; + + // |n|n + str += 5; + quotedCode = GxuDetermineQuotedCode(str, advance, nullptr, flags, code); + REQUIRE(quotedCode == CODE_NEWLINE); + REQUIRE(advance == 2); + str += advance; + quotedCode = GxuDetermineQuotedCode(str, advance, nullptr, flags, code); + REQUIRE(quotedCode == CODE_NEWLINE); + REQUIRE(advance == 2); + } +}