add strverscmp tests from the manual, bug found by jianzhong.huang
authorSzabolcs Nagy <nsz@port70.net>
Mon, 13 Oct 2014 08:41:14 +0000 (10:41 +0200)
committerSzabolcs Nagy <nsz@port70.net>
Mon, 13 Oct 2014 08:41:14 +0000 (10:41 +0200)
src/regression/strverscmp.c [new file with mode: 0644]

diff --git a/src/regression/strverscmp.c b/src/regression/strverscmp.c
new file mode 100644 (file)
index 0000000..a4daa26
--- /dev/null
@@ -0,0 +1,26 @@
+// leading zero handling according to the manual
+#define _GNU_SOURCE
+#include <string.h>
+#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;
+}