From da2b7d64ac5693bc2a3dbfd1138972afae1466bc Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Mon, 13 Oct 2014 10:41:14 +0200 Subject: [PATCH] add strverscmp tests from the manual, bug found by jianzhong.huang --- src/regression/strverscmp.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/regression/strverscmp.c diff --git a/src/regression/strverscmp.c b/src/regression/strverscmp.c new file mode 100644 index 0000000..a4daa26 --- /dev/null +++ b/src/regression/strverscmp.c @@ -0,0 +1,26 @@ +// leading zero handling according to the manual +#define _GNU_SOURCE +#include +#include "test.h" + +#define ASSERT(x) ((x) || (t_error(#x " failed\n"),0)) + +int main() +{ + ASSERT(strverscmp("", "") == 0); + ASSERT(strverscmp("a", "a") == 0); + ASSERT(strverscmp("a", "b") < 0); + ASSERT(strverscmp("b", "a") > 0); + ASSERT(strverscmp("000", "00") < 0); + ASSERT(strverscmp("00", "000") > 0); + ASSERT(strverscmp("a0", "a") > 0); + ASSERT(strverscmp("00", "01") < 0); + ASSERT(strverscmp("01", "010") < 0); + ASSERT(strverscmp("010", "09") < 0); + ASSERT(strverscmp("09", "0") < 0); + ASSERT(strverscmp("9", "10") < 0); + ASSERT(strverscmp("0a", "0") > 0); + ASSERT(strverscmp("foobar-1.1.2", "foobar-1.1.3") < 0); + ASSERT(strverscmp("foobar-1.1.2", "foobar-1.01.3") > 0); + return t_status; +} -- 2.20.1