diff options
author | Brody Kenrick <user.fake@server.userfake> | 2013-12-05 06:56:54 (GMT) |
---|---|---|
committer | Brody Kenrick <user.fake@server.userfake> | 2013-12-05 07:28:40 (GMT) |
commit | 0717c67c9fa894ecb08dc5de281753a00922d1ee (patch) | |
tree | 77baf10b4244a189f1212f3affee08a82a999013 /testdata/scad | |
parent | d3b82dcac0cbd6bb46c3236d1183f84b76b44748 (diff) |
Unicode support for strings
Add suport for using unicode strings in .scad files. Support iterating
across them/accessing them via [] and searching.
--------
Add GLIB (to build for test and normal build -- both with installed and
built locally development files).
Add support for unicode chars to length and search builtin functions and
[] for strings.
Added unicode testing functions.
Ad GLIB to library info page.
Diffstat (limited to 'testdata/scad')
-rw-r--r-- | testdata/scad/misc/search-tests-unicode.scad | 116 | ||||
-rw-r--r-- | testdata/scad/misc/string-unicode.scad | 36 |
2 files changed, 152 insertions, 0 deletions
diff --git a/testdata/scad/misc/search-tests-unicode.scad b/testdata/scad/misc/search-tests-unicode.scad new file mode 100644 index 0000000..d863eff --- /dev/null +++ b/testdata/scad/misc/search-tests-unicode.scad @@ -0,0 +1,116 @@ +//Test search with unicode strings + +//Helper function that pretty prints our search test +//Expected result is checked against execution of a search() invocation and OK/FAIL is indicated +module test_search_and_echo( exp_res, search_to_find, search_to_search, search_up_to_num_matches = undef) +{ + if(undef != search_up_to_num_matches) + { + assign( test_res = search(search_to_find, search_to_search, search_up_to_num_matches) ) + echo(str("Expect ", exp_res, " for search(", search_to_find, ", ", search_to_search, ", ", search_up_to_num_matches, ")=", test_res, ". ", (exp_res == test_res)?"OK":"FAIL" )); + } + else + { + assign( test_res = search(search_to_find, search_to_search) ) + echo(str("Expect ", exp_res, " for search(", search_to_find, ", ", search_to_search, ")=", test_res, ". ", (exp_res == test_res)?"OK":"FAIL" )); + } +} + + +//"Normal" text for comparison +echo ("----- Lookup of 1 byte into 1 byte"); +//Hits - up_to_count 1 +test_search_and_echo( [0], "a","aaaa" ); +test_search_and_echo( [0], "a","aaaa",1 ); +test_search_and_echo( [0,0], "aa","aaaa" ); +test_search_and_echo( [0,0], "aa","aaaa",1 ); + + +//Hits - up to count 1+ (incl 0 == all) +test_search_and_echo( [[0,1,2,3]] , "a","aaaa",0 ); +test_search_and_echo( [[0,1]], "a","aaaa",2 ); +test_search_and_echo( [[0,1,2]], "a","aaaa",3 ); +test_search_and_echo( [[0,1,2,3]] , "a","aaaa",4 ); +test_search_and_echo( [[0,1,2,3],[0,1,2,3]] , "aa","aaaa",0 ); +//Misses +test_search_and_echo( [], "b","aaaa" ); +test_search_and_echo( [], "b","aaaa",1 ); +test_search_and_echo( [[]], "b","aaaa",0 ); +test_search_and_echo( [[]], "b","aaaa",2 ); + +test_search_and_echo( [], "bb","aaaa" ); +test_search_and_echo( [], "bb","aaaa",1 ); +test_search_and_echo( [[],[]], "bb","aaaa",0 ); +test_search_and_echo( [[],[]], "bb","aaaa",2 ); +//Miss - empties +test_search_and_echo( [], "","aaaa" ); +test_search_and_echo( [], "","" ); +test_search_and_echo( [], "a","" ); + + +//Unicode tests +echo ("----- Lookup of multi-byte into 1 byte"); +test_search_and_echo( [], "Π","aaaa" ); +test_search_and_echo( [], "π‘","aaaa" ); +test_search_and_echo( [[]], "Π","aaaa",0 ); +test_search_and_echo( [[]], "π‘","aaaa",0 ); + +test_search_and_echo( [], "ΠΠ","aaaa" ); +test_search_and_echo( [], "π‘π‘","aaaa" ); +test_search_and_echo( [[],[]], "ΠΠ","aaaa",0 ); +test_search_and_echo( [[],[]], "π‘π‘","aaaa",0 ); + +echo ("----- Lookup of 1-byte into multi-byte"); +test_search_and_echo( [] , "a","ΠΠΠΠ" ); +test_search_and_echo( [] , "a","π‘π‘π‘π‘" ); +test_search_and_echo( [] , "a","ΠΠΠΠ",1 ); + +test_search_and_echo( [[]] , "a","π‘π‘π‘π‘",0 ); +test_search_and_echo( [[]] , "a","π‘π‘π‘π‘",2 ); + +echo ("----- Lookup of 1-byte into mixed multi-byte"); +test_search_and_echo( [0], "a","aΠaΠaΠaΠa" ); +test_search_and_echo( [0], "a","aπ‘aπ‘aπ‘aπ‘a" ); +test_search_and_echo( [0], "a","aπ‘Ππ‘aπ‘Ππ‘a" ); + +test_search_and_echo( [[0,2,4,6,8]], "a","aΠaΠaΠaΠa",0 ); +test_search_and_echo( [[0,2,4,6,8]], "a","aπ‘aπ‘aπ‘aπ‘a", 0 ); +test_search_and_echo( [[0,4,8]] , "a","aπ‘Ππ‘aπ‘Ππ‘a", 0 ); + +echo ("----- Lookup of 2-byte into 2-byte"); +test_search_and_echo( [0] , "Π","ΠΠΠΠ" ); +test_search_and_echo( [[0,1,2,3]] , "Π","ΠΠΠΠ",0 ); + +echo ("----- Lookup of 2-byte into 4-byte"); +test_search_and_echo( [] , "Π","π‘π‘π‘π‘" ); + +echo ("----- Lookup of 4-byte into 4-byte"); +test_search_and_echo( [0] , "π‘","π‘π‘π‘π‘" ); +test_search_and_echo( [[0,1,2,3]], "π‘","π‘π‘π‘π‘",0 ); + +echo ("----- Lookup of 4-byte into 2-byte"); +test_search_and_echo( [] , "π‘","ΠΠΠΠ" ); + +echo ("----- Lookup of 2-byte into mixed multi-byte"); +test_search_and_echo( [1] , "Π","aΠaΠaΠaΠa",1 ); +test_search_and_echo( [] , "Π","aπ‘aπ‘aπ‘aπ‘a", 1 ); +test_search_and_echo( [2] , "Π","aπ‘Ππ‘aπ‘Ππ‘a", 1 ); + +test_search_and_echo( [[1,3,5,7]] , "Π","aΠaΠaΠaΠa",0 ); +test_search_and_echo( [[]] , "Π","aπ‘aπ‘aπ‘aπ‘a", 0 ); +test_search_and_echo( [[2,6]] , "Π","aπ‘Ππ‘aπ‘Ππ‘a", 0 ); + +echo ("----- Lookup of 4-byte into mixed multi-byte"); +test_search_and_echo( [] , "π‘","aΠaΠaΠaΠa",1 ); +test_search_and_echo( [1] , "π‘","aπ‘aπ‘aπ‘aπ‘a", 1 ); + +test_search_and_echo( [[]] , "π‘","aΠaΠaΠaΠa",0 ); +test_search_and_echo( [[1,3,5,7]] , "π‘","aπ‘aπ‘aπ‘aπ‘a", 0 ); +test_search_and_echo( [[1,3,5,7]] , "π‘","aπ‘Ππ‘aπ‘Ππ‘a", 0 ); + +echo ("----- Lookup of mixed multi-byte into mixed multi-byte"); +test_search_and_echo( [[0,2,4,6,8],[1,3,5,7],[]], "aΠπ‘","aΠaΠaΠaΠa",0 ); +test_search_and_echo( [[0,2,4,6,8],[],[1,3,5,7]], "aΠπ‘","aπ‘aπ‘aπ‘aπ‘a", 0 ); +test_search_and_echo( [[0,4,8],[2,6],[1,3,5,7]] , "aΠπ‘","aπ‘Ππ‘aπ‘Ππ‘a", 0 ); +test_search_and_echo( [[1,3,5,7],[0,4,8],[2,6]] , "π‘aΠ","aπ‘Ππ‘aπ‘Ππ‘a", 0 ); + diff --git a/testdata/scad/misc/string-unicode.scad b/testdata/scad/misc/string-unicode.scad new file mode 100644 index 0000000..d8e3e5c --- /dev/null +++ b/testdata/scad/misc/string-unicode.scad @@ -0,0 +1,36 @@ +//Test how well arrays of unicode string are accessed. + +texts_array = [ +"DEADBEEF", +"ΠΠ΅Π½ΠΈΠ²ΡΠΉ ΡΡΠΆΠΈΠΉ ΠΊΠΎΡ", +"ΩΨ³ΩΩ Ψ§ΩΨ²ΩΨ¬Ψ¨ΩΩ Ψ§ΩΩΨ·", +"ζΆζ°ηε§θ²", +"Àâü ΓΓΓ Γ", +"πππππ
πππππππππππ", +"β β β β β
β β β β β β β β β β ", +"π‘π±ππ", +]; + +text_2bytes = "ΠΠ΅Π½ΠΈΠ²ΡΠΉ ΡΡΠΆΠΈΠΉ ΠΊΠΎΡ"; +text_4bytes = "π‘π±ππ"; + + +//Test all the normal accesses +for (text_array_idx = [0:(len(texts_array)-1)]) +{ + echo( "[", text_array_idx, "] = ", texts_array[text_array_idx], " of len=", len(texts_array[text_array_idx]), ":" ); + for (text_idx = [0:(len(texts_array[text_array_idx])-1)]) + { + echo( " [", text_idx, ,"]=", texts_array[text_array_idx][text_idx] ); + } +} + +//Test one past the last element of (x-byte unicode). This will be one past the length but inside the char length of the string +echo( "Past end of unicode only 2-byte ", text_2bytes[len(text_2bytes)] ); +echo( "Past end of unicode only 4-byte ", text_4bytes[len(text_4bytes)] ); + +//Test past the last element of (x-byte unicode). Outside both lengths. +echo( "Past end of both 2-byte ", text_2bytes[ len(text_2bytes) * 2 ] ); +echo( "Past end of both 4-byte ", text_4bytes[ len(text_4bytes) * 4 ] ); + + |