]> gitweb.factorcode.org Git - factor.git/commitdiff
punycode: simplify decode-digit add test cases.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 26 Dec 2021 21:13:58 +0000 (13:13 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 26 Dec 2021 21:13:58 +0000 (13:13 -0800)
extra/punycode/punycode-tests.factor
extra/punycode/punycode.factor

index 950ac86df836810196fa10e3d51d81b76e677fa2..e8ba19939e65423cc4904155a87b30bf72b44bc2 100644 (file)
@@ -1,6 +1,13 @@
 
 USING: arrays assocs fry kernel linked-assocs punycode
-tools.test urls ;
+punycode.private tools.test urls ;
+
+{ 0 } [ CHAR: A decode-digit ] unit-test
+{ 1 } [ CHAR: B decode-digit ] unit-test
+{ 25 } [ CHAR: Z decode-digit ] unit-test
+{ 26 } [ CHAR: 0 decode-digit ] unit-test
+{ 35 } [ CHAR: 9 decode-digit ] unit-test
+[ CHAR: & decode-digit ] [ invalid-digit? ] must-fail-with
 
 {
     ! Wikipedia Examples
index f3a7c73e06a458eea62992b0cae93d5fa83a0ddb..bd3069060e0942219a33c0a2a8379160a60c460b 100644 (file)
@@ -107,11 +107,11 @@ PRIVATE>
 
 ERROR: invalid-digit char ;
 
-:: decode-digit ( ch -- digit )
+: decode-digit ( ch -- digit )
     {
-        { [ ch CHAR: A CHAR: Z between? ] [ ch CHAR: A - ] }
-        { [ ch CHAR: 0 CHAR: 9 between? ] [ ch CHAR: 0 26 - - ] }
-        [ ch invalid-digit ]
+        { [ dup LETTER? ] [ CHAR: A - ] }
+        { [ dup digit? ] [ CHAR: 0 26 - - ] }
+        [ invalid-digit ]
     } cond ;
 
 :: decode-delta ( extended extpos! bias -- extpos' delta )