From 3d6482b0949159c33d6ac2972a69868bdda766f2 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 12 Jun 2022 20:13:23 +0200 Subject: Move some test code to newline created .c files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- strrneqlen.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'strrneqlen.c') diff --git a/strrneqlen.c b/strrneqlen.c index b5f56b4..f76cac8 100644 --- a/strrneqlen.c +++ b/strrneqlen.c @@ -12,6 +12,30 @@ extern inline size_t libsimple_strrneqlen(const char *, const char *, size_t); int main(void) { + size_t i, j, n; + + for (n = 0; n < 10; n++) { + char a[] = "abcdefgh", b[] = "abcdefgh"; + size_t I, J; + assert(libsimple_strrneqlen("", "", n) == 0); + assert(libsimple_strrneqlen("x", "", n) == 0); + assert(libsimple_strrneqlen("x", "y", n) == 0); + assert(libsimple_strrneqlen("", "y", n) == 0); + for (i = 0; i <= 8; i++) { + for (j = 0; j <= 8; j++) { + I = 8 - i; + J = 8 - j; + assert(libsimple_strrneqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); + a[i] = b[j] = '\0'; + assert(libsimple_strrneqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); + a[i] = "abcdefgh"[i]; + b[j] = "abcdefgh"[j]; + } + } + assert(libsimple_strrneqlen("abc", "ABC", n) == 0); + assert(libsimple_strrneqlen("123", "123", n) == MIN(3, n)); + } + return 0; } -- cgit v1.2.3-70-g09d2