]> gitweb.factorcode.org Git - factor.git/commitdiff
Add more unit tests for code-point-length
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 19 Mar 2009 22:36:49 +0000 (17:36 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 19 Mar 2009 22:36:49 +0000 (17:36 -0500)
core/io/encodings/utf8/utf8-tests.factor
core/io/encodings/utf8/utf8.factor

index e30e9be0d0e9c0d2f36ab53d60bc4a4310ae1bfb..6cd3ee803305efbb5aa9c2759b0ef1ab9c460c19 100755 (executable)
@@ -1,5 +1,5 @@
 USING: io.encodings.utf8 tools.test io.encodings.string strings arrays
-bootstrap.unicode ;
+bootstrap.unicode kernel sequences ;
 IN: io.encodings.utf8.tests
 
 : decode-utf8-w/stream ( array -- newarray )
@@ -25,3 +25,7 @@ IN: io.encodings.utf8.tests
 
 [ 3 ] [ 1 "日本語" >utf8-index ] unit-test
 [ 3 ] [ 9 "日本語" utf8-index> ] unit-test
+
+[ 3 ] [ 2 "lápis" >utf8-index ] unit-test
+
+[ V{ } ] [ 100000 [ [ code-point-length ] [ 1string utf8 encode length ] bi = not ] filter ] unit-test
index aca36c8551bfa7df9dd715e2c4fafaa3f8b651d2..83ecc33b8ed5544fd5f5bae4bde8a4681def43ab 100755 (executable)
@@ -73,7 +73,7 @@ M: utf8 encode-char
 PRIVATE>
 
 : code-point-length ( n -- x )
-    log2 {
+    next-power-of-2 log2 {
         { [ dup 0 7 between? ] [ 1 ] }
         { [ dup 8 11 between? ] [ 2 ] }
         { [ dup 12 16 between? ] [ 3 ] }
@@ -87,4 +87,4 @@ PRIVATE>
     code-point-offsets [ <= ] with find drop ;
 
 : >utf8-index ( n string -- n' )
-    code-point-offsets nth ;
\ No newline at end of file
+    code-point-offsets nth ;