From d5cbf91b90e40d0325357b02d6be8b435649dd0c Mon Sep 17 00:00:00 2001 From: seleznevae Date: Fri, 24 May 2019 21:25:33 +0300 Subject: [PATCH] [A] Added tests for mk_wcswidth --- .drone.yml | 12 ++----- ChangeLog.md | 6 ++++ tests/wb_tests/test_string_buffer.c | 53 +++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/.drone.yml b/.drone.yml index ef1faa6..528678b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,13 +10,11 @@ steps: image: alpine commands: - apk add gcc g++ cmake make binutils-gold - - CMAKE_C_FLAGS="-Werror" - - CMAKE_CXX_FLAGS="-Werror" - ls - uname -a - mkdir -p build - cd build - - cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" + - cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" - cmake --build . --target all - ls - ctest -VV @@ -34,13 +32,11 @@ steps: image: alpine commands: - apk add gcc g++ cmake make binutils-gold - - CMAKE_C_FLAGS="-Werror" - - CMAKE_CXX_FLAGS="-Werror" - ls - uname -a - mkdir -p build - cd build - - cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" + - cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" - cmake --build . --target all - ls - ctest -VV @@ -57,13 +53,11 @@ steps: image: alpine commands: - apk add gcc g++ cmake make binutils-gold - - CMAKE_C_FLAGS="-Werror" - - CMAKE_CXX_FLAGS="-Werror" - ls - uname -a - mkdir -p build - cd build - - cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" + - cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" - cmake --build . --target all - ls - ctest -VV \ No newline at end of file diff --git a/ChangeLog.md b/ChangeLog.md index 4e9bd58..134de9b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,9 @@ +## v0.1.5 + +### Tests + +- Add tests for 'mk_wcswidth' function. + ## v0.1.4 ### Internal diff --git a/tests/wb_tests/test_string_buffer.c b/tests/wb_tests/test_string_buffer.c index 47ff884..792f808 100644 --- a/tests/wb_tests/test_string_buffer.c +++ b/tests/wb_tests/test_string_buffer.c @@ -1,5 +1,6 @@ #include "tests.h" #include "string_buffer.h" +#include "wcwidth.h" #include @@ -20,6 +21,9 @@ void test_strchr_count(void); void test_str_n_substring(void); void test_buffer_text_width(void); void test_buffer_text_height(void); +#if defined(FT_HAVE_WCHAR) +void test_wchar_basics(void); +#endif void test_string_buffer(void) @@ -28,6 +32,9 @@ void test_string_buffer(void) test_str_n_substring(); test_buffer_text_width(); test_buffer_text_height(); +#if defined(FT_HAVE_WCHAR) + test_wchar_basics(); +#endif } @@ -314,3 +321,49 @@ void test_buffer_text_height(void) buffer->str.cstr = old_value; destroy_string_buffer(buffer); } + +#if defined(FT_HAVE_WCHAR) +void test_wchar_basics(void) +{ +#if !defined(FT_MICROSOFT_COMPILER) + assert_true(mk_wcswidth(L"", 0) == 0); + assert_true(mk_wcswidth(L"1", 0) == 0); + + assert_true(mk_wcswidth(L"1", 1) == 1); + assert_true(mk_wcswidth(L"λ", 1) == 1); // Greek + assert_true(mk_wcswidth(L"ऋ", 1) == 1); // Hindi + assert_true(mk_wcswidth(L"ź", 1) == 1); // Polish + assert_true(mk_wcswidth(L"ü", 1) == 1); // Portuguese + assert_true(mk_wcswidth(L"ц", 1) == 1); // Russian + assert_true(mk_wcswidth(L"ñ", 1) == 1); // Spanish + assert_true(mk_wcswidth(L"ğ", 1) == 1); // Turkish + + + assert_true(mk_wcswidth(L"ФЦУЙъхЭЯЧьЮЪЁ", 13) == 13); + assert_true(mk_wcswidth(L"ФЦУЙъхЭЯЧьЮЪЁ", 14) == 13); + assert_true(mk_wcswidth(L"ФЦУЙъхЭЯЧьЮЪЁ", 10) == 10); + + /* panagrams from http://clagnut.com/blog/2380/ */ + const wchar_t *str = NULL; + /* 10 20 30 40 50 60 70 80 90 100 110 */ + str = L"Numbers 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; + assert_true(mk_wcswidth(str, 500) == 110); + str = L"German Falsches Üben von Xylophonmusik quält jeden größeren Zwerg"; + assert_true(mk_wcswidth(str, 500) == 68); + str = L"Greek Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός Takhístè"; + assert_true(mk_wcswidth(str, 500) == 80); + str = L"Irish D’ḟuascail Íosa Úrṁac na hÓiġe Beannaiṫe pór Éaḃa agus Áḋaiṁ"; + assert_true(mk_wcswidth(str, 500) == 70); + str = L"Polish Pójdźże, kiń tę chmurność w głąb flaszy"; + assert_true(mk_wcswidth(str, 500) == 49); + str = L"Portuguese Luís argüia à Júlia que «brações, fé, chá, óxido, pôr, zângão» eram palavras do português"; + assert_true(mk_wcswidth(str, 500) == 100); + str = L"Russian Съешь же ещё этих мягких французских булок, да выпей чаю"; + assert_true(mk_wcswidth(str, 500) == 66); + str = L"Spanish Benjamín pidió una bebida de kiwi y fresa; Noé, sin vergüenza, la más exquisita champaña del menú"; + assert_true(mk_wcswidth(str, 500) == 107); + str = L"Turkish Vakfın çoğu bu huysuz genci plajda görmüştü"; + assert_true(mk_wcswidth(str, 500) == 53); +#endif +} +#endif