From 64a3d017f0569d986de4f9cf8402e3bfe4b680a2 Mon Sep 17 00:00:00 2001 From: aiekick Date: Sun, 7 Jul 2024 02:49:30 +0200 Subject: [PATCH] [FIX] : add some extended number format like strtod --- ImGuiFileDialog | 2 +- tests/CMakeLists.txt | 1 + tests/ImGuiFileDialog/Test_Utils.cpp | 47 +++++++++++++++++++++++----- tests/main.cpp | 4 +-- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/ImGuiFileDialog b/ImGuiFileDialog index d0dd6cc..a027816 160000 --- a/ImGuiFileDialog +++ b/ImGuiFileDialog @@ -1 +1 @@ -Subproject commit d0dd6cce164727efd2f2ffac553ffdeaebe8dc91 +Subproject commit a027816b686613d1d6af8fa1b203a1b0e6001b41 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 16b36a1..52797f2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -172,6 +172,7 @@ SetTest(Test_IGFD_Utils_IsAValidCharForADigit_0) SetTest(Test_IGFD_Utils_ExtractNumFromStringAtPos_0) SetTest(Test_IGFD_Utils_ExtractNumFromStringAtPos_1) +SetTest(Test_IGFD_Utils_ExtractNumFromStringAtPos_2) SetTest(Test_IGFD_Utils_NaturalCompare_0) SetTest(Test_IGFD_Utils_NaturalCompare_1) diff --git a/tests/ImGuiFileDialog/Test_Utils.cpp b/tests/ImGuiFileDialog/Test_Utils.cpp index 17e7c10..5c63d4d 100644 --- a/tests/ImGuiFileDialog/Test_Utils.cpp +++ b/tests/ImGuiFileDialog/Test_Utils.cpp @@ -1,8 +1,9 @@ #include "Test_FileStyle.h" #include +#include -#include "ImGuiFileDialog/ImGuiFileDialog.h" +#include //////////////////////////////////////////////////////////////////////////// //// ReplaceString ///////////////////////////////////////////////////////// @@ -178,6 +179,11 @@ bool Test_IGFD_Utils_IsAValidCharForADigit_0() { if (!IGFD::Utils::M_IsAValidCharForADigit('+')) return false; if (!IGFD::Utils::M_IsAValidCharForADigit('.')) return false; if (!IGFD::Utils::M_IsAValidCharForADigit('e')) return false; + if (!IGFD::Utils::M_IsAValidCharForADigit('E')) return false; + if (!IGFD::Utils::M_IsAValidCharForADigit('x')) return false; + if (!IGFD::Utils::M_IsAValidCharForADigit('X')) return false; + if (!IGFD::Utils::M_IsAValidCharForADigit('p')) return false; + if (!IGFD::Utils::M_IsAValidCharForADigit('P')) return false; if (!IGFD::Utils::M_IsAValidCharForADigit('0')) return false; if (!IGFD::Utils::M_IsAValidCharForADigit('1')) return false; if (!IGFD::Utils::M_IsAValidCharForADigit('2')) return false; @@ -200,7 +206,7 @@ bool Test_IGFD_Utils_IsAValidCharForADigit_0() { // invalids numbers bool Test_IGFD_Utils_ExtractNumFromStringAtPos_0() { - float n = 0.0f; + double n = 0.0; size_t p = 0; if (IGFD::Utils::M_ExtractNumFromStringAtPos("++2.5", p = 0, n)) return false; if (IGFD::Utils::M_ExtractNumFromStringAtPos("--2.5", p = 0, n)) return false; @@ -214,22 +220,48 @@ bool Test_IGFD_Utils_ExtractNumFromStringAtPos_0() { if (IGFD::Utils::M_ExtractNumFromStringAtPos("-", p = 0, n)) return false; if (IGFD::Utils::M_ExtractNumFromStringAtPos("e", p = 0, n)) return false; if (IGFD::Utils::M_ExtractNumFromStringAtPos(".", p = 0, n)) return false; + + // supported by strtod but will slow down more andwhy sorting by that + if (IGFD::Utils::M_ExtractNumFromStringAtPos("INF", p = 0, n)) return false; + if (IGFD::Utils::M_ExtractNumFromStringAtPos("NAN", p = 0, n)) return false; return true; } -// valids cases, verify number and new pos +// valid numbers bool Test_IGFD_Utils_ExtractNumFromStringAtPos_1() { - float n = 0.0f; + double n = 0.0; + size_t p = 0; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("+2.5", p = 0, n)) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("-2.5", p = 0, n)) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos(".2.5", p = 0, n)) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("-2.5", p = 0, n)) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("+2.5", p = 0, n)) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("1e-5", p = 0, n)) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("1E32.5", p = 0, n)) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("0x14", p = 0, n)) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("0X14", p = 0, n)) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("2p2.5", p = 0, n)) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("2.5P-2.9", p = 0, n)) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("4588E4588", p = 0, n)) return false; + return true; +} + +// valids cases, verify number and new pos +bool Test_IGFD_Utils_ExtractNumFromStringAtPos_2() { + double n = 0.0; size_t p = 0; if (!IGFD::Utils::M_ExtractNumFromStringAtPos("abc-2.8abc", p = 3, n)) return false; - if (n != -2.8f) return false; + if (n != -2.8) return false; if (p != 7U) return false; if (!IGFD::Utils::M_ExtractNumFromStringAtPos("abc+8.9abc", p = 3, n)) return false; - if (n != 8.9f) return false; + if (n != 8.9) return false; if (p != 7U) return false; if (!IGFD::Utils::M_ExtractNumFromStringAtPos("abc10.6546abc", p = 3, n)) return false; - if (n != 10.6546f) return false; + if (n != 10.6546) return false; if (p != 10U) return false; + if (!IGFD::Utils::M_ExtractNumFromStringAtPos("4588E4588", p = 3, n)) return false; + if (!std::isinf(n)) return false; + if (p != 9U) return false; return true; } @@ -487,6 +519,7 @@ bool Test_Utils(const std::string& vTest) { IfTestExist(Test_IGFD_Utils_IsAValidCharForADigit_0); else IfTestExist(Test_IGFD_Utils_ExtractNumFromStringAtPos_0); else IfTestExist(Test_IGFD_Utils_ExtractNumFromStringAtPos_1); + else IfTestExist(Test_IGFD_Utils_ExtractNumFromStringAtPos_2); else IfTestExist(Test_IGFD_Utils_NaturalCompare_0); else IfTestExist(Test_IGFD_Utils_NaturalCompare_1); else IfTestExist(Test_IGFD_Utils_NaturalCompare_2); diff --git a/tests/main.cpp b/tests/main.cpp index 0271139..85d9702 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -7,7 +7,7 @@ #define GetCurrentDir _getcwd #define SetCurrentDir _chdir #define ROOT_SLASH "\\" -#elif defined(UNIX) +#else #include // chdir #define GetCurrentDir getcwd #define SetCurrentDir chdir @@ -29,7 +29,7 @@ int main(int argc, char** argv) { return Test_ImGuiFileDialog(argv[1]) ? 0 : 1; } - return Test_ImGuiFileDialog("Test_IGFD_Utils_NaturalCompare_2") ? 0 : 1; + return Test_ImGuiFileDialog("Test_IGFD_Utils_ExtractNumFromStringAtPos_2") ? 0 : 1; return 0; } \ No newline at end of file