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.ur | 431 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 431 insertions(+) create mode 100644 tests/utf8.ur (limited to 'tests/utf8.ur') diff --git a/tests/utf8.ur b/tests/utf8.ur new file mode 100644 index 00000000..0dedc726 --- /dev/null +++ b/tests/utf8.ur @@ -0,0 +1,431 @@ +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 strlens () : transaction page = return + +
{[strlen "abc"]}
+
{[strlen "çbc"]}
+
{[strlen "çãc"]}
+
{[strlen "çãó"]}
+
{[strlen "ç"]}
+
{[strlen "c"]}
+
{[strlen ""]}
+
{[strlen "が"]}
+
{[strlen "漢"]}
+
{[strlen "カ"]}
+
{[strlen "وظيفية"]}
+
{[strlen "函數"]}
+
{[strlen "Функциональное"]}
+ +
+ +fun strlenGens () : transaction page = return + +
{[strlenGe "" 1]}
+
{[strlenGe "" 0]}
+
{[strlenGe "aba" 4]}
+
{[strlenGe "aba" 3]}
+
{[strlenGe "aba" 2]}
+
{[strlenGe "áçà" 4]}
+
{[strlenGe "áçà" 3]}
+
{[strlenGe "áçà" 2]}
+ + +
+ +fun strcats () : transaction page = + let + fun catAndLen a b = + +
{[strcat a b]}
+
{[strlen (strcat a b)]}
+
+ in + return + + {catAndLen "" ""} + {catAndLen "aa" "bb"} + {catAndLen "" "bb"} + {catAndLen "aa" ""} + {catAndLen "àà" "áá"} + {catAndLen "" "áá"} + {catAndLen "àà" ""} + + +end + +fun strsubs () : transaction page = + return + +
{[strsub "abàç" 0]}
+
{[strsub "abàç" 1]}
+
{[strsub "abàç" 2]}
+
{[strsub "abàç" 3]}
+ +
+ +fun strsuffixs () : transaction page = + return + +
{[strsuffix "abàç" 0]}
+
{[strsuffix "abàç" 1]}
+
{[strsuffix "abàç" 2]}
+
{[strsuffix "abàç" 3]}
+ +
+ +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 + +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 + +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 + +fun strcspns () : transaction page = + return + +
{[strcspn "abàç" ""]}
+
{[strcspn "abàç" "abàç"]}
+
{[strcspn "abàç" "a"]}
+
{[strcspn "abàç" "bàç"]}
+
{[strcspn "abàç" "àç"]}
+
{[strcspn "abàç" "ç"]}
+ +
+ +fun str1s () : transaction page = return + +
{[str1 #"a"]}
+
{[str1 (strsub "à" 0)]}
+
{[str1 (strsub "aá" 1)]}
+ +
+ +fun isalnums () : transaction page = return + +
{[isalnum #"a"]}
+
{[isalnum (strsub "à" 0)]}
+
{[isalnum #"A"]}
+
{[isalnum (strsub "À" 0)]}
+
{[isalnum #"1"]}
+
{[not (isalnum #"!")]}
+
{[not (isalnum #"#")]}
+
{[not (isalnum #" ")]}
+ +
+ +fun isalphas () : transaction page = return + +
{[isalpha #"a"]}
+
{[isalpha (strsub "à" 0)]}
+
{[isalpha #"A"]}
+
{[isalpha (strsub "À" 0)]}
+
{[not (isalpha #"1")]}
+
{[not (isalpha #"!")]}
+
{[not (isalpha #"#")]}
+
{[not (isalpha #" ")]}
+ +
+ +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")]}
+ +
+ +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"]}
+ +
+ +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")]}
+ +
+ +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")]}
+ +
+ +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")]}
+ +
+ +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")]}
+ +
+ +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")]}
+ +
+ +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"]}
+ +
+ +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")]}
+ +
+ +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")]}
+ +
+ +fun tolowers () : transaction page = + return + +
{[tolower #"A" = #"a"]}
+
{[tolower #"a" = #"a"]}
+
{[tolower (strsub "á" 0) = (strsub "á" 0)]}
+
{[tolower (strsub "Á" 0) = (strsub "á" 0)]}
+
{[tolower #"1" = #"1"]}
+ +
+ +fun touppers () : transaction page = + return + +
{[toupper #"A" = #"A"]}
+
{[toupper #"a" = #"A"]}
+
{[toupper (strsub "á" 0) = (strsub "Á" 0)]}
+
{[toupper (strsub "Á" 0) = (strsub "Á" 0)]}
+
{[toupper #"1" = #"1"]}
+ +
+ +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)]}
+ +
+ +table t : { Id : int, Text : string } + + +fun test_db () : transaction page = + dml (INSERT INTO t (Id, Text) VALUES({[1]}, {["abc"]})); + t1 <- oneRow (SELECT t.Text FROM t WHERE t.Id = 1); + + dml (INSERT INTO t (Id, Text) VALUES({[2]}, {["çãó"]})); + t2 <- oneRow (SELECT t.Text FROM t WHERE t.Id = 2); + + dml (INSERT INTO t (Id, Text) VALUES({[3]}, {["が"]})); + t3 <- oneRow (SELECT t.Text FROM t WHERE t.Id = 3); + + dml (INSERT INTO t (Id, Text) VALUES({[4]}, {["漢"]})); + t4 <- oneRow (SELECT t.Text FROM t WHERE t.Id = 4); + + dml (INSERT INTO t (Id, Text) VALUES({[5]}, {["カ"]})); + t5 <- oneRow (SELECT t.Text FROM t WHERE t.Id = 5); + + dml (INSERT INTO t (Id, Text) VALUES({[6]}, {["وظيفية"]})); + 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]}
+ +
-- cgit v1.2.3