From c2a217f9121dd865122bc6150c53e77bd662050d Mon Sep 17 00:00:00 2001 From: fab Date: Sat, 3 Nov 2018 20:09:20 +0000 Subject: utf-8 aware functions for basis. unit-testing. --- tests/utf8.py | 449 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 449 insertions(+) create mode 100644 tests/utf8.py (limited to 'tests/utf8.py') diff --git a/tests/utf8.py b/tests/utf8.py new file mode 100644 index 00000000..ff9b737a --- /dev/null +++ b/tests/utf8.py @@ -0,0 +1,449 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case: substring (1)""" + self.start('Utf8/substrings') + + pre = self.xpath('pre[1]') + self.assertEqual('abc', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('bc', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('c', pre.text) + + pre = self.xpath('pre[4]') + self.assertEqual('ábó', pre.text) + + pre = self.xpath('pre[5]') + self.assertEqual('bó', pre.text) + + pre = self.xpath('pre[6]') + self.assertEqual('ó', pre.text) + + pre = self.xpath('pre[7]') + self.assertEqual('çãó', pre.text) + + pre = self.xpath('pre[8]') + self.assertEqual('ãó', pre.text) + + pre = self.xpath('pre[9]') + self.assertEqual('ó', pre.text) + + pre = self.xpath('pre[10]') + self.assertEqual('', pre.text) + + pre = self.xpath('pre[11]') + self.assertEqual('', pre.text) + + + def test_2(self): + """Test case: strlen (2)""" + self.start('Utf8/strlens') + + pre = self.xpath('pre[1]') + self.assertEqual('3', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('3', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('3', pre.text) + + pre = self.xpath('pre[4]') + self.assertEqual('3', pre.text) + + pre = self.xpath('pre[5]') + self.assertEqual('1', pre.text) + + pre = self.xpath('pre[6]') + self.assertEqual('1', pre.text) + + pre = self.xpath('pre[7]') + self.assertEqual('0', pre.text) + + pre = self.xpath('pre[8]') + self.assertEqual('1', pre.text) + + pre = self.xpath('pre[9]') + self.assertEqual('1', pre.text) + + pre = self.xpath('pre[10]') + self.assertEqual('1', pre.text) + + pre = self.xpath('pre[11]') + self.assertEqual('6', pre.text) + + pre = self.xpath('pre[12]') + self.assertEqual('2', pre.text) + + pre = self.xpath('pre[13]') + self.assertEqual('14', pre.text) + + + def test_3(self): + """Test case: strlenGe (3)""" + self.start('Utf8/strlenGens') + + pre = self.xpath('pre[1]') + self.assertEqual('False', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('True', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('False', pre.text) + + pre = self.xpath('pre[4]') + self.assertEqual('True', pre.text) + + pre = self.xpath('pre[5]') + self.assertEqual('True', pre.text) + + pre = self.xpath('pre[6]') + self.assertEqual('False', pre.text) + + pre = self.xpath('pre[7]') + self.assertEqual('True', pre.text) + + pre = self.xpath('pre[8]') + self.assertEqual('True', pre.text) + + def test_4(self): + """Test case: strcat (4)""" + self.start('Utf8/strcats') + + pre = self.xpath('pre[1]') + self.assertEqual('', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('0', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('aabb', pre.text) + + pre = self.xpath('pre[4]') + self.assertEqual('4', pre.text) + + pre = self.xpath('pre[5]') + self.assertEqual('bb', pre.text) + + pre = self.xpath('pre[6]') + self.assertEqual('2', pre.text) + + pre = self.xpath('pre[7]') + self.assertEqual('aa', pre.text) + + pre = self.xpath('pre[8]') + self.assertEqual('2', pre.text) + + pre = self.xpath('pre[9]') + self.assertEqual('ààáá', pre.text) + + pre = self.xpath('pre[10]') + self.assertEqual('4', pre.text) + + pre = self.xpath('pre[11]') + self.assertEqual('áá', pre.text) + + pre = self.xpath('pre[12]') + self.assertEqual('2', pre.text) + + pre = self.xpath('pre[13]') + self.assertEqual('àà', pre.text) + + pre = self.xpath('pre[14]') + self.assertEqual('2', pre.text) + + def test_5(self): + """Test case: strsub (5)""" + self.start('Utf8/strsubs') + + pre = self.xpath('pre[1]') + self.assertEqual('a', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('b', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('à', pre.text) + + pre = self.xpath('pre[4]') + self.assertEqual('ç', pre.text) + + def test_6(self): + """Test case: strsuffix (6)""" + self.start('Utf8/strsuffixs') + + pre = self.xpath('pre[1]') + self.assertEqual('abàç', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('bàç', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('àç', pre.text) + + pre = self.xpath('pre[4]') + self.assertEqual('ç', pre.text) + + def test_7(self): + """Test case: strchr (7)""" + self.start('Utf8/strchrs') + + pre = self.xpath('pre[1]') + self.assertEqual('None', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('Some "bàç"', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('Some "àç"', pre.text) + + pre = self.xpath('pre[4]') + self.assertEqual('Some "ç"', pre.text) + + pre = self.xpath('pre[5]') + self.assertEqual('Some ""', pre.text) + + def test_8(self): + """Test case: strindex (8)""" + self.start('Utf8/strindexs') + + pre = self.xpath('pre[1]') + self.assertEqual('None', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('Some 0', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('Some 1', pre.text) + + pre = self.xpath('pre[4]') + self.assertEqual('Some 2', pre.text) + + pre = self.xpath('pre[5]') + self.assertEqual('Some 3', pre.text) + + def test_9(self): + """Test case: strindex (9)""" + self.start('Utf8/strsindexs') + + pre = self.xpath('pre[1]') + # behavior of strstr C function + self.assertEqual('Some 0', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('Some 0', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('None', pre.text) + + pre = self.xpath('pre[4]') + self.assertEqual('Some 1', pre.text) + + pre = self.xpath('pre[5]') + self.assertEqual('None', pre.text) + + pre = self.xpath('pre[6]') + self.assertEqual('Some 2', pre.text) + + pre = self.xpath('pre[7]') + self.assertEqual('None', pre.text) + + pre = self.xpath('pre[8]') + self.assertEqual('None', pre.text) + + pre = self.xpath('pre[9]') + self.assertEqual('Some 3', pre.text) + + def test_10(self): + """Test case: strcspn (10)""" + self.start('Utf8/strcspns') + + pre = self.xpath('pre[1]') + self.assertEqual('4', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('0', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('0', pre.text) + + pre = self.xpath('pre[4]') + self.assertEqual('1', pre.text) + + pre = self.xpath('pre[5]') + self.assertEqual('2', pre.text) + + pre = self.xpath('pre[6]') + self.assertEqual('3', pre.text) + + def test_11(self): + """Test case: str1 (11)""" + self.start('Utf8/str1s') + + pre = self.xpath('pre[1]') + self.assertEqual('a', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('à', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('á', pre.text) + + def test_12(self): + """Test case: isalnum (12)""" + self.start('Utf8/isalnums') + + for idx in range(1, 9): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed isalnum: assert ' + str(idx)) + + def test_13(self): + """Test case: isalpha (13)""" + self.start('Utf8/isalphas') + + for idx in range(1, 9): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed isalpha: assert ' + str(idx)) + + def test_14(self): + """Test case: isblank (14)""" + self.start('Utf8/isblanks') + + for idx in range(1, 11): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed isblank: assert ' + str(idx)) + + def test_15(self): + """Test case: iscntrl (15)""" + self.start('Utf8/iscntrls') + + for idx in range(1, 11): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed iscntrl: assert ' + str(idx)) + + def test_16(self): + """Test case: isdigit (16)""" + self.start('Utf8/isdigits') + + for idx in range(1, 11): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed isdigit: assert ' + str(idx)) + + + def test_17(self): + """Test case: isgraph (17)""" + self.start('Utf8/isgraphs') + + for idx in range(1, 11): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed isgraph: assert ' + str(idx)) + + def test_18(self): + """Test case: islower (18)""" + self.start('Utf8/islowers') + + for idx in range(1, 11): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed islower: assert ' + str(idx)) + + def test_19(self): + """Test case: isprint (19)""" + self.start('Utf8/isprints') + + for idx in range(1, 11): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed isprint: assert ' + str(idx)) + + def test_20(self): + """Test case: ispunct (20)""" + self.start('Utf8/ispuncts') + + for idx in range(1, 11): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed ispunct: assert ' + str(idx)) + + def test_21(self): + """Test case: isspace (21)""" + self.start('Utf8/isspaces') + + for idx in range(1, 11): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed isspace: assert ' + str(idx)) + + def test_22(self): + """Test case: isupper (22)""" + self.start('Utf8/isuppers') + + for idx in range(1, 11): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed isupper: assert ' + str(idx)) + + def test_23(self): + """Test case: isxdigit (23)""" + self.start('Utf8/isxdigits') + + for idx in range(1, 11): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed isxdigit: assert ' + str(idx)) + + def test_24(self): + """Test case: toupper (24)""" + self.start('Utf8/touppers') + + for idx in range(1, 6): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed toupper: assert ' + str(idx)) + + def test_25(self): + """Test case: ord (25)""" + self.start('Utf8/ord_and_chrs') + + for idx in range(1, 8): + pre = self.xpath('pre[' + str(idx) + ']') + self.assertEqual('True', pre.text, 'Failed ord: assert ' + str(idx)) + + def test_26 (self): + """Test case: test_db (26) """ + self.start('Utf8/test_db') + + pre = self.xpath('pre[1]') + self.assertEqual('abc', pre.text) + + pre = self.xpath('pre[2]') + self.assertEqual('3', pre.text) + + pre = self.xpath('pre[3]') + self.assertEqual('çãó', pre.text) + + pre = self.xpath('pre[4]') + self.assertEqual('3', pre.text) + + pre = self.xpath('pre[5]') + self.assertEqual('が', pre.text) + + pre = self.xpath('pre[6]') + self.assertEqual('1', pre.text) + + pre = self.xpath('pre[7]') + self.assertEqual('漢', pre.text) + + pre = self.xpath('pre[8]') + self.assertEqual('1', pre.text) + + pre = self.xpath('pre[9]') + self.assertEqual('カ', pre.text) + + pre = self.xpath('pre[10]') + self.assertEqual('1', pre.text) + + pre = self.xpath('pre[11]') + self.assertEqual('وظيفية', pre.text) + + pre = self.xpath('pre[12]') + self.assertEqual('6', pre.text) -- cgit v1.2.3 From f6d40570a8859260571f0b904ba329a1c4d1046c Mon Sep 17 00:00:00 2001 From: fab Date: Mon, 19 Nov 2018 20:33:20 +0000 Subject: several fixes on unit tests and implementation --- lib/js/urweb.js | 6 +- src/c/urweb.c | 22 ++- tests/utf8.py | 344 +------------------------------- tests/utf8.ur | 605 ++++++++++++++++++++++++++++++-------------------------- tests/utf8.urp | 1 + 5 files changed, 350 insertions(+), 628 deletions(-) (limited to 'tests/utf8.py') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index f81f05e3..de1a2ad0 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -27,8 +27,8 @@ function le(x, y) { return x <= y; } // Characters -function isLower(c) { return c >= 'a' && c <= 'z'; } -function isUpper(c) { return c >= 'A' && c <= 'Z'; } +function isLower(c) { return c.toLowerCase() == c && c != c.toUpperCase(); } +function isUpper(c) { return c.toUpperCase() == c && c != c.toLowerCase(); } function isAlpha(c) { return isLower(c) || isUpper(c); } function isDigit(c) { return c >= '0' && c <= '9'; } function isAlnum(c) { return isAlpha(c) || isDigit(c); } @@ -36,7 +36,7 @@ function isBlank(c) { return c == ' ' || c == '\t'; } function isSpace(c) { return isBlank(c) || c == '\r' || c == '\n'; } function isXdigit(c) { return isDigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); } function ord(c) { return c.charCodeAt(0); } -function isPrint(c) { return ord(c) > 31 && ord(c) < 127; } +function isPrint(c) { return ord(c) > 31 && ord(c) != 127; } function toLower(c) { return c.toLowerCase(); } function toUpper(c) { return c.toUpperCase(); } diff --git a/src/c/urweb.c b/src/c/urweb.c index 69c3da94..be65afcc 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -1606,8 +1606,9 @@ uw_Basis_string uw_Basis_jsifyString(uw_context ctx, uw_Basis_string s) { return r; } +uw_Basis_bool uw_Basis_isprint(uw_context ctx, uw_Basis_char ch); + uw_Basis_string uw_Basis_jsifyChar(uw_context ctx, uw_Basis_char c1) { - unsigned char c = c1; char *r, *s2; uw_check_heap(ctx, 7); @@ -1615,7 +1616,7 @@ uw_Basis_string uw_Basis_jsifyChar(uw_context ctx, uw_Basis_char c1) { r = s2 = ctx->heap.front; *s2++ = '"'; - switch (c) { + switch (c1) { case '"': strcpy(s2, "\\\""); s2 += 2; @@ -1637,10 +1638,16 @@ uw_Basis_string uw_Basis_jsifyChar(uw_context ctx, uw_Basis_char c1) { s2 += 4; break; default: - if (isprint((int)c) || c >= 128) - *s2++ = c; + + if (uw_Basis_isprint(ctx, c1) == uw_Basis_True) + { + int offset = 0; + U8_APPEND_UNSAFE(s2, offset, c1); + s2 += offset; + } else { - sprintf(s2, "\\%03o", (unsigned char)c); + assert(0777 >= c1); + sprintf(s2, "\\%03o", (unsigned char)c1); s2 += 4; } } @@ -2482,16 +2489,17 @@ uw_Basis_bool uw_Basis_strlenGe(uw_context ctx, uw_Basis_string s, uw_Basis_int } int aux_strchr(uw_Basis_string s, uw_Basis_char ch, int* o_offset) { - int u8idx = 0, offset = 0; + int u8idx = 0, offset = 0, offsetpr = 0; uw_Basis_char c; while (s[offset] != 0) { U8_NEXT(s, offset, -1, c); if (c == ch) { - *o_offset = offset; + *o_offset = offsetpr; return u8idx; } + offsetpr = offset; ++u8idx; } diff --git a/tests/utf8.py b/tests/utf8.py index ff9b737a..440bc82a 100644 --- a/tests/utf8.py +++ b/tests/utf8.py @@ -5,445 +5,103 @@ class Suite(base.Base): def test_1(self): """Test case: substring (1)""" self.start('Utf8/substrings') - - pre = self.xpath('pre[1]') - self.assertEqual('abc', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('bc', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('c', pre.text) - - pre = self.xpath('pre[4]') - self.assertEqual('ábó', pre.text) - - pre = self.xpath('pre[5]') - self.assertEqual('bó', pre.text) - - pre = self.xpath('pre[6]') - self.assertEqual('ó', pre.text) - - pre = self.xpath('pre[7]') - self.assertEqual('çãó', pre.text) - - pre = self.xpath('pre[8]') - self.assertEqual('ãó', pre.text) - - pre = self.xpath('pre[9]') - self.assertEqual('ó', pre.text) - - pre = self.xpath('pre[10]') - self.assertEqual('', pre.text) - - pre = self.xpath('pre[11]') - self.assertEqual('', pre.text) - def test_2(self): """Test case: strlen (2)""" self.start('Utf8/strlens') - - pre = self.xpath('pre[1]') - self.assertEqual('3', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('3', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('3', pre.text) - - pre = self.xpath('pre[4]') - self.assertEqual('3', pre.text) - - pre = self.xpath('pre[5]') - self.assertEqual('1', pre.text) - - pre = self.xpath('pre[6]') - self.assertEqual('1', pre.text) - - pre = self.xpath('pre[7]') - self.assertEqual('0', pre.text) - - pre = self.xpath('pre[8]') - self.assertEqual('1', pre.text) - - pre = self.xpath('pre[9]') - self.assertEqual('1', pre.text) - - pre = self.xpath('pre[10]') - self.assertEqual('1', pre.text) - - pre = self.xpath('pre[11]') - self.assertEqual('6', pre.text) - - pre = self.xpath('pre[12]') - self.assertEqual('2', pre.text) - - pre = self.xpath('pre[13]') - self.assertEqual('14', pre.text) - def test_3(self): """Test case: strlenGe (3)""" self.start('Utf8/strlenGens') - - pre = self.xpath('pre[1]') - self.assertEqual('False', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('True', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('False', pre.text) - - pre = self.xpath('pre[4]') - self.assertEqual('True', pre.text) - - pre = self.xpath('pre[5]') - self.assertEqual('True', pre.text) - - pre = self.xpath('pre[6]') - self.assertEqual('False', pre.text) - - pre = self.xpath('pre[7]') - self.assertEqual('True', pre.text) - - pre = self.xpath('pre[8]') - self.assertEqual('True', pre.text) def test_4(self): """Test case: strcat (4)""" self.start('Utf8/strcats') - - pre = self.xpath('pre[1]') - self.assertEqual('', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('0', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('aabb', pre.text) - - pre = self.xpath('pre[4]') - self.assertEqual('4', pre.text) - - pre = self.xpath('pre[5]') - self.assertEqual('bb', pre.text) - - pre = self.xpath('pre[6]') - self.assertEqual('2', pre.text) - - pre = self.xpath('pre[7]') - self.assertEqual('aa', pre.text) - - pre = self.xpath('pre[8]') - self.assertEqual('2', pre.text) - - pre = self.xpath('pre[9]') - self.assertEqual('ààáá', pre.text) - - pre = self.xpath('pre[10]') - self.assertEqual('4', pre.text) - - pre = self.xpath('pre[11]') - self.assertEqual('áá', pre.text) - - pre = self.xpath('pre[12]') - self.assertEqual('2', pre.text) - - pre = self.xpath('pre[13]') - self.assertEqual('àà', pre.text) - - pre = self.xpath('pre[14]') - self.assertEqual('2', pre.text) def test_5(self): """Test case: strsub (5)""" self.start('Utf8/strsubs') - pre = self.xpath('pre[1]') - self.assertEqual('a', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('b', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('à', pre.text) - - pre = self.xpath('pre[4]') - self.assertEqual('ç', pre.text) - def test_6(self): """Test case: strsuffix (6)""" self.start('Utf8/strsuffixs') - pre = self.xpath('pre[1]') - self.assertEqual('abàç', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('bàç', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('àç', pre.text) - - pre = self.xpath('pre[4]') - self.assertEqual('ç', pre.text) - def test_7(self): """Test case: strchr (7)""" self.start('Utf8/strchrs') - - pre = self.xpath('pre[1]') - self.assertEqual('None', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('Some "bàç"', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('Some "àç"', pre.text) - - pre = self.xpath('pre[4]') - self.assertEqual('Some "ç"', pre.text) - - pre = self.xpath('pre[5]') - self.assertEqual('Some ""', pre.text) def test_8(self): """Test case: strindex (8)""" self.start('Utf8/strindexs') - - pre = self.xpath('pre[1]') - self.assertEqual('None', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('Some 0', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('Some 1', pre.text) - - pre = self.xpath('pre[4]') - self.assertEqual('Some 2', pre.text) - - pre = self.xpath('pre[5]') - self.assertEqual('Some 3', pre.text) def test_9(self): """Test case: strindex (9)""" self.start('Utf8/strsindexs') - pre = self.xpath('pre[1]') - # behavior of strstr C function - self.assertEqual('Some 0', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('Some 0', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('None', pre.text) - - pre = self.xpath('pre[4]') - self.assertEqual('Some 1', pre.text) - - pre = self.xpath('pre[5]') - self.assertEqual('None', pre.text) - - pre = self.xpath('pre[6]') - self.assertEqual('Some 2', pre.text) - - pre = self.xpath('pre[7]') - self.assertEqual('None', pre.text) - - pre = self.xpath('pre[8]') - self.assertEqual('None', pre.text) - - pre = self.xpath('pre[9]') - self.assertEqual('Some 3', pre.text) - def test_10(self): """Test case: strcspn (10)""" self.start('Utf8/strcspns') - pre = self.xpath('pre[1]') - self.assertEqual('4', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('0', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('0', pre.text) - - pre = self.xpath('pre[4]') - self.assertEqual('1', pre.text) - - pre = self.xpath('pre[5]') - self.assertEqual('2', pre.text) - - pre = self.xpath('pre[6]') - self.assertEqual('3', pre.text) - def test_11(self): """Test case: str1 (11)""" self.start('Utf8/str1s') - pre = self.xpath('pre[1]') - self.assertEqual('a', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('à', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('á', pre.text) - def test_12(self): """Test case: isalnum (12)""" self.start('Utf8/isalnums') - - for idx in range(1, 9): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed isalnum: assert ' + str(idx)) def test_13(self): """Test case: isalpha (13)""" self.start('Utf8/isalphas') - - for idx in range(1, 9): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed isalpha: assert ' + str(idx)) def test_14(self): """Test case: isblank (14)""" self.start('Utf8/isblanks') - - for idx in range(1, 11): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed isblank: assert ' + str(idx)) def test_15(self): """Test case: iscntrl (15)""" self.start('Utf8/iscntrls') - - for idx in range(1, 11): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed iscntrl: assert ' + str(idx)) - + def test_16(self): """Test case: isdigit (16)""" self.start('Utf8/isdigits') - - for idx in range(1, 11): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed isdigit: assert ' + str(idx)) - def test_17(self): """Test case: isgraph (17)""" self.start('Utf8/isgraphs') - for idx in range(1, 11): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed isgraph: assert ' + str(idx)) - def test_18(self): """Test case: islower (18)""" self.start('Utf8/islowers') - for idx in range(1, 11): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed islower: assert ' + str(idx)) - def test_19(self): """Test case: isprint (19)""" self.start('Utf8/isprints') - for idx in range(1, 11): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed isprint: assert ' + str(idx)) - def test_20(self): """Test case: ispunct (20)""" self.start('Utf8/ispuncts') - for idx in range(1, 11): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed ispunct: assert ' + str(idx)) - def test_21(self): """Test case: isspace (21)""" self.start('Utf8/isspaces') - for idx in range(1, 11): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed isspace: assert ' + str(idx)) - def test_22(self): """Test case: isupper (22)""" self.start('Utf8/isuppers') - for idx in range(1, 11): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed isupper: assert ' + str(idx)) - def test_23(self): """Test case: isxdigit (23)""" self.start('Utf8/isxdigits') - for idx in range(1, 11): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed isxdigit: assert ' + str(idx)) - def test_24(self): """Test case: toupper (24)""" self.start('Utf8/touppers') - for idx in range(1, 6): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed toupper: assert ' + str(idx)) - def test_25(self): """Test case: ord (25)""" self.start('Utf8/ord_and_chrs') - for idx in range(1, 8): - pre = self.xpath('pre[' + str(idx) + ']') - self.assertEqual('True', pre.text, 'Failed ord: assert ' + str(idx)) - def test_26 (self): """Test case: test_db (26) """ self.start('Utf8/test_db') - - pre = self.xpath('pre[1]') - self.assertEqual('abc', pre.text) - - pre = self.xpath('pre[2]') - self.assertEqual('3', pre.text) - - pre = self.xpath('pre[3]') - self.assertEqual('çãó', pre.text) - - pre = self.xpath('pre[4]') - self.assertEqual('3', pre.text) - - pre = self.xpath('pre[5]') - self.assertEqual('が', pre.text) - - pre = self.xpath('pre[6]') - self.assertEqual('1', pre.text) - - pre = self.xpath('pre[7]') - self.assertEqual('漢', pre.text) - - pre = self.xpath('pre[8]') - self.assertEqual('1', pre.text) - - pre = self.xpath('pre[9]') - self.assertEqual('カ', pre.text) - - pre = self.xpath('pre[10]') - self.assertEqual('1', pre.text) - - pre = self.xpath('pre[11]') - self.assertEqual('وظيفية', pre.text) - - pre = self.xpath('pre[12]') - self.assertEqual('6', pre.text) diff --git a/tests/utf8.ur b/tests/utf8.ur index 0dedc726..1038a59f 100644 --- a/tests/utf8.ur +++ b/tests/utf8.ur @@ -1,68 +1,104 @@ -fun substrings () : transaction page = return - -
{[substring "abc" 0 3]}
-
{[substring "abc" 1 2]}
-
{[substring "abc" 2 1]}
-
{[substring "ábó" 0 3]}
-
{[substring "ábó" 1 2]}
-
{[substring "ábó" 2 1]}
-
{[substring "çãó" 0 3]}
-
{[substring "çãó" 1 2]}
-
{[substring "çãó" 2 1]}
-
{[substring "çãó" 2 0]}
-
{[substring "" 0 0]}
- + +fun test_fn_both_sides [a ::: Type] (_ : eq a) (_ : show a) (f : unit -> a) (expected : a) (testname : string) : xbody = + +

Server side test: {[testname]}

+
{[assert (f () = expected) "False" testname "True" ]}
+

Client side test: {[testname]}

{[r]}
+ end}> +
+fun test_fn_sside [a ::: Type] (_ : eq a) (_ : show a) (f : unit -> a) (expected : a) (testname : string) : xbody = + +

Server side test: {[testname]}

+
{[assert (f () = expected) "False" testname "True" ]}
+
+ +fun substrings () : transaction page = + + return + + + {test_fn_both_sides (fn _ => substring "abc" 0 3) "abc" "substrings 1"} + {test_fn_both_sides (fn _ => substring "abc" 1 2) "bc" "substrings 2"} + {test_fn_both_sides (fn _ => substring "abc" 2 1) "c" "substrings 3"} + {test_fn_both_sides (fn _ => substring "ábó" 0 3) "ábó" "substrings 4"} + {test_fn_both_sides (fn _ => substring "ábó" 1 2) "bó" "substrings 5"} + {test_fn_both_sides (fn _ => substring "ábó" 2 1) "ó" "substrings 6"} + {test_fn_both_sides (fn _ => substring "ábó" 0 2) "áb" "substrings 7"} + {test_fn_both_sides (fn _ => substring "ábó" 0 1) "á" "substrings 8"} + + {test_fn_both_sides (fn _ => substring "" 0 0) "" "substrings 9"} + + + + fun strlens () : transaction page = return - -
{[strlen "abc"]}
-
{[strlen "çbc"]}
-
{[strlen "çãc"]}
-
{[strlen "çãó"]}
-
{[strlen "ç"]}
-
{[strlen "c"]}
-
{[strlen ""]}
-
{[strlen "が"]}
-
{[strlen "漢"]}
-
{[strlen "カ"]}
-
{[strlen "وظيفية"]}
-
{[strlen "函數"]}
-
{[strlen "Функциональное"]}
+ + {test_fn_both_sides (fn _ => strlen "abc") 3 "strlen 1"} + {test_fn_both_sides (fn _ => strlen "çbc") 3 "strlen 2"} + {test_fn_both_sides (fn _ => strlen "çãc") 3 "strlen 3"} + {test_fn_both_sides (fn _ => strlen "çãó") 3 "strlen 4"} + {test_fn_both_sides (fn _ => strlen "ç") 1 "strlen 5"} + {test_fn_both_sides (fn _ => strlen "c") 1 "strlen 6"} + {test_fn_both_sides (fn _ => strlen "") 0 "strlen 7"} + {test_fn_both_sides (fn _ => strlen "が") 1 "strlen 8"} + {test_fn_both_sides (fn _ => strlen "漢") 1 "strlen 9"} + {test_fn_both_sides (fn _ => strlen "カ") 1 "strlen 10"} + {test_fn_both_sides (fn _ => strlen "وظيفية") 6 "strlen 11"} + {test_fn_both_sides (fn _ => strlen "函數") 2 "strlen 12"} + {test_fn_both_sides (fn _ => strlen "Функциональное") 14 "strlen 13"} +
fun strlenGens () : transaction page = return -
{[strlenGe "" 1]}
-
{[strlenGe "" 0]}
-
{[strlenGe "aba" 4]}
-
{[strlenGe "aba" 3]}
-
{[strlenGe "aba" 2]}
-
{[strlenGe "áçà" 4]}
-
{[strlenGe "áçà" 3]}
-
{[strlenGe "áçà" 2]}
+ {test_fn_both_sides (fn _ => strlenGe "" 1) False "strlenGe 1"} + {test_fn_both_sides (fn _ => strlenGe "" 0) True "strlenGe 2"} + {test_fn_both_sides (fn _ => strlenGe "aba" 4) False "strlenGe 3"} + {test_fn_both_sides (fn _ => strlenGe "aba" 3) True "strlenGe 4"} + {test_fn_both_sides (fn _ => strlenGe "aba" 2) True "strlenGe 5"} + + {test_fn_both_sides (fn _ => strlenGe "àçá" 4) False "strlenGe 6"} + {test_fn_both_sides (fn _ => strlenGe "àçá" 3) True "strlenGe 7"} + {test_fn_both_sides (fn _ => strlenGe "àçá" 2) True "strlenGe 8"}
+type clen = { S : string, L : int } + +val clen_eq : eq clen = mkEq (fn a b => + a.S = b.S && a.L = b.L) + +val clen_show : show clen = mkShow (fn a => + "{S = " ^ a.S ^ ", L = " ^ (show a.L) ^ "}") + fun strcats () : transaction page = let - fun catAndLen a b = - -
{[strcat a b]}
-
{[strlen (strcat a b)]}
-
+ fun test_cat_and_len n a b expS expL = + test_fn_both_sides (fn _ => let val c = strcat a b in {S = c, L = strlen c} end) {S=expS, L=expL} ("strcat " ^ (show n)) in return - {catAndLen "" ""} - {catAndLen "aa" "bb"} - {catAndLen "" "bb"} - {catAndLen "aa" ""} - {catAndLen "àà" "áá"} - {catAndLen "" "áá"} - {catAndLen "àà" ""} + {test_cat_and_len 1 "" "" "" 0} + + {test_cat_and_len 2 "aa" "bb" "aabb" 4} + {test_cat_and_len 3 "" "bb" "bb" 2} + {test_cat_and_len 4 "aa" "" "aa" 2} + + {test_cat_and_len 5 "àà" "áá" "ààáá" 4} + {test_cat_and_len 6 "" "áá" "áá" 2} + {test_cat_and_len 7 "àà" "" "àà" 2} + + {test_cat_and_len 8 "函數" "ãã" "函數ãã" 4} + end @@ -70,324 +106,303 @@ end fun strsubs () : transaction page = return -
{[strsub "abàç" 0]}
-
{[strsub "abàç" 1]}
-
{[strsub "abàç" 2]}
-
{[strsub "abàç" 3]}
+ {test_fn_both_sides (fn _ => strsub "abàç" 0) #"a" "strsub 1"} + {test_fn_both_sides (fn _ => strsub "abàç" 1) #"b" "strsub 2"} + {test_fn_both_sides (fn _ => strsub "àb" 0) (strsub "à" 0) "strsub 3"} + {test_fn_both_sides (fn _ => strsub "abàç" 2) (strsub "à" 0) "strsub 4"} + {test_fn_both_sides (fn _ => strsub "abàç" 3) (strsub "ç" 0) "strsub 5"}
fun strsuffixs () : transaction page = return -
{[strsuffix "abàç" 0]}
-
{[strsuffix "abàç" 1]}
-
{[strsuffix "abàç" 2]}
-
{[strsuffix "abàç" 3]}
+ {test_fn_both_sides (fn _ => strsuffix "abàç" 0) "abàç" "strsuffix 1"} + {test_fn_both_sides (fn _ => strsuffix "abàç" 1) "bàç" "strsuffix 2"} + {test_fn_both_sides (fn _ => strsuffix "abàç" 2) "àç" "strsuffix 3"} + {test_fn_both_sides (fn _ => strsuffix "abàç" 3) "ç" "strsuffix 4"}
fun strchrs () : transaction page = - let - fun optToStr ms = - case ms of - None => "None" - | Some s => "Some \"" ^ s ^ "\"" - - in - return - -
{[optToStr (strchr "abàç" #"c")]}
-
{[optToStr (strchr "abàç" #"a")]}
-
{[optToStr (strchr "abàç" #"b")]}
-
{[optToStr (strchr "abàç" (strsub "à" 0))]}
-
{[optToStr (strchr "abàç" (strsub "ç" 0))]}
- -
- end + return + + {test_fn_both_sides (fn _ => strchr "abàç" #"c") None "strchr 1"} + {test_fn_both_sides (fn _ => strchr "abàç" #"a") (Some "abàç") "strchr 2"} + {test_fn_both_sides (fn _ => strchr "abàç" #"b") (Some "bàç") "strchr 3"} + {test_fn_both_sides (fn _ => strchr "abàç" (strsub "à" 0)) (Some "àç") "strchr 4"} + {test_fn_both_sides (fn _ => strchr "abàç" (strsub "ç" 0)) (Some "ç") "strchr 5"} + + fun strindexs () : transaction page = - let - fun optToStr ms = - case ms of - None => "None" - | Some s => "Some " ^ (show s) - - in - return - -
{[optToStr (strindex "abàç" #"c")]}
-
{[optToStr (strindex "abàç" #"a")]}
-
{[optToStr (strindex "abàç" #"b")]}
-
{[optToStr (strindex "abàç" (strsub "à" 0))]}
-
{[optToStr (strindex "abàç" (strsub "ç" 0))]}
- -
- end + return + + {test_fn_both_sides (fn _ => strindex "abàç" #"c") None "strindex 1"} + {test_fn_both_sides (fn _ => strindex "abàç" #"a") (Some 0) "strindex 2"} + {test_fn_both_sides (fn _ => strindex "abàç" #"b") (Some 1) "strindex 3"} + {test_fn_both_sides (fn _ => strindex "abàç" (strsub "à" 0)) (Some 2) "strindex 4"} + {test_fn_both_sides (fn _ => strindex "abàç" (strsub "ç" 0)) (Some 3) "strindex 5"} + + + fun strsindexs () : transaction page = - let - fun optToStr ms = - case ms of - None => "None" - | Some s => "Some " ^ (show s) - - in - return - -
{[optToStr (strsindex "abàç" "")]}
-
{[optToStr (strsindex "abàç" "abàç")]}
-
{[optToStr (strsindex "abàç" "abàc")]}
-
{[optToStr (strsindex "abàç" "bàç")]}
-
{[optToStr (strsindex "abàç" "bàc")]}
-
{[optToStr (strsindex "abàç" "àç")]}
-
{[optToStr (strsindex "abàç" "àc")]}
-
{[optToStr (strsindex "abàç" "ac")]}
-
{[optToStr (strsindex "abàç" "ç")]}
- -
- end + return + + {test_fn_both_sides (fn _ => strsindex "abàç" "") (Some 0) "strsindex 1"} + {test_fn_both_sides (fn _ => strsindex "abàç" "abàç") (Some 0) "strsindex 2"} + {test_fn_both_sides (fn _ => strsindex "abàç" "abàc") None "strsindex 3"} + {test_fn_both_sides (fn _ => strsindex "abàç" "bàç") (Some 1) "strsindex 4"} + {test_fn_both_sides (fn _ => strsindex "abàç" "bàc") None "strsindex 5"} + {test_fn_both_sides (fn _ => strsindex "abàç" "àç") (Some 2) "strsindex 6"} + {test_fn_both_sides (fn _ => strsindex "abàç" "àc") None "strsindex 7"} + {test_fn_both_sides (fn _ => strsindex "abàç" "ç") (Some 3) "strsindex 8"} + {test_fn_both_sides (fn _ => strsindex "abàç" "c") None "strsindex 9"} + + fun strcspns () : transaction page = return -
{[strcspn "abàç" ""]}
-
{[strcspn "abàç" "abàç"]}
-
{[strcspn "abàç" "a"]}
-
{[strcspn "abàç" "bàç"]}
-
{[strcspn "abàç" "àç"]}
-
{[strcspn "abàç" "ç"]}
+ {test_fn_both_sides (fn _ => strcspn "abàç" "") 4 "strcspn 1"} + {test_fn_both_sides (fn _ => strcspn "abàç" "abàç") 0 "strcspn 2"} + {test_fn_both_sides (fn _ => strcspn "abàç" "a") 0 "strcspn 3"} + {test_fn_both_sides (fn _ => strcspn "abàç" "bàç") 1 "strcspn 4"} + {test_fn_both_sides (fn _ => strcspn "abàç" "àç") 2 "strcspn 5"} + {test_fn_both_sides (fn _ => strcspn "abàç" "ç") 3 "strcspn 6"}
fun str1s () : transaction page = return -
{[str1 #"a"]}
-
{[str1 (strsub "à" 0)]}
-
{[str1 (strsub "aá" 1)]}
+ {test_fn_both_sides (fn _ => str1 #"a") "a" "str1 1"} + {test_fn_both_sides (fn _ => str1 (strsub "à" 0)) "à" "str1 2"} + {test_fn_both_sides (fn _ => str1 (strsub "aá" 1)) "á" "str1 3"}
fun isalnums () : transaction page = return -
{[isalnum #"a"]}
-
{[isalnum (strsub "à" 0)]}
-
{[isalnum #"A"]}
-
{[isalnum (strsub "À" 0)]}
-
{[isalnum #"1"]}
-
{[not (isalnum #"!")]}
-
{[not (isalnum #"#")]}
-
{[not (isalnum #" ")]}
+ {test_fn_both_sides (fn _ => isalnum #"a") True "isalnum 1"} + {test_fn_both_sides (fn _ => isalnum #"a") True "isalnum 2"} + {test_fn_both_sides (fn _ => isalnum (strsub "à" 0)) True "isalnum 3"} + {test_fn_both_sides (fn _ => isalnum #"A") True "isalnum 4"} + {test_fn_both_sides (fn _ => isalnum (strsub "À" 0)) True "isalnum 5"} + {test_fn_both_sides (fn _ => isalnum #"1") True "isalnum 6"} + {test_fn_both_sides (fn _ => not (isalnum #"!")) True "isalnum 7"} + {test_fn_both_sides (fn _ => not (isalnum #"#")) True "isalnum 8"} + {test_fn_both_sides (fn _ => not (isalnum #" ")) True "isalnum 9"}
fun isalphas () : transaction page = return -
{[isalpha #"a"]}
-
{[isalpha (strsub "à" 0)]}
-
{[isalpha #"A"]}
-
{[isalpha (strsub "À" 0)]}
-
{[not (isalpha #"1")]}
-
{[not (isalpha #"!")]}
-
{[not (isalpha #"#")]}
-
{[not (isalpha #" ")]}
+ {test_fn_both_sides (fn _ => isalpha #"a") True "isalpha 1"} + {test_fn_both_sides (fn _ => isalpha (strsub "à" 0)) True "isalpha 2"} + {test_fn_both_sides (fn _ => isalpha #"A") True "isalpha 3"} + {test_fn_both_sides (fn _ => isalpha (strsub "À" 0)) True "isalpha 4"} + {test_fn_both_sides (fn _ => not (isalpha #"1")) True "isalpha 5"} + {test_fn_both_sides (fn _ => not (isalpha #"!")) True "isalpha 6"} + {test_fn_both_sides (fn _ => not (isalpha #"#")) True "isalpha 7"} + {test_fn_both_sides (fn _ => not (isalpha #" ")) True "isalpha 8"}
fun isblanks () : transaction page = return -
{[not (isblank #"a")]}
-
{[not (isblank (strsub "à" 0))]}
-
{[not (isblank #"A")]}
-
{[not (isblank (strsub "À" 0))]}
-
{[not (isblank #"1")]}
-
{[not (isblank #"!")]}
-
{[not (isblank #"#")]}
-
{[isblank #" "]}
-
{[isblank #"\t"]}
-
{[not (isblank #"\n")]}
+ {test_fn_both_sides (fn _ => not (isblank #"a")) True "isblank 1"} + {test_fn_both_sides (fn _ => not (isblank (strsub "à" 0))) True "isblank 2"} + {test_fn_both_sides (fn _ => not (isblank #"A")) True "isblank 3"} + {test_fn_both_sides (fn _ => not (isblank (strsub "À" 0))) True "isblank 4"} + {test_fn_both_sides (fn _ => not (isblank #"1")) True "isblank 5"} + {test_fn_both_sides (fn _ => not (isblank #"!")) True "isblank 6"} + {test_fn_both_sides (fn _ => not (isblank #"#")) True "isblank 7"} + {test_fn_both_sides (fn _ => isblank #" ") True "isblank 8"} + {test_fn_both_sides (fn _ => isblank #"\t") True "isblank 9"} + {test_fn_both_sides (fn _ => not (isblank #"\n")) True "isblank 10"}
fun iscntrls () : transaction page = return -
{[not (iscntrl #"a")]}
-
{[not (iscntrl (strsub "à" 0))]}
-
{[not (iscntrl #"A")]}
-
{[not (iscntrl (strsub "À" 0))]}
-
{[not (iscntrl #"1")]}
-
{[not (iscntrl #"!")]}
-
{[not (iscntrl #"#")]}
-
{[not (iscntrl #" ")]}
-
{[iscntrl #"\t"]}
-
{[iscntrl #"\n"]}
+ {test_fn_sside (fn _ => not (iscntrl #"a")) True "iscntrl 1"} + {test_fn_sside (fn _ => not (iscntrl (strsub "à" 0))) True "iscntrl 2"} + {test_fn_sside (fn _ => not (iscntrl #"A")) True "iscntrl 3"} + {test_fn_sside (fn _ => not (iscntrl (strsub "À" 0))) True "iscntrl 4"} + {test_fn_sside (fn _ => not (iscntrl #"1")) True "iscntrl 5"} + {test_fn_sside (fn _ => not (iscntrl #"!")) True "iscntrl 6"} + {test_fn_sside (fn _ => not (iscntrl #"#")) True "iscntrl 7"} + {test_fn_sside (fn _ => not (iscntrl #" ")) True "iscntrl 8"} + {test_fn_sside (fn _ => iscntrl #"\t") True "iscntrl 9"} + {test_fn_sside (fn _ => iscntrl #"\n") True "iscntrl 10"}
fun isdigits () : transaction page = return -
{[not (isdigit #"a")]}
-
{[not (isdigit (strsub "à" 0))]}
-
{[not (isdigit #"A")]}
-
{[not (isdigit (strsub "À" 0))]}
-
{[isdigit #"1"]}
-
{[not (isdigit #"!")]}
-
{[not (isdigit #"#")]}
-
{[not (isdigit #" ")]}
-
{[not (isdigit #"\t")]}
-
{[not (isdigit #"\n")]}
+ {test_fn_both_sides (fn _ => not (isdigit #"a")) True "isdigit 1"} + {test_fn_both_sides (fn _ => not (isdigit (strsub "à" 0))) True "isdigit 2"} + {test_fn_both_sides (fn _ => not (isdigit #"A")) True "isdigit 3"} + {test_fn_both_sides (fn _ => not (isdigit (strsub "À" 0))) True "isdigit 4"} + {test_fn_both_sides (fn _ => isdigit #"1") True "isdigit 5"} + {test_fn_both_sides (fn _ => not (isdigit #"!")) True "isdigit 6"} + {test_fn_both_sides (fn _ => not (isdigit #"#")) True "isdigit 7"} + {test_fn_both_sides (fn _ => not (isdigit #" ")) True "isdigit 8"} + {test_fn_both_sides (fn _ => not (isdigit #"\t")) True "isdigit 9"} + {test_fn_both_sides (fn _ => not (isdigit #"\n")) True "isdigit 10"} -
+ fun isgraphs () : transaction page = return -
{[isgraph #"a"]}
-
{[isgraph (strsub "à" 0)]}
-
{[isgraph #"A"]}
-
{[isgraph (strsub "À" 0)]}
-
{[isgraph #"1"]}
-
{[isgraph #"!"]}
-
{[isgraph #"#"]}
-
{[not (isgraph #" ")]}
-
{[not (isgraph #"\t")]}
-
{[not (isdigit #"\n")]}
+ {test_fn_sside (fn _ => isgraph #"a") True "isgraph 1"} + {test_fn_sside (fn _ => isgraph (strsub "à" 0)) True "isgraph 2"} + {test_fn_sside (fn _ => isgraph #"A") True "isgraph 3"} + {test_fn_sside (fn _ => isgraph (strsub "À" 0)) True "isgraph 4"} + {test_fn_sside (fn _ => isgraph #"1") True "isgraph 5"} + {test_fn_sside (fn _ => isgraph #"!") True "isgraph 6"} + {test_fn_sside (fn _ => isgraph #"#") True "isgraph 7"} + {test_fn_sside (fn _ => not (isgraph #" ")) True "isgraph 8"} + {test_fn_sside (fn _ => not (isgraph #"\t")) True "isgraph 9"} + {test_fn_sside (fn _ => not (isdigit #"\n")) True "isgraph 10"} -
+ fun islowers () : transaction page = return -
{[islower #"a"]}
-
{[islower (strsub "à" 0)]}
-
{[not (islower #"A")]}
-
{[not (islower (strsub "À" 0))]}
-
{[not (islower #"1")]}
-
{[not (islower #"!")]}
-
{[not (islower #"#")]}
-
{[not (islower #" ")]}
-
{[not (islower #"\t")]}
-
{[not (islower #"\n")]}
+ {test_fn_both_sides (fn _ => islower #"a") True "islower 1"} + {test_fn_both_sides (fn _ => islower (strsub "à" 0)) True "islower 2"} + {test_fn_both_sides (fn _ => not (islower #"A")) True "islower 3"} + {test_fn_both_sides (fn _ => not (islower (strsub "À" 0))) True "islower 4"} + {test_fn_both_sides (fn _ => not (islower #"1")) True "islower 5"} + {test_fn_both_sides (fn _ => not (islower #"!")) True "islower 6"} + {test_fn_both_sides (fn _ => not (islower #"#")) True "islower 7"} + {test_fn_both_sides (fn _ => not (islower #" ")) True "islower 8"} + {test_fn_both_sides (fn _ => not (islower #"\t")) True "islower 9"} + {test_fn_both_sides (fn _ => not (islower #"\n")) True "islower 10"}
fun isprints () : transaction page = return -
{[isprint #"a"]}
-
{[isprint (strsub "à" 0)]}
-
{[isprint #"A"]}
-
{[isprint (strsub "À" 0)]}
-
{[isprint #"1"]}
-
{[isprint #"!"]}
-
{[isprint #"#"]}
-
{[isprint #" "]}
-
{[not (isprint #"\t")]}
-
{[not (isprint #"\n")]}
+ {test_fn_both_sides (fn _ => isprint #"a") True "isprint 1"} + {test_fn_both_sides (fn _ => isprint (strsub "à" 0)) True "isprint 2"} + {test_fn_both_sides (fn _ => isprint #"A") True "isprint 3"} + {test_fn_both_sides (fn _ => isprint (strsub "À" 0)) True "isprint 4"} + {test_fn_both_sides (fn _ => isprint #"1") True "isprint 5"} + {test_fn_both_sides (fn _ => isprint #"!") True "isprint 6"} + {test_fn_both_sides (fn _ => isprint #"#") True "isprint 7"} + {test_fn_both_sides (fn _ => isprint #" ") True "isprint 8"} + {test_fn_both_sides (fn _ => not (isprint #"\t")) True "isprint 9"} + {test_fn_both_sides (fn _ => not (isprint #"\n")) True "isprint 10"}
fun ispuncts () : transaction page = return -
{[not (ispunct #"a")]}
-
{[not (ispunct (strsub "à" 0))]}
-
{[not (ispunct #"A")]}
-
{[not (ispunct (strsub "À" 0))]}
-
{[not (ispunct #"1")]}
-
{[ispunct #"!"]}
-
{[ispunct #"#"]}
-
{[not (ispunct #" ")]}
-
{[not (isprint #"\t")]}
-
{[not (isprint #"\n")]}
+ {test_fn_sside (fn _ => not (ispunct #"a")) True "ispunct 1"} + {test_fn_sside (fn _ => not (ispunct (strsub "à" 0))) True "ispunct 2"} + {test_fn_sside (fn _ => not (ispunct #"A")) True "ispunct 3"} + {test_fn_sside (fn _ => not (ispunct (strsub "À" 0))) True "ispunct 4"} + {test_fn_sside (fn _ => not (ispunct #"1")) True "ispunct 5"} + {test_fn_sside (fn _ => ispunct #"!") True "ispunct 6"} + {test_fn_sside (fn _ => ispunct #"#") True "ispunct 7"} + {test_fn_sside (fn _ => not (ispunct #" ")) True "ispunct 8"} + {test_fn_sside (fn _ => not (isprint #"\t")) True "ispunct 9"} + {test_fn_sside (fn _ => not (isprint #"\n")) True "ispunct 10"}
fun isspaces () : transaction page = return -
{[not (isspace #"a")]}
-
{[not (isspace (strsub "à" 0))]}
-
{[not (isspace #"A")]}
-
{[not (isspace (strsub "À" 0))]}
-
{[not (isspace #"1")]}
-
{[not (isspace #"!")]}
-
{[not (isspace #"#")]}
-
{[isspace #" "]}
-
{[isspace #"\t"]}
-
{[isspace #"\n"]}
+ {test_fn_both_sides (fn _ => not (isspace #"a")) True "isspace 1"} + {test_fn_both_sides (fn _ => not (isspace (strsub "à" 0))) True "isspace 2"} + {test_fn_both_sides (fn _ => not (isspace #"A")) True "isspace 3"} + {test_fn_both_sides (fn _ => not (isspace (strsub "À" 0))) True "isspace 4"} + {test_fn_both_sides (fn _ => not (isspace #"1")) True "isspace 5"} + {test_fn_both_sides (fn _ => not (isspace #"!")) True "isspace 6"} + {test_fn_both_sides (fn _ => not (isspace #"#")) True "isspace 7"} + {test_fn_both_sides (fn _ => isspace #" ") True "isspace 8"} + {test_fn_both_sides (fn _ => isspace #"\t") True "isspace 9"} + {test_fn_both_sides (fn _ => isspace #"\n") True "isspace 10"}
fun isuppers () : transaction page = return -
{[not (isupper #"a")]}
-
{[not (isupper (strsub "à" 0))]}
-
{[isupper #"A"]}
-
{[isupper (strsub "À" 0)]}
-
{[not (isupper #"1")]}
-
{[not (isupper #"!")]}
-
{[not (isupper #"#")]}
-
{[not (isupper #" ")]}
-
{[not (isupper #"\t")]}
-
{[not (isupper #"\n")]}
+ {test_fn_both_sides (fn _ => not (isupper #"a")) True "isupper 1"} + {test_fn_both_sides (fn _ => not (isupper (strsub "à" 0))) True "isupper 2"} + {test_fn_both_sides (fn _ => isupper #"A") True "isupper 3"} + {test_fn_both_sides (fn _ => isupper (strsub "À" 0)) True "isupper 4"} + {test_fn_both_sides (fn _ => not (isupper #"1")) True "isupper 5"} + {test_fn_both_sides (fn _ => not (isupper #"!")) True "isupper 6"} + {test_fn_both_sides (fn _ => not (isupper #"#")) True "isupper 7"} + {test_fn_both_sides (fn _ => not (isupper #" ")) True "isupper 8"} + {test_fn_both_sides (fn _ => not (isupper #"\t")) True "isupper 9"} + {test_fn_both_sides (fn _ => not (isupper #"\n")) True "isupper 10"}
fun isxdigits () : transaction page = return -
{[isxdigit #"a"]}
-
{[not (isxdigit (strsub "à" 0))]}
-
{[isxdigit #"A"]}
-
{[not (isxdigit (strsub "À" 0))]}
-
{[isxdigit #"1"]}
-
{[not (isxdigit #"!")]}
-
{[not (isxdigit #"#")]}
-
{[not (isxdigit #" ")]}
-
{[not (isxdigit #"\t")]}
-
{[not (isxdigit #"\n")]}
+ {test_fn_both_sides (fn _ => isxdigit #"a") True "isxdigit 1"} + {test_fn_both_sides (fn _ => not (isxdigit (strsub "à" 0))) True "isxdigit 2"} + {test_fn_both_sides (fn _ => isxdigit #"A") True "isxdigit 3"} + {test_fn_both_sides (fn _ => not (isxdigit (strsub "À" 0))) True "isxdigit 4"} + {test_fn_both_sides (fn _ => isxdigit #"1") True "isxdigit 5"} + {test_fn_both_sides (fn _ => not (isxdigit #"!")) True "isxdigit 6"} + {test_fn_both_sides (fn _ => not (isxdigit #"#")) True "isxdigit 7"} + {test_fn_both_sides (fn _ => not (isxdigit #" ")) True "isxdigit 8"} + {test_fn_both_sides (fn _ => not (isxdigit #"\t")) True "isxdigit 9"} + {test_fn_both_sides (fn _ => not (isxdigit #"\n")) True "isxdigit 10"}
fun tolowers () : transaction page = return -
{[tolower #"A" = #"a"]}
-
{[tolower #"a" = #"a"]}
-
{[tolower (strsub "á" 0) = (strsub "á" 0)]}
-
{[tolower (strsub "Á" 0) = (strsub "á" 0)]}
-
{[tolower #"1" = #"1"]}
+ {test_fn_both_sides (fn _ => tolower #"A") #"a" "tolower 1"} + {test_fn_both_sides (fn _ => tolower #"a") #"a" "tolower 2"} + {test_fn_both_sides (fn _ => tolower (strsub "á" 0)) (strsub "á" 0) "tolower 3"} + {test_fn_both_sides (fn _ => tolower (strsub "Á" 0)) (strsub "á" 0) "tolower 4"} + {test_fn_both_sides (fn _ => tolower #"1") #"1" "tolower 5"}
fun touppers () : transaction page = return -
{[toupper #"A" = #"A"]}
-
{[toupper #"a" = #"A"]}
-
{[toupper (strsub "á" 0) = (strsub "Á" 0)]}
-
{[toupper (strsub "Á" 0) = (strsub "Á" 0)]}
-
{[toupper #"1" = #"1"]}
+ {test_fn_both_sides (fn _ => toupper #"A") #"A" "toupper 1"} + {test_fn_both_sides (fn _ => toupper #"a") #"A" "toupper 2"} + {test_fn_both_sides (fn _ => toupper (strsub "á" 0)) (strsub "Á" 0) "toupper 3"} + {test_fn_both_sides (fn _ => toupper (strsub "Á" 0)) (strsub "Á" 0) "toupper 4"} + {test_fn_both_sides (fn _ => toupper #"1") #"1" "toupper 5"}
fun ord_and_chrs () : transaction page = return -
{[chr (ord #"A") = #"A"]}
-
{[chr (ord #"a") = #"a"]}
-
{[chr (ord (strsub "á" 0)) = (strsub "á" 0)]}
-
{[chr (ord (strsub "Á" 0)) = (strsub "Á" 0)]}
-
{[chr (ord #"1") = #"1"]}
-
{[chr (ord #"\n") = #"\n"]}
-
{[chr (ord (strsub "が" 0)) = (strsub "が" 0)]}
-
{[chr (ord (strsub "漢" 0)) = (strsub "漢" 0)]}
-
{[chr (ord (strsub "カ" 0)) = (strsub "カ" 0)]}
+ {test_fn_both_sides (fn _ => chr (ord #"A")) #"A" "ord => chr 1"} + {test_fn_both_sides (fn _ => chr (ord #"a")) #"a" "ord => chr 2"} + {test_fn_both_sides (fn _ => chr (ord (strsub "á" 0))) (strsub "á" 0) "ord => chr 3"} + {test_fn_both_sides (fn _ => chr (ord (strsub "Á" 0))) (strsub "Á" 0) "ord => chr 4"} + {test_fn_both_sides (fn _ => chr (ord #"1")) #"1" "ord => chr 5"} + {test_fn_both_sides (fn _ => chr (ord #"\n")) #"\n" "ord => chr 6"} + {test_fn_both_sides (fn _ => chr (ord (strsub "が" 0))) (strsub "が" 0) "ord => chr 7"} + {test_fn_both_sides (fn _ => chr (ord (strsub "漢" 0))) (strsub "漢" 0) "ord => chr 8"} + {test_fn_both_sides (fn _ => chr (ord (strsub "カ" 0))) (strsub "カ" 0) "ord => chr 9"}
@@ -395,37 +410,77 @@ table t : { Id : int, Text : string } fun test_db () : transaction page = - dml (INSERT INTO t (Id, Text) VALUES({[1]}, {["abc"]})); + let + val s1 = "abc" + val s2 = "çãó" + val s3 = "が" + val s4 = "漢" + val s5 = "カ" + val s6 = "وظيفية" + + fun test_str_and_len n c expS expL = + test_fn_both_sides (fn _ => {S = c, L = strlen c}) {S=expS, L=expL} ("test_db " ^ (show n)) + + in + dml (INSERT INTO t (Id, Text) VALUES({[1]}, {[s1]})); t1 <- oneRow (SELECT t.Text FROM t WHERE t.Id = 1); - dml (INSERT INTO t (Id, Text) VALUES({[2]}, {["çãó"]})); + dml (INSERT INTO t (Id, Text) VALUES({[2]}, {[s2]})); t2 <- oneRow (SELECT t.Text FROM t WHERE t.Id = 2); - dml (INSERT INTO t (Id, Text) VALUES({[3]}, {["が"]})); + dml (INSERT INTO t (Id, Text) VALUES({[3]}, {[s3]})); t3 <- oneRow (SELECT t.Text FROM t WHERE t.Id = 3); - dml (INSERT INTO t (Id, Text) VALUES({[4]}, {["漢"]})); + dml (INSERT INTO t (Id, Text) VALUES({[4]}, {[s4]})); t4 <- oneRow (SELECT t.Text FROM t WHERE t.Id = 4); - dml (INSERT INTO t (Id, Text) VALUES({[5]}, {["カ"]})); + dml (INSERT INTO t (Id, Text) VALUES({[5]}, {[s5]})); t5 <- oneRow (SELECT t.Text FROM t WHERE t.Id = 5); - dml (INSERT INTO t (Id, Text) VALUES({[6]}, {["وظيفية"]})); + dml (INSERT INTO t (Id, Text) VALUES({[6]}, {[s6]})); t6 <- oneRow (SELECT t.Text FROM t WHERE t.Id = 6); return -
{[t1.T.Text]}
-
{[strlen t1.T.Text]}
-
{[t2.T.Text]}
-
{[strlen t2.T.Text]}
-
{[t3.T.Text]}
-
{[strlen t3.T.Text]}
-
{[t4.T.Text]}
-
{[strlen t4.T.Text]}
-
{[t5.T.Text]}
-
{[strlen t5.T.Text]}
-
{[t6.T.Text]}
-
{[strlen t6.T.Text]}
+ {test_str_and_len 1 t1.T.Text s1 (strlen s1)} + {test_str_and_len 2 t2.T.Text s2 (strlen s2)} + {test_str_and_len 3 t3.T.Text s3 (strlen s3)} + {test_str_and_len 4 t4.T.Text s4 (strlen s4)} + {test_str_and_len 5 t5.T.Text s5 (strlen s5)} + {test_str_and_len 6 t6.T.Text s6 (strlen s6)} + +
+ end + +fun index () : transaction page = + return + + substrings + strlens + strlenGens + strcats + strsubs + strsuffixs + strchrs + strindexs + strsindexs + strcspns + str1s + isalnums + isalphas + isblanks + iscntrls + isdigits + isgraphs + islowers + isprints + ispuncts + isspaces + isuppers + isxdigits + tolowers + touppers + ord_and_chrs + test_db diff --git a/tests/utf8.urp b/tests/utf8.urp index 9b3067af..25288aa8 100644 --- a/tests/utf8.urp +++ b/tests/utf8.urp @@ -2,4 +2,5 @@ database dbname=utf8 sql utf8.sql safeGet Utf8/test_db +$/option utf8 \ No newline at end of file -- cgit v1.2.3 From e452bb052b6c1afbaaa72efb653ea31561333866 Mon Sep 17 00:00:00 2001 From: fab Date: Tue, 11 Dec 2018 22:16:37 +0000 Subject: exhaustive testing brought to selenium. bug fix in isspace. useful function to test if char is <128 --- lib/js/urweb.js | 5 +- lib/ur/basis.urs | 1 + src/c/urweb.c | 5 ++ tests/utf8.py | 79 +++++++++++++++++--- tests/utf8.ur | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 292 insertions(+), 15 deletions(-) (limited to 'tests/utf8.py') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 00637172..2d39bc69 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -2122,9 +2122,7 @@ function isBlank(c) { } function isSpace(c) { var cp = ord(c); - if (cp == 10) - return true; - if (cp == 13) + if (cp >= 10 && cp <= 13) return true; if (cp == 133) return true; @@ -2790,6 +2788,7 @@ function isPrint(c) { function toLower(c) { var cp = ord(c); + if (cp == 304) return chr(105); else if (cp >= 7312 && cp <= 7354) diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs index c9d6556b..c893e65d 100644 --- a/lib/ur/basis.urs +++ b/lib/ur/basis.urs @@ -80,6 +80,7 @@ val ord : char -> int val chr : int -> char val iscodepoint : int -> bool +val issingle : char -> bool (** String operations *) diff --git a/src/c/urweb.c b/src/c/urweb.c index 96e30cec..78946872 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -4496,6 +4496,11 @@ uw_Basis_bool uw_Basis_iscodepoint (uw_context ctx, uw_Basis_int n) { return !!(n <= 0x10FFFF); } +uw_Basis_bool uw_Basis_issingle (uw_context ctx, uw_Basis_char c) { + (void)ctx; + return !!(c < 128); +} + uw_Basis_char uw_Basis_chr(uw_context ctx, uw_Basis_int n) { (void)ctx; uw_Basis_char ch = (uw_Basis_char)n; diff --git a/tests/utf8.py b/tests/utf8.py index 440bc82a..ac8df5c3 100644 --- a/tests/utf8.py +++ b/tests/utf8.py @@ -2,51 +2,51 @@ import unittest import base class Suite(base.Base): - def test_1(self): + def test_99(self): """Test case: substring (1)""" self.start('Utf8/substrings') - def test_2(self): + def test_98(self): """Test case: strlen (2)""" self.start('Utf8/strlens') - def test_3(self): + def test_97(self): """Test case: strlenGe (3)""" self.start('Utf8/strlenGens') - def test_4(self): + def test_96(self): """Test case: strcat (4)""" self.start('Utf8/strcats') - def test_5(self): + def test_95(self): """Test case: strsub (5)""" self.start('Utf8/strsubs') - def test_6(self): + def test_94(self): """Test case: strsuffix (6)""" self.start('Utf8/strsuffixs') - def test_7(self): + def test_93(self): """Test case: strchr (7)""" self.start('Utf8/strchrs') - def test_8(self): + def test_92(self): """Test case: strindex (8)""" self.start('Utf8/strindexs') - def test_9(self): + def test_91(self): """Test case: strindex (9)""" self.start('Utf8/strsindexs') - def test_10(self): + def test_90(self): """Test case: strcspn (10)""" self.start('Utf8/strcspns') - def test_11(self): + def test_89(self): """Test case: str1 (11)""" self.start('Utf8/str1s') - def test_12(self): + def test_88(self): """Test case: isalnum (12)""" self.start('Utf8/isalnums') @@ -105,3 +105,58 @@ class Suite(base.Base): def test_26 (self): """Test case: test_db (26) """ self.start('Utf8/test_db') + + def full_test (self, name): + + gap = 1000 + i = 0 + while (i + gap < 130000): + self.start('Utf8/' + name + '/' + str(i) + '/' + str(i + gap)) + errors = self.body_text() + self.assertEqual("", errors, errors) + i = i + gap + + + def test_1 (self): + """Test case: ftTolower """ + self.full_test("ftTolower") + + def test_2 (self): + """Test case: ftToupper """ + self.full_test("ftToupper") + + def test_3 (self): + """Test case: ftIsalpha """ + self.full_test("ftIsalpha") + + def test_4 (self): + """Test case: ftIsdigit """ + self.full_test("ftIsdigit") + + def test_5 (self): + """Test case: ftIsalnum """ + self.full_test("ftIsalnum") + + def test_6 (self): + """Test case: ftIsspace """ + self.full_test("ftIsspace") + + def test_7 (self): + """Test case: ftIsblank """ + self.full_test("ftIsblank") + + def test_8 (self): + """Test case: ftIsprint """ + self.full_test("ftIsprint") + + def test_9 (self): + """Test case: ftIsxdigit """ + self.full_test("ftIsxdigit") + + def test_10 (self): + """Test case: ftIsupper """ + self.full_test("ftIsupper") + + def test_11 (self): + """Test case: ftIslower """ + self.full_test("ftIslower") diff --git a/tests/utf8.ur b/tests/utf8.ur index c7aefd79..777bb141 100644 --- a/tests/utf8.ur +++ b/tests/utf8.ur @@ -1,4 +1,13 @@ +fun from_m_upto_n f m n = + if m < n then + + { f m } + { from_m_upto_n f (m + 1) n } + + else + + fun test_fn_both_sides [a ::: Type] (_ : eq a) (_ : show a) (f : unit -> a) (expected : a) (testname : string) : xbody =

Server side test: {[testname]}

@@ -31,6 +40,38 @@ fun test_fn_cside [a ::: Type] (_ : eq a) (_ : show a) (f : unit -> a) (expected
+ +fun test_fn_cside_ch (f : unit -> char) (expected : char) (testname : string) : xbody = + + + else + return

ERROR {[testname]}: {[msgErr]}

+ end}> + + + +fun test_fn_cside_b (f : unit -> bool) (expected : bool) (testname : string) : xbody = + + + else + return

ERROR {[testname]}: {[msgErr]}

+ end}> + + + + fun highencode () : transaction page = return @@ -553,6 +594,182 @@ fun test_db () : transaction page = end +and ftTolower (minCh : int) (maxCh : int) : transaction page = + let + fun test_chr (n : int) : xbody = + if iscodepoint n then + test_fn_cside_ch (fn _ => tolower (chr n)) (tolower (chr n)) + ("test chr " ^ (show n) ^ " : " ^ (show (chr n))) + else + + in + return + + { from_m_upto_n (fn n => test_chr n) minCh maxCh } + + + end + +and ftToupper (minCh : int) (maxCh : int) : transaction page = + let + fun test_chr (n : int) : xbody = + if iscodepoint n then + test_fn_cside_ch (fn _ => toupper (chr n)) (toupper (chr n)) + ("test chr " ^ (show n) ^ " : " ^ (show (chr n))) + else + + in + return + + { from_m_upto_n (fn n => test_chr n) minCh maxCh } + + + end + +and ftIsalpha (minCh : int) (maxCh : int) : transaction page = + let + fun test_chr (n : int) : xbody = + if iscodepoint n then + test_fn_cside_b (fn _ => isalpha (chr n)) (isalpha (chr n)) + ("test chr " ^ (show n) ^ " : " ^ (show (chr n))) + else + + in + return + + { from_m_upto_n (fn n => test_chr n) minCh maxCh } + + + end + +and ftIsdigit (minCh : int) (maxCh : int) : transaction page = + let + fun test_chr (n : int) : xbody = + if iscodepoint n then + test_fn_cside_b (fn _ => isdigit (chr n)) (isdigit (chr n)) + ("test chr " ^ (show n) ^ " : " ^ (show (chr n))) + else + + in + return + + { from_m_upto_n (fn n => test_chr n) minCh maxCh } + + + end + +and ftIsalnum (minCh : int) (maxCh : int) : transaction page = + let + fun test_chr (n : int) : xbody = + if iscodepoint n then + test_fn_cside_b (fn _ => isalnum (chr n)) (isalnum (chr n)) + ("test chr " ^ (show n) ^ " : " ^ (show (chr n))) + else + + in + return + + { from_m_upto_n (fn n => test_chr n) minCh maxCh } + + + end + +and ftIsspace (minCh : int) (maxCh : int) : transaction page = + let + fun test_chr (n : int) : xbody = + if iscodepoint n then + test_fn_cside_b (fn _ => isspace (chr n)) (isspace (chr n)) + ("test chr " ^ (show n) ^ " : " ^ (show (chr n))) + else + + in + return + + { from_m_upto_n (fn n => test_chr n) minCh maxCh } + + + end + +and ftIsblank (minCh : int) (maxCh : int) : transaction page = + let + fun test_chr (n : int) : xbody = + if iscodepoint n then + test_fn_cside_b (fn _ => isblank (chr n)) (isblank (chr n)) + ("test chr " ^ (show n) ^ " : " ^ (show (chr n))) + else + + in + return + + { from_m_upto_n (fn n => test_chr n) minCh maxCh } + + + end + +and ftIsprint (minCh : int) (maxCh : int) : transaction page = + let + fun test_chr (n : int) : xbody = + if iscodepoint n then + test_fn_cside_b (fn _ => isprint (chr n)) (isprint (chr n)) + ("test chr " ^ (show n) ^ " : " ^ (show (chr n))) + else + + in + return + + { from_m_upto_n (fn n => test_chr n) minCh maxCh } + + + end + +and ftIsxdigit (minCh : int) (maxCh : int) : transaction page = + let + fun test_chr (n : int) : xbody = + if iscodepoint n then + test_fn_cside_b (fn _ => isxdigit (chr n)) (isxdigit (chr n)) + ("test chr " ^ (show n) ^ " : " ^ (show (chr n))) + else + + in + return + + { from_m_upto_n (fn n => test_chr n) minCh maxCh } + + + end + +and ftIsupper (minCh : int) (maxCh : int) : transaction page = + let + fun test_chr (n : int) : xbody = + if iscodepoint n then + test_fn_cside_b (fn _ => isupper (chr n)) (isupper (chr n)) + ("test chr " ^ (show n) ^ " : " ^ (show (chr n))) + else + + in + return + + { from_m_upto_n (fn n => test_chr n) minCh maxCh } + + + end + +and ftIslower (minCh : int) (maxCh : int) : transaction page = + let + fun test_chr (n : int) : xbody = + if iscodepoint n then + test_fn_cside_b (fn _ => islower (chr n)) (islower (chr n)) + ("test chr " ^ (show n) ^ " : " ^ (show (chr n))) + else + + in + return + + { from_m_upto_n (fn n => test_chr n) minCh maxCh } + + + end + fun index () : transaction page = return -- cgit v1.2.3 From db41db44f8693d6d1b740eb0b55ef84a4245b576 Mon Sep 17 00:00:00 2001 From: fab Date: Wed, 12 Dec 2018 21:29:05 +0000 Subject: tidy unit tests --- tests/utf8.py | 112 ++++++++++++++++++++++++++++++++-------------------------- tests/utf8.ur | 20 +++-------- 2 files changed, 66 insertions(+), 66 deletions(-) (limited to 'tests/utf8.py') diff --git a/tests/utf8.py b/tests/utf8.py index ac8df5c3..6036fa12 100644 --- a/tests/utf8.py +++ b/tests/utf8.py @@ -2,109 +2,119 @@ import unittest import base class Suite(base.Base): - def test_99(self): + + def no_falses(self, name): + self.start('Utf8/' + name) + + elems = self.driver.find_elements_by_xpath('//pre') + + self.assertNotEqual(0, len(elems)) + for e in elems: + self.assertEqual("True", e.text) + + def test_1(self): """Test case: substring (1)""" - self.start('Utf8/substrings') - - def test_98(self): + self.no_falses('substrings') + + def test_2(self): """Test case: strlen (2)""" - self.start('Utf8/strlens') + self.no_falses('strlens') - def test_97(self): + def test_3(self): """Test case: strlenGe (3)""" - self.start('Utf8/strlenGens') + self.no_falses('strlenGens') - def test_96(self): + def test_4(self): """Test case: strcat (4)""" - self.start('Utf8/strcats') + self.no_falses('strcats') - def test_95(self): + def test_5(self): """Test case: strsub (5)""" - self.start('Utf8/strsubs') + self.no_falses('strsubs') - def test_94(self): + def test_6(self): """Test case: strsuffix (6)""" - self.start('Utf8/strsuffixs') + self.no_falses('strsuffixs') - def test_93(self): + def test_7(self): """Test case: strchr (7)""" - self.start('Utf8/strchrs') + self.no_falses('strchrs') - def test_92(self): + def test_8(self): """Test case: strindex (8)""" - self.start('Utf8/strindexs') + self.no_falses('strindexs') - def test_91(self): + def test_9(self): """Test case: strindex (9)""" - self.start('Utf8/strsindexs') + self.no_falses('strsindexs') - def test_90(self): + def test_10(self): """Test case: strcspn (10)""" - self.start('Utf8/strcspns') + self.no_falses('strcspns') - def test_89(self): + def test_11(self): """Test case: str1 (11)""" - self.start('Utf8/str1s') + self.no_falses('str1s') - def test_88(self): + def test_12(self): """Test case: isalnum (12)""" - self.start('Utf8/isalnums') + self.no_falses('isalnums') def test_13(self): """Test case: isalpha (13)""" - self.start('Utf8/isalphas') + self.no_falses('isalphas') def test_14(self): """Test case: isblank (14)""" - self.start('Utf8/isblanks') + self.no_falses('isblanks') def test_15(self): """Test case: iscntrl (15)""" - self.start('Utf8/iscntrls') + self.no_falses('iscntrls') def test_16(self): """Test case: isdigit (16)""" - self.start('Utf8/isdigits') + self.no_falses('isdigits') def test_17(self): """Test case: isgraph (17)""" - self.start('Utf8/isgraphs') + self.no_falses('isgraphs') def test_18(self): """Test case: islower (18)""" - self.start('Utf8/islowers') + self.no_falses('islowers') def test_19(self): """Test case: isprint (19)""" - self.start('Utf8/isprints') + self.no_falses('isprints') def test_20(self): """Test case: ispunct (20)""" - self.start('Utf8/ispuncts') + self.no_falses('ispuncts') def test_21(self): """Test case: isspace (21)""" - self.start('Utf8/isspaces') + self.no_falses('isspaces') def test_22(self): """Test case: isupper (22)""" - self.start('Utf8/isuppers') + self.no_falses('isuppers') def test_23(self): """Test case: isxdigit (23)""" - self.start('Utf8/isxdigits') + self.no_falses('isxdigits') def test_24(self): """Test case: toupper (24)""" - self.start('Utf8/touppers') + self.no_falses('touppers') def test_25(self): """Test case: ord (25)""" - self.start('Utf8/ord_and_chrs') + self.no_falses('ord_and_chrs') def test_26 (self): """Test case: test_db (26) """ - self.start('Utf8/test_db') + self.no_falses('test_db') def full_test (self, name): @@ -117,46 +127,48 @@ class Suite(base.Base): i = i + gap - def test_1 (self): + def test_89 (self): """Test case: ftTolower """ self.full_test("ftTolower") - def test_2 (self): + def test_90 (self): """Test case: ftToupper """ self.full_test("ftToupper") - def test_3 (self): + def test_91 (self): """Test case: ftIsalpha """ self.full_test("ftIsalpha") - def test_4 (self): + def test_92 (self): """Test case: ftIsdigit """ self.full_test("ftIsdigit") - def test_5 (self): + def test_93 (self): """Test case: ftIsalnum """ self.full_test("ftIsalnum") - def test_6 (self): + def test_94 (self): """Test case: ftIsspace """ self.full_test("ftIsspace") - def test_7 (self): + def test_95 (self): """Test case: ftIsblank """ self.full_test("ftIsblank") - def test_8 (self): + def test_96 (self): """Test case: ftIsprint """ self.full_test("ftIsprint") - def test_9 (self): + def test_97 (self): """Test case: ftIsxdigit """ self.full_test("ftIsxdigit") - def test_10 (self): + def test_98 (self): """Test case: ftIsupper """ self.full_test("ftIsupper") - def test_11 (self): + def test_99 (self): """Test case: ftIslower """ self.full_test("ftIslower") + ''' + ''' diff --git a/tests/utf8.ur b/tests/utf8.ur index 777bb141..4a89c22b 100644 --- a/tests/utf8.ur +++ b/tests/utf8.ur @@ -11,32 +11,20 @@ fun from_m_upto_n f m n = fun test_fn_both_sides [a ::: Type] (_ : eq a) (_ : show a) (f : unit -> a) (expected : a) (testname : string) : xbody =

Server side test: {[testname]}

-
{[assert (f () = expected) "False" testname "True" ]}
-

Client side test: {[testname]}

{[r]}
- end}> +
{[show (f () = expected)]}
+

Client side test: {[testname]}

{[show (f () = expected)]}
}> fun test_fn_sside [a ::: Type] (_ : eq a) (_ : show a) (f : unit -> a) (expected : a) (testname : string) : xbody =

Server side test: {[testname]}

-
{[assert (f () = expected) "False" testname "True" ]}
+
{[show (f () = expected)]}
fun test_fn_cside [a ::: Type] (_ : eq a) (_ : show a) (f : unit -> a) (expected : a) (testname : string) : xbody = -

Client side test: {[testname]}

{[r]}
- end}> +

Client side test: {[testname]}

{[show (f () = expected)]}
}>
-- cgit v1.2.3