diff options
| author | ruki <[email protected]> | 2017-08-15 13:39:50 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-08-15 13:44:27 +0800 |
| commit | b92d83c523045d7e8b716dc0610b88b0d357575f (patch) | |
| tree | 161cebb851686c2b140ca53451089d4faca307d0 /core/src/sv | |
| parent | f7083cb5c14a5cf84c9c0ccd07891a251ec39b35 (diff) | |
remove some unused codes
Diffstat (limited to 'core/src/sv')
| -rw-r--r-- | core/src/sv/test/CMakeLists.txt | 27 | ||||
| -rw-r--r-- | core/src/sv/test/comp.c | 333 | ||||
| -rw-r--r-- | core/src/sv/test/match.c | 357 | ||||
| -rw-r--r-- | core/src/sv/test/range.c | 200 | ||||
| -rw-r--r-- | core/src/sv/test/semver.c | 106 | ||||
| -rw-r--r-- | core/src/sv/test/semvers.c | 115 | ||||
| -rw-r--r-- | core/src/sv/test/usage.c | 46 | ||||
| -rw-r--r-- | core/src/sv/test/utils.c | 102 | ||||
| -rw-r--r-- | core/src/sv/test/version.c | 236 | ||||
| -rw-r--r-- | core/src/sv/test/xmake.lua | 45 |
10 files changed, 0 insertions, 1567 deletions
diff --git a/core/src/sv/test/CMakeLists.txt b/core/src/sv/test/CMakeLists.txt deleted file mode 100644 index 89d4a0eec..000000000 --- a/core/src/sv/test/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -add_executable(version version.c) -target_link_libraries(version ${PROJECT_NAME}) -add_test(version version) - -add_executable(comp comp.c) -target_link_libraries(comp ${PROJECT_NAME}) -add_test(comp comp) - -add_executable(range range.c) -target_link_libraries(range ${PROJECT_NAME}) -add_test(range range) - -add_executable(match match.c) -target_link_libraries(match ${PROJECT_NAME}) -add_test(match match) - -add_executable(utils utils.c) -target_link_libraries(utils ${PROJECT_NAME}) -add_test(utils utils) - -add_executable(usage usage.c) -target_link_libraries(usage ${PROJECT_NAME}) -add_test(usage usage) - -add_executable(semvers semvers.c) -target_link_libraries(semvers ${PROJECT_NAME}) -add_test(semvers semvers) diff --git a/core/src/sv/test/comp.c b/core/src/sv/test/comp.c deleted file mode 100644 index faa68a500..000000000 --- a/core/src/sv/test/comp.c +++ /dev/null @@ -1,333 +0,0 @@ -/* - * This is free and unencumbered software released into the public domain. - * - * Anyone is free to copy, modify, publish, use, compile, sell, or - * distribute this software, either in source code form or as a compiled - * binary, for any purpose, commercial or non-commercial, and by any - * means. - * - * In jurisdictions that recognize copyright laws, the author or authors - * of this software dedicate any and all copyright interest in the - * software to the public domain. We make this dedication for the benefit - * of the public at large and to the detriment of our heirs and - * successors. We intend this dedication to be an overt act of - * relinquishment in perpetuity of all present and future rights to this - * software under copyright law. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to <http://unlicense.org> - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include "semver.h" - -#define STRNSIZE(s) (s), sizeof(s)-1 - -int test_read(const char *expected, const char *str, size_t len) { - unsigned slen; - char buffer[1024]; - semver_comp_t comp = {0}; - - printf("test: `%.*s`", (int) len, str); - if (semver_compn(&comp, str, len)) { - puts(" \tcouldn't parse"); - return 1; - } - slen = (unsigned) semver_comp_write(comp, buffer, 1024); - printf(" \t=> \t`%.*s`", slen, buffer); - if (memcmp(expected, buffer, (size_t) slen > len ? slen : len) != 0) { - printf(" != `%s`\n", expected); - semver_comp_dtor(&comp); - return 1; - } - printf(" == `%s`\n", expected); - semver_comp_dtor(&comp); - return 0; -} - -int test_and(const char *expected, const char *base_str, size_t base_len, const char *str, size_t len) { - unsigned slen; - char buffer[1024]; - semver_comp_t comp = {0}; - - printf("test and: `%.*s`", (int) base_len, base_str); - if (semver_compn(&comp, base_str, base_len)) { - puts(" \tcouldn't parse"); - return 1; - } - if (semver_and(&comp, str, len)) { - puts(" \tand failed"); - return 1; - } - slen = (unsigned) semver_comp_write(comp, buffer, 1024); - printf(" \t=> \t`%.*s`", slen, buffer); - if (memcmp(expected, buffer, (size_t) slen > base_len + len + 1 ? slen : base_len + len + 1) != 0) { - printf(" != `%s`\n", expected); - semver_comp_dtor(&comp); - return 1; - } - printf(" == `%s`\n", expected); - semver_comp_dtor(&comp); - return 0; -} - -int main(void) { - puts("failure:"); - if (test_read("", STRNSIZE("* ")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("* ")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("* |")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("* || *")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("abc")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE(">")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("<=")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("~")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("^")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("=")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE(">a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("<a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("~a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("^a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("=a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE(">1.a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("<1.a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("~1.a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("^1.a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("=1.a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("1.2.3 ")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("1.2.3 -")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("1.2.3 - ")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("1.2.3 -a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("1.2.3 - a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("1.2.3 - 1.2.a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("a.2.3")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("1.a.3")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("1.2.a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("1.2.3-")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("1.2.3-alpha+")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("1.2.3+")) == 0) { - return EXIT_FAILURE; - } - if (test_read("1.2.3", STRNSIZE("1.2.3"))) { - return EXIT_FAILURE; - } - - puts("\nsome prerelease and build:"); - if (test_read(">=0.0.0 1.2.3-alpha", STRNSIZE("* 1.2.3-alpha"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.0 1.2.3-alpha.2", STRNSIZE("* 1.2.3-alpha.2"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.0 1.2.3+77", STRNSIZE("* 1.2.3+77"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.0 1.2.3+77.2", STRNSIZE("* 1.2.3+77.2"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.0 1.2.3-alpha.2+77", STRNSIZE("* 1.2.3-alpha.2+77"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.0 1.2.3-alpha.2+77.2", STRNSIZE("* 1.2.3-alpha.2+77.2"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.0 1.2.3-al-pha.2+77", STRNSIZE("* 1.2.3-al-pha.2+77"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.0 1.2.3-al-pha.2+77.2", STRNSIZE("* 1.2.3-al-pha.2+77.2"))) { - return EXIT_FAILURE; - } - - puts("\nx-range:"); - if (test_read(">=0.0.0", STRNSIZE("*"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.0.0 <2.0.0", STRNSIZE("1.x"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.0 <1.3.0", STRNSIZE("1.2.x"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.0", STRNSIZE(""))) { - return EXIT_FAILURE; - } - if (test_read(">=1.0.0 <2.0.0", STRNSIZE("1"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.0 <1.3.0", STRNSIZE("1.2"))) { - return EXIT_FAILURE; - } - - puts("\nhyphen:"); - if (test_read(">=1.2.3 <=2.3.4", STRNSIZE("1.2.3 - 2.3.4"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.0 <=2.3.4", STRNSIZE("1.2 - 2.3.4"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.3 <2.4.0", STRNSIZE("1.2.3 - 2.3"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.3 <3.0.0", STRNSIZE("1.2.3 - 2"))) { - return EXIT_FAILURE; - } - - puts("\ntidle:"); - if (test_read(">=1.2.3 <1.3.0", STRNSIZE("~1.2.3"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.0 <1.3.0", STRNSIZE("~1.2"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.0.0 <2.0.0", STRNSIZE("~1"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.2.3 <0.3.0", STRNSIZE("~0.2.3"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.2.0 <0.3.0", STRNSIZE("~0.2"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.0 <1.0.0", STRNSIZE("~0"))) { - return EXIT_FAILURE; - } - - puts("\ncaret:"); - if (test_read(">=1.2.3 <2.0.0", STRNSIZE("^1.2.3"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.2.3 <0.3.0", STRNSIZE("^0.2.3"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.3 <0.0.4", STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - - puts("\nprimitive:"); - if (test_read(">=1.2.3 <2.0.0", STRNSIZE(">=1.2.3 <2.0"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.2.3 <0.3.0", STRNSIZE(">=0.2.3 <0.3"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.5.0 <0.0.4", STRNSIZE(">=0.5 <0.0.4"))) { - return EXIT_FAILURE; - } - if (test_read(">0.0.3", STRNSIZE(">0.0.3"))) { - return EXIT_FAILURE; - } - if (test_read("0.0.3", STRNSIZE("=0.0.3"))) { - return EXIT_FAILURE; - } - if (test_read("9.0.0", STRNSIZE("=9"))) { - return EXIT_FAILURE; - } - - puts("\nand:"); - if (test_and(">=0.0.0 >=0.0.3 <0.0.4", STRNSIZE("*"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_and(">=1.0.0 <2.0.0 >=0.0.3 <0.0.4", STRNSIZE("1.x"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_and(">=1.2.0 <1.3.0 >=0.0.3 <0.0.4", STRNSIZE("1.2.x"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_and(">=1.2.0 <1.3.0 >=1.2.0 <1.3.0 >=0.0.3 <0.0.4", STRNSIZE("1.2 1.2.x"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_and(">=1.0.0 <2.0.0 >=0.0.3 <0.0.4", STRNSIZE("1"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_and(">=1.2.0 <1.3.0 >=0.0.3 <0.0.4", STRNSIZE("1.2"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_and("", STRNSIZE("1.2"), STRNSIZE("")) == 0) { - return EXIT_FAILURE; - } - if (test_and("", STRNSIZE("1.2"), STRNSIZE("a")) == 0) { - return EXIT_FAILURE; - } - if (test_and("", STRNSIZE("1.2"), STRNSIZE("1.2.x abc")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget " - "dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascet" - "ur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, s")) - == 0) { - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/core/src/sv/test/match.c b/core/src/sv/test/match.c deleted file mode 100644 index d960bb7fc..000000000 --- a/core/src/sv/test/match.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * This is free and unencumbered software released into the public domain. - * - * Anyone is free to copy, modify, publish, use, compile, sell, or - * distribute this software, either in source code form or as a compiled - * binary, for any purpose, commercial or non-commercial, and by any - * means. - * - * In jurisdictions that recognize copyright laws, the author or authors - * of this software dedicate any and all copyright interest in the - * software to the public domain. We make this dedication for the benefit - * of the public at large and to the detriment of our heirs and - * successors. We intend this dedication to be an overt act of - * relinquishment in perpetuity of all present and future rights to this - * software under copyright law. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to <http://unlicense.org> - */ - -#include <stdlib.h> -#include <stdio.h> - -#include "semver.h" - -#define STRNSIZE(s) (s), sizeof(s)-1 - -int test_matchn(bool expected, const char *semver_str, size_t semver_len, const char *comp_str, size_t comp_len) { - bool result; - semver_t semver = {0}; - - printf("test: `%.*s` ^ `%.*s`", (int) semver_len, semver_str, (int) comp_len, comp_str); - if (semvern(&semver, semver_str, semver_len)) { - puts(" \tcouldn't parse semver"); - return 1; - } - result = semver_comp_matchn(&semver, comp_str, comp_len); - printf(" \t=> %d\t", result); - if (result != expected) { - printf(" != `%d`\n", expected); - semver_dtor(&semver); - return 1; - } - printf(" == `%d`\n", expected); - semver_dtor(&semver); - return 0; -} - -int test_rmatchn(bool expected, const char *semver_str, size_t semver_len, const char *range_str, size_t range_len) { - bool result; - semver_t semver = {0}; - - printf("test: `%.*s` ^ `%.*s`", (int) semver_len, semver_str, (int) range_len, range_str); - if (semvern(&semver, semver_str, semver_len)) { - puts(" \tcouldn't parse semver"); - return 1; - } - result = semver_range_matchn(&semver, range_str, range_len); - printf(" \t=> %d\t", result); - if (result != expected) { - printf(" != `%d`\n", expected); - semver_dtor(&semver); - return 1; - } - printf(" == `%d`\n", expected); - semver_dtor(&semver); - return 0; -} - -int main(void) { - if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("1.2.3"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("1.2.x"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("1.x.x"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("1.x"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("1"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("*"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE(">1"))) { - return EXIT_FAILURE; - } - if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE(">2"))) { - return EXIT_FAILURE; - } - if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE(">=2"))) { - return EXIT_FAILURE; - } - if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE("<1"))) { - return EXIT_FAILURE; - } - if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE("<=1"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE(">=1.2.3"))) { - return EXIT_FAILURE; - } - if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE(">1.2.3"))) { - return EXIT_FAILURE; - } - if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE("<1.2.3"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("<=1.2.3"))) { - return EXIT_FAILURE; - } - if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE("2.x"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("<0.0.1-99"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("<=0.0.1-99"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("<=0.0.1-98"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("=0.0.1-98"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE(">=0.0.1-98"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE(">=0.0.1-97"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE(">0.0.1-97"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha"), STRNSIZE("0.0.1-alpha"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("<0.0.1-99"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<0.0.1-alpha.99"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<=0.0.1-alpha.99"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<=0.0.1-alpha.98"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("=0.0.1-alpha.98"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">=0.0.1-alpha.98"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">=0.0.1-alpha.97"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">0.0.1-alpha.97"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<0.0.1-alpha.99.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<=0.0.1-alpha.99.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<=0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(false, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("=0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(false, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">=0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">=0.0.1-alpha.97.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">0.0.1-alpha.97.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("<0.0.1-alpha.99.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("<=0.0.1-alpha.99.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(false, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("<=0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(false, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("=0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE(">=0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE(">=0.0.1-alpha.97.1"))) { - return EXIT_FAILURE; - } - if (test_matchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE(">0.0.1-alpha.97.1"))) { - return EXIT_FAILURE; - } - - if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 1.2.3"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 1.2.x"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 1.x.x"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 1.x"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || *"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || >1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || >2"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || >=2"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || <1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || <=1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || >=1.2.3"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || >1.2.3"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || <1.2.3"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || <=1.2.3"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 2.x"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || <0.0.1-99"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || <=0.0.1-99"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || <=0.0.1-98"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || =0.0.1-98"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || >=0.0.1-98"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || >=0.0.1-97"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || >0.0.1-97"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha"), STRNSIZE("9.x || 0.0.1-alpha"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || <0.0.1-99"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <0.0.1-alpha.99"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <=0.0.1-alpha.99"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <=0.0.1-alpha.98"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || =0.0.1-alpha.98"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >=0.0.1-alpha.98"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >=0.0.1-alpha.97"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >0.0.1-alpha.97"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <0.0.1-alpha.99.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <=0.0.1-alpha.99.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <=0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(false, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || =0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(false, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >=0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >=0.0.1-alpha.97.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >0.0.1-alpha.97.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || <0.0.1-alpha.99.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || <=0.0.1-alpha.99.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(false, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || <=0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(false, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || =0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || >=0.0.1-alpha.98.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || >=0.0.1-alpha.97.1"))) { - return EXIT_FAILURE; - } - if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || >0.0.1-alpha.97.1"))) { - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/core/src/sv/test/range.c b/core/src/sv/test/range.c deleted file mode 100644 index 17611ab25..000000000 --- a/core/src/sv/test/range.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * This is free and unencumbered software released into the public domain. - * - * Anyone is free to copy, modify, publish, use, compile, sell, or - * distribute this software, either in source code form or as a compiled - * binary, for any purpose, commercial or non-commercial, and by any - * means. - * - * In jurisdictions that recognize copyright laws, the author or authors - * of this software dedicate any and all copyright interest in the - * software to the public domain. We make this dedication for the benefit - * of the public at large and to the detriment of our heirs and - * successors. We intend this dedication to be an overt act of - * relinquishment in perpetuity of all present and future rights to this - * software under copyright law. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to <http://unlicense.org> - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include "semver.h" - -#define STRNSIZE(s) (s), sizeof(s)-1 - -int test_read(const char *expected, const char *str, size_t len) { - unsigned slen; - char buffer[1024]; - semver_range_t range = {0}; - - printf("test: `%.*s`", (int) len, str); - if (semver_rangen(&range, str, len)) { - puts(" \tcouldn't parse"); - return 1; - } - slen = (unsigned) semver_range_write(range, buffer, 1024); - printf(" \t=> \t`%.*s`", slen, buffer); - if (memcmp(expected, buffer, (size_t) slen > len ? slen : len) != 0) { - printf(" != `%s`\n", expected); - semver_range_dtor(&range); - return 1; - } - printf(" == `%s`\n", expected); - semver_range_dtor(&range); - return 0; -} - -int test_or(const char *expected, const char *base_str, size_t base_len, const char *str, size_t len) { - unsigned slen; - char buffer[1024]; - semver_range_t range = {0}; - - printf("test and: `%.*s`", (int) base_len, base_str); - if (semver_rangen(&range, base_str, base_len)) { - puts(" \tcouldn't parse base"); - return 1; - } - if (semver_or(&range, str, len)) { - puts(" \tand failed"); - return 1; - } - slen = (unsigned) semver_range_write(range, buffer, 1024); - printf(" \t=> \t`%.*s`", slen, buffer); - if (memcmp(expected, buffer, (size_t) slen > base_len + len + 1 ? slen : base_len + len + 1) != 0) { - printf(" != `%s`\n", expected); - semver_range_dtor(&range); - return 1; - } - printf(" == `%s`\n", expected); - semver_range_dtor(&range); - return 0; -} - -int main(void) { - puts("failure:"); - if (test_read("", STRNSIZE("* |")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("* ||a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("* || a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("* || 1.a")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget " - "dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascet" - "ur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, s")) - == 0) { - return EXIT_FAILURE; - } - - puts("\nx-range:"); - if (test_read(">=0.0.0 || 1.2.3", STRNSIZE("* || 1.2.3"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.0.0 <2.0.0 || >=2.0.0 <3.0.0", STRNSIZE("1.x || 2.x"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.0 <1.3.0 || 3.0.0", STRNSIZE("1.2.x || 3.0.0"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.0", STRNSIZE(""))) { - return EXIT_FAILURE; - } - if (test_read(">=1.0.0 <2.0.0 || >=2.0.0 <3.0.0 || >=3.0.0 <4.0.0", STRNSIZE("1 || 2 || 3"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.0 <1.3.0 || >=5.0.0", STRNSIZE("1.2 || >=5"))) { - return EXIT_FAILURE; - } - - puts("\nhyphen:"); - if (test_read(">=1.2.3 <=2.3.4 || >=5.0.0", STRNSIZE("1.2.3 - 2.3.4 || >=5"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.0 <=2.3.4 || >=5.0.0", STRNSIZE("1.2 - 2.3.4 || >=5"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.3 <2.4.0 || >=5.0.0", STRNSIZE("1.2.3 - 2.3 || >=5"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.3 <3.0.0 || >=5.0.0", STRNSIZE("1.2.3 - 2 || >=5"))) { - return EXIT_FAILURE; - } - - puts("\ntidle:"); - if (test_read(">=1.2.3 <1.3.0 || >=5.0.0", STRNSIZE("~1.2.3 || >=5"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.2.0 <1.3.0 || >=5.0.0", STRNSIZE("~1.2 || >=5"))) { - return EXIT_FAILURE; - } - if (test_read(">=1.0.0 <2.0.0 || >=5.0.0", STRNSIZE("~1 || >=5"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.2.3 <0.3.0 || >=5.0.0", STRNSIZE("~0.2.3 || >=5"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.2.0 <0.3.0 || >=5.0.0", STRNSIZE("~0.2 || >=5"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.0 <1.0.0 || >=5.0.0", STRNSIZE("~0 || >=5"))) { - return EXIT_FAILURE; - } - - puts("\ncaret:"); - if (test_read(">=1.2.3 <2.0.0 || >=5.0.0", STRNSIZE("^1.2.3 || >=5"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.2.3 <0.3.0 || >=5.0.0", STRNSIZE("^0.2.3 || >=5"))) { - return EXIT_FAILURE; - } - if (test_read(">=0.0.3 <0.0.4 || >=5.0.0", STRNSIZE("^0.0.3 || >=5"))) { - return EXIT_FAILURE; - } - - puts("\nand:"); - if (test_or(">=0.0.0 || >=0.0.3 <0.0.4", STRNSIZE("*"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_or(">=1.0.0 <2.0.0 || >=0.0.3 <0.0.4", STRNSIZE("1.x"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_or(">=1.2.0 <1.3.0 || >=0.0.3 <0.0.4", STRNSIZE("1.2.x"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_or(">=1.2.0 <1.3.0 || >=1.2.0 <1.3.0 || >=0.0.3 <0.0.4", STRNSIZE("1.2 || 1.2.x"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_or(">=1.0.0 <2.0.0 || >=0.0.3 <0.0.4", STRNSIZE("1"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_or(">=1.2.0 <1.3.0 || >=0.0.3 <0.0.4", STRNSIZE("1.2"), STRNSIZE("^0.0.3"))) { - return EXIT_FAILURE; - } - if (test_or("", STRNSIZE("1.2"), STRNSIZE("")) == 0) { - return EXIT_FAILURE; - } - if (test_or("", STRNSIZE("1.2"), STRNSIZE("a")) == 0) { - return EXIT_FAILURE; - } - if (test_or("", STRNSIZE("1.2"), STRNSIZE("1.2.x || abc")) == 0) { - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/core/src/sv/test/semver.c b/core/src/sv/test/semver.c deleted file mode 100644 index 762f4ce40..000000000 --- a/core/src/sv/test/semver.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * This is free and unencumbered software released into the public domain. - * - * Anyone is free to copy, modify, publish, use, compile, sell, or - * distribute this software, either in source code form or as a compiled - * binary, for any purpose, commercial or non-commercial, and by any - * means. - * - * In jurisdictions that recognize copyright laws, the author or authors - * of this software dedicate any and all copyright interest in the - * software to the public domain. We make this dedication for the benefit - * of the public at large and to the detriment of our heirs and - * successors. We intend this dedication to be an overt act of - * relinquishment in perpetuity of all present and future rights to this - * software under copyright law. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to <http://unlicense.org> - */ - -#include <semver.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#define STRNSIZE(s) (s), sizeof(s)-1 - -int test_semver(const char *expected, const char *str, size_t len) { - size_t offset = 0; - unsigned slen; - char buffer[1024]; - semver_t semver = {0}; - - printf("test: `%.*s`", (int) len, str); - if (semver_read(&semver, str, len, &offset)) { - puts(" \tcouldn't parse"); - return 1; - } - slen = (unsigned) semver_write(semver, buffer, 1024); - printf(" \t=> \t`%.*s`", slen, buffer); - if (memcmp(expected, buffer, (size_t) slen > len ? slen : len) != 0) { - printf(" != `%s`\n", expected); - semver_dtor(&semver); - return 1; - } - printf(" == `%s`\n", expected); - semver_dtor(&semver); - return 0; -} - -int main(void) { - if (test_semver("1.2.3", STRNSIZE("1.2.3"))) { - return EXIT_FAILURE; - } - if (test_semver("1.2.3-alpha", STRNSIZE("v1.2.3-alpha"))) { - return EXIT_FAILURE; - } - if (test_semver("1.2.3-alpha.2", STRNSIZE("1.2.3-alpha.2"))) { - return EXIT_FAILURE; - } - if (test_semver("1.2.3+77", STRNSIZE("v1.2.3+77"))) { - return EXIT_FAILURE; - } - if (test_semver("1.2.3+77.2", STRNSIZE("1.2.3+77.2"))) { - return EXIT_FAILURE; - } - if (test_semver("1.2.3-alpha.2+77", STRNSIZE("v1.2.3-alpha.2+77"))) { - return EXIT_FAILURE; - } - if (test_semver("1.2.3-alpha.2+77.2", STRNSIZE("1.2.3-alpha.2+77.2"))) { - return EXIT_FAILURE; - } - if (test_semver("1.2.3-al-pha.2+77", STRNSIZE("v1.2.3-al-pha.2+77"))) { - return EXIT_FAILURE; - } - if (test_semver("1.2.3-al-pha.2+77.2", STRNSIZE("1.2.3-al-pha.2+77.2"))) { - return EXIT_FAILURE; - } - if (test_semver("", STRNSIZE("")) == 0) { - return EXIT_FAILURE; - } - if (test_semver("", STRNSIZE("vv1.2.3")) == 0) { - return EXIT_FAILURE; - } - if (test_semver("", STRNSIZE("v1.2")) == 0) { - return EXIT_FAILURE; - } - if (test_semver("", STRNSIZE("v1.2.x")) == 0) { - return EXIT_FAILURE; - } - if (test_semver("", STRNSIZE("v1.2.3-")) == 0) { - return EXIT_FAILURE; - } - if (test_semver("", STRNSIZE("v1.2.3+")) == 0) { - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/core/src/sv/test/semvers.c b/core/src/sv/test/semvers.c deleted file mode 100644 index fec6072bd..000000000 --- a/core/src/sv/test/semvers.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * This is free and unencumbered software released into the public domain. - * - * Anyone is free to copy, modify, publish, use, compile, sell, or - * distribute this software, either in source code form or as a compiled - * binary, for any purpose, commercial or non-commercial, and by any - * means. - * - * In jurisdictions that recognize copyright laws, the author or authors - * of this software dedicate any and all copyright interest in the - * software to the public domain. We make this dedication for the benefit - * of the public at large and to the detriment of our heirs and - * successors. We intend this dedication to be an overt act of - * relinquishment in perpetuity of all present and future rights to this - * software under copyright law. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to <http://unlicense.org> - */ - -#include <stdlib.h> -#include <assert.h> - -#include "semver.h" - -#define STRNSIZE(s) (s), sizeof(s)-1 - -int main(void) { - semver_t v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10; - semvers_t semvers = {0}; - - semver_tryn(&v0, STRNSIZE("2.0.0")); - semver_tryn(&v1, STRNSIZE("2.0.1")); - semver_tryn(&v2, STRNSIZE("2.0.2")); - semver_tryn(&v3, STRNSIZE("v2.0.0")); - semver_tryn(&v4, STRNSIZE("v2.0.1")); - semver_tryn(&v5, STRNSIZE("v2.0.2")); - semver_tryn(&v6, STRNSIZE("v2.0.3")); - semver_tryn(&v7, STRNSIZE("v2.1.0-beta1")); - semver_tryn(&v8, STRNSIZE("v2.1.0-beta2")); - semver_tryn(&v9, STRNSIZE("v2.0")); - semver_tryn(&v10, STRNSIZE("v2.1")); - - if (semver_rmatch(v0, ">2.0.1")) semvers_push(semvers, v0); - if (semver_rmatch(v1, ">2.0.1")) semvers_unshift(semvers, v1); - if (semver_rmatch(v2, ">2.0.1")) semvers_push(semvers, v2); - if (semver_rmatch(v3, ">2.0.1")) semvers_unshift(semvers, v3); - if (semver_rmatch(v4, ">2.0.1")) semvers_push(semvers, v4); - if (semver_rmatch(v5, ">2.0.1")) semvers_unshift(semvers, v5); - if (semver_rmatch(v6, ">2.0.1")) semvers_push(semvers, v6); - if (semver_rmatch(v7, ">2.0.1")) semvers_unshift(semvers, v7); - if (semver_rmatch(v8, ">2.0.1")) semvers_push(semvers, v8); - if (semver_rmatch(v9, ">2.0.1")) semvers_unshift(semvers, v9); - if (semver_rmatch(v10, ">2.0.1")) semvers_push(semvers, v10); - if (semver_rmatch(v0, ">2.0.1")) semvers_push(semvers, v0); - if (semver_rmatch(v1, ">2.0.1")) semvers_unshift(semvers, v1); - if (semver_rmatch(v2, ">2.0.1")) semvers_push(semvers, v2); - if (semver_rmatch(v3, ">2.0.1")) semvers_unshift(semvers, v3); - if (semver_rmatch(v4, ">2.0.1")) semvers_push(semvers, v4); - if (semver_rmatch(v5, ">2.0.1")) semvers_unshift(semvers, v5); - if (semver_rmatch(v6, ">2.0.1")) semvers_push(semvers, v6); - if (semver_rmatch(v7, ">2.0.1")) semvers_unshift(semvers, v7); - if (semver_rmatch(v8, ">2.0.1")) semvers_push(semvers, v8); - if (semver_rmatch(v9, ">2.0.1")) semvers_unshift(semvers, v9); - if (semver_rmatch(v10, ">2.0.1")) semvers_push(semvers, v10); - if (semver_rmatch(v0, ">2.0.1")) semvers_push(semvers, v0); - if (semver_rmatch(v1, ">2.0.1")) semvers_unshift(semvers, v1); - if (semver_rmatch(v2, ">2.0.1")) semvers_push(semvers, v2); - if (semver_rmatch(v3, ">2.0.1")) semvers_unshift(semvers, v3); - if (semver_rmatch(v4, ">2.0.1")) semvers_push(semvers, v4); - if (semver_rmatch(v5, ">2.0.1")) semvers_unshift(semvers, v5); - if (semver_rmatch(v6, ">2.0.1")) semvers_push(semvers, v6); - if (semver_rmatch(v7, ">2.0.1")) semvers_unshift(semvers, v7); - if (semver_rmatch(v8, ">2.0.1")) semvers_push(semvers, v8); - if (semver_rmatch(v9, ">2.0.1")) semvers_unshift(semvers, v9); - if (semver_rmatch(v10, ">2.0.1")) semvers_push(semvers, v10); - - if (semvers.length != 18) { - return EXIT_FAILURE; - } - if (semvers.capacity != 32) { - return EXIT_FAILURE; - } - - semvers_sort(semvers); - - for (unsigned i = 0; i < semvers.length; ++i) { - semver_fwrite(semvers.data + i, stdout); - putc('\n', stdout); - } - - v0 = semvers_pop(semvers); - v1 = semvers_shift(semvers); - - assert(memcmp("v2.1", v0.raw, v0.len) == 0); - assert(memcmp("v2.0.2", v1.raw, v1.len) == 0 || memcmp("2.0.2", v1.raw, v1.len) == 0); - - semvers_rsort(semvers); - putc('\n', stdout); - for (unsigned i = 0; i < semvers.length; ++i) { - semver_fwrite(semvers.data + i, stdout); - putc('\n', stdout); - } - - semvers_dtor(semvers); - - return EXIT_SUCCESS; -} diff --git a/core/src/sv/test/usage.c b/core/src/sv/test/usage.c deleted file mode 100644 index 818608137..000000000 --- a/core/src/sv/test/usage.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This is free and unencumbered software released into the public domain. - * - * Anyone is free to copy, modify, publish, use, compile, sell, or - * distribute this software, either in source code form or as a compiled - * binary, for any purpose, commercial or non-commercial, and by any - * means. - * - * In jurisdictions that recognize copyright laws, the author or authors - * of this software dedicate any and all copyright interest in the - * software to the public domain. We make this dedication for the benefit - * of the public at large and to the detriment of our heirs and - * successors. We intend this dedication to be an overt act of - * relinquishment in perpetuity of all present and future rights to this - * software under copyright law. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to <http://unlicense.org> - */ - -#include <stdlib.h> -#include <assert.h> - -#include "semver.h" - -int main(void) { - semver_t semver = {0}; - - semver(&semver, "v1.2.3-alpha.1"); - - assert(1 == semver.major); - assert(2 == semver.minor); - assert(3 == semver.patch); - assert(0 == memcmp("alpha", semver.prerelease.raw, sizeof("alpha")-1)); - assert(0 == memcmp("1", semver.prerelease.next->raw, sizeof("1")-1)); - assert(true == semver_rmatch(semver, "1.2.1 || >=1.2.3-alpha <1.2.5")); - - semver_dtor(&semver); -} diff --git a/core/src/sv/test/utils.c b/core/src/sv/test/utils.c deleted file mode 100644 index 89ae4cd1b..000000000 --- a/core/src/sv/test/utils.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This is free and unencumbered software released into the public domain. - * - * Anyone is free to copy, modify, publish, use, compile, sell, or - * distribute this software, either in source code form or as a compiled - * binary, for any purpose, commercial or non-commercial, and by any - * means. - * - * In jurisdictions that recognize copyright laws, the author or authors - * of this software dedicate any and all copyright interest in the - * software to the public domain. We make this dedication for the benefit - * of the public at large and to the detriment of our heirs and - * successors. We intend this dedication to be an overt act of - * relinquishment in perpetuity of all present and future rights to this - * software under copyright law. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to <http://unlicense.org> - */ - -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -#include "semver.h" - -int test_version_fwrite(void) { - static const char input_str[] = "1.2.3-alpha.1+x86-64"; - semver_t version; - int rv; - - rv = semver(&version, input_str); - if (0 == rv) { - printf("test_version_fwrite: "); - semver_fwrite(&version, stdout); - if (0 == errno) { - printf("\n"); - rv = 0; - } - } - semver_dtor(&version); - return rv; -} - -int test_comparator_fwrite(void) { - static const char input_str[] = "<=1.2.3"; - semver_comp_t comp; - int rv; - - rv = semver_comp(&comp, input_str); - if (0 == rv) { - printf("test_comparator_fwrite: "); - semver_comp_fwrite(&comp, stdout); - if (0 == errno) { - printf("\n"); - rv = 0; - } - } - semver_comp_dtor(&comp); - return rv; -} - -int test_range_fwrite(void) { - static const char input_str[] = ">=1.2.3 <4.0.0"; - semver_range_t range; - int rv; - - rv = semver_range(&range, input_str); - if (0 == rv) { - printf("test_range_fwrite: "); - semver_range_fwrite(&range, stdout); - if (0 == errno) { - printf("\n"); - rv = 0; - } - } - semver_range_dtor(&range); - return rv; -} - -int main(void) { - if (test_version_fwrite()) { - return EXIT_FAILURE; - } - - if (test_comparator_fwrite()) { - return EXIT_FAILURE; - } - - if (test_range_fwrite()) { - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/core/src/sv/test/version.c b/core/src/sv/test/version.c deleted file mode 100644 index a10b6e645..000000000 --- a/core/src/sv/test/version.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * This is free and unencumbered software released into the public domain. - * - * Anyone is free to copy, modify, publish, use, compile, sell, or - * distribute this software, either in source code form or as a compiled - * binary, for any purpose, commercial or non-commercial, and by any - * means. - * - * In jurisdictions that recognize copyright laws, the author or authors - * of this software dedicate any and all copyright interest in the - * software to the public domain. We make this dedication for the benefit - * of the public at large and to the detriment of our heirs and - * successors. We intend this dedication to be an overt act of - * relinquishment in perpetuity of all present and future rights to this - * software under copyright law. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * For more information, please refer to <http://unlicense.org> - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include "semver.h" - -#define STRNSIZE(s) (s), sizeof(s)-1 - -int test_read(const char *expected, const char *str, size_t len) { - unsigned slen; - char buffer[1024]; - semver_t semver = {0}; - - printf("test: `%.*s`", (int) len, str); - if (semvern(&semver, str, len)) { - puts(" \tcouldn't parse"); - return 1; - } - slen = (unsigned) semver_write(semver, buffer, 1024); - printf(" \t=> \t`%.*s`", slen, buffer); - if (memcmp(expected, buffer, (size_t) slen > len ? slen : len) != 0) { - printf(" != `%s`\n", expected); - semver_dtor(&semver); - return 1; - } - printf(" == `%s`\n", expected); - semver_dtor(&semver); - return 0; -} - -int test_try_read(const char *expected, const char *str, size_t len) { - unsigned slen; - char buffer[1024]; - semver_t semver = {0}; - - printf("test: `%.*s`", (int) len, str); - if (semver_tryn(&semver, str, len)) { - puts(" \tcouldn't parse"); - return 1; - } - slen = (unsigned) semver_write(semver, buffer, 1024); - printf(" \t=> \t`%.*s`", slen, buffer); - if (memcmp(expected, buffer, (size_t) slen > len ? slen : len) != 0) { - printf(" != `%s`\n", expected); - semver_dtor(&semver); - return 1; - } - printf(" == `%s`\n", expected); - semver_dtor(&semver); - return 0; -} - -int main(void) { - puts("normal:"); - if (test_read("0.2.3", STRNSIZE("0.2.3"))) { - return EXIT_FAILURE; - } - if (test_read("1.2.3", STRNSIZE("1.2.3"))) { - return EXIT_FAILURE; - } - if (test_read("1.2.3-alpha", STRNSIZE("v1.2.3-alpha"))) { - return EXIT_FAILURE; - } - if (test_read("1.2.3-alpha.2", STRNSIZE("1.2.3-alpha.2"))) { - return EXIT_FAILURE; - } - if (test_read("1.2.3+77", STRNSIZE("v1.2.3+77"))) { - return EXIT_FAILURE; - } - if (test_read("1.2.3+0", STRNSIZE("v1.2.3+0"))) { - return EXIT_FAILURE; - } - if (test_read("1.2.3+77.2", STRNSIZE("1.2.3+77.2"))) { - return EXIT_FAILURE; - } - if (test_read("1.2.3-alpha.2+77", STRNSIZE("v1.2.3-alpha.2+77"))) { - return EXIT_FAILURE; - } - if (test_read("1.2.3-alpha.2+77.2", STRNSIZE("1.2.3-alpha.2+77.2"))) { - return EXIT_FAILURE; - } - if (test_read("1.2.3-al-pha.2+77", STRNSIZE("v1.2.3-al-pha.2+77"))) { - return EXIT_FAILURE; - } - if (test_read("1.2.3-al-pha.2+77.2", STRNSIZE("1.2.3-al-pha.2+77.2"))) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("vv1.2.3")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("v1.2")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("v1.2.x")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("v1.2.3-")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("v1.2.3+")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("v1.2.3+01")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("v0.01.3")) == 0) { - return EXIT_FAILURE; - } - if (test_read("", STRNSIZE("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget " - "dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascet" - "ur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, s")) - == 0) { - return EXIT_FAILURE; - } - - puts("try:"); - if (test_try_read("0.2.3", STRNSIZE("0.2.3"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3", STRNSIZE("1.2.3"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3-alpha", STRNSIZE("v1.2.3-alpha"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3-alpha.2", STRNSIZE("1.2.3-alpha.2"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3+77", STRNSIZE("v1.2.3+77"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3+0", STRNSIZE("v1.2.3+0"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3+77.2", STRNSIZE("1.2.3+77.2"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3-alpha.2+77", STRNSIZE("v1.2.3-alpha.2+77"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3-alpha.2+77.2", STRNSIZE("1.2.3-alpha.2+77.2"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3-al-pha.2+77", STRNSIZE("v1.2.3-al-pha.2+77"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3-al-pha.2+77.2", STRNSIZE("1.2.3-al-pha.2+77.2"))) { - return EXIT_FAILURE; - } - if (test_try_read("", STRNSIZE("")) == 0) { - return EXIT_FAILURE; - } - if (test_try_read("", STRNSIZE("vv1.2.3")) == 0) { - return EXIT_FAILURE; - } - if (test_try_read("", STRNSIZE("v1.2")) == 0) { - return EXIT_FAILURE; - } - if (test_try_read("", STRNSIZE("v1.2.x")) == 0) { - return EXIT_FAILURE; - } - if (test_try_read("", STRNSIZE("v1.2.3-")) == 0) { - return EXIT_FAILURE; - } - if (test_try_read("", STRNSIZE("v1.2.3+")) == 0) { - return EXIT_FAILURE; - } - if (test_try_read("", STRNSIZE("v1.2.3+01")) == 0) { - return EXIT_FAILURE; - } - if (test_try_read("", STRNSIZE("v0.01.3")) == 0) { - return EXIT_FAILURE; - } - if (test_try_read("", STRNSIZE("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget " - "dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascet" - "ur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, s")) - == 0) { - return EXIT_FAILURE; - } - if (test_try_read("0.2.0", STRNSIZE("0.2"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.0.0", STRNSIZE("v1"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.0-alpha", STRNSIZE("v1.2alpha"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3-alpha.2", STRNSIZE("1.2.3alpha.2"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.0.0+77", STRNSIZE("v1+77"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.0+0", STRNSIZE("v1.2+0"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.0.0+77.2", STRNSIZE("v1+77.2"))) { - return EXIT_FAILURE; - } - if (test_try_read("1.2.3-alpha.2+77", STRNSIZE("v1.2.3alpha.2+77"))) { - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/core/src/sv/test/xmake.lua b/core/src/sv/test/xmake.lua deleted file mode 100644 index 4169560e8..000000000 --- a/core/src/sv/test/xmake.lua +++ /dev/null @@ -1,45 +0,0 @@ -set_default(false) -set_languages("c99") -set_kind("binary") -add_deps("sv") -add_links("sv") -add_includedirs("../include") -add_linkdirs("$(buildir)") - -target("version_test") - add_files("version.c") - -target("comp_test") - add_files("comp.c") - -target("range_test") - add_files("range.c") - -target("match_test") - add_files("match.c") - -target("semvers_test") - add_files("semvers.c") - -target("utils_test") - add_files("utils.c") - -target("usage_test") - add_files("usage.c") - -task("check") - on_run(function () - import("core.project.task") - task.run("run", {target = "version_test"}) - task.run("run", {target = "comp_test"}) - task.run("run", {target = "range_test"}) - task.run("run", {target = "match_test"}) - task.run("run", {target = "semvers_test"}) - task.run("run", {target = "utils_test"}) - task.run("run", {target = "usage_test"}) - end) - set_menu { - usage = "xmake check" - , description = "Run tests !" - , options = {} - } |
