From ef5da197863828edbd458cb88a5d98dbdb761f57 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sun, 26 Dec 2021 13:13:58 -0800 Subject: [PATCH] punycode: simplify decode-digit add test cases. --- extra/punycode/punycode-tests.factor | 9 ++++++++- extra/punycode/punycode.factor | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/extra/punycode/punycode-tests.factor b/extra/punycode/punycode-tests.factor index 950ac86df8..e8ba19939e 100644 --- a/extra/punycode/punycode-tests.factor +++ b/extra/punycode/punycode-tests.factor @@ -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 diff --git a/extra/punycode/punycode.factor b/extra/punycode/punycode.factor index f3a7c73e06..bd3069060e 100644 --- a/extra/punycode/punycode.factor +++ b/extra/punycode/punycode.factor @@ -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 ) -- 2.34.1