Unit tests and refactoring for ascii and latin1
parent
b32276d1da
commit
c4d6201b77
|
@ -0,0 +1,9 @@
|
||||||
|
USING: io.encodings.string io.encodings.ascii tools.test strings arrays ;
|
||||||
|
IN: io.encodings.ascii.tests
|
||||||
|
|
||||||
|
[ B{ CHAR: f CHAR: o CHAR: o } ] [ "foo" ascii encode ] unit-test
|
||||||
|
[ { 128 } >string ascii encode ] must-fail
|
||||||
|
[ B{ 127 } ] [ { 127 } ascii encode ] unit-test
|
||||||
|
|
||||||
|
[ "bar" ] [ "bar" ascii decode ] unit-test
|
||||||
|
[ { CHAR: b HEX: fffd CHAR: r } ] [ { CHAR: b 233 CHAR: r } ascii decode >array ] unit-test
|
|
@ -3,13 +3,16 @@
|
||||||
USING: io io.encodings strings kernel math sequences byte-arrays io.encodings ;
|
USING: io io.encodings strings kernel math sequences byte-arrays io.encodings ;
|
||||||
IN: io.encodings.ascii
|
IN: io.encodings.ascii
|
||||||
|
|
||||||
: encode-check<= ( string stream max -- )
|
: encode-check< ( string stream max -- )
|
||||||
[ pick <= [ encode-error ] [ stream-write1 ] if ] 2curry each ;
|
[ pick <= [ encode-error ] [ stream-write1 ] if ] 2curry each ;
|
||||||
|
|
||||||
|
: push-if< ( sbuf character max -- )
|
||||||
|
over <= [ drop HEX: fffd ] when swap push ;
|
||||||
|
|
||||||
TUPLE: ascii ;
|
TUPLE: ascii ;
|
||||||
|
|
||||||
M: ascii stream-write-encoded ( string stream encoding -- )
|
M: ascii stream-write-encoded ( string stream encoding -- )
|
||||||
drop 127 encode-check<= ;
|
drop 128 encode-check< ;
|
||||||
|
|
||||||
M: ascii decode-step
|
M: ascii decode-step
|
||||||
drop dup 128 >= [ decode-error ] [ swap push ] if ;
|
drop 128 push-if< ;
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
USING: io.encodings.string io.encodings.latin1 tools.test strings arrays ;
|
||||||
|
IN: io.encodings.latin1.tests
|
||||||
|
|
||||||
|
[ B{ CHAR: f CHAR: o CHAR: o } ] [ "foo" latin1 encode ] unit-test
|
||||||
|
[ { 256 } >string latin1 encode ] must-fail
|
||||||
|
[ B{ 255 } ] [ { 255 } latin1 encode ] unit-test
|
||||||
|
|
||||||
|
[ "bar" ] [ "bar" latin1 decode ] unit-test
|
||||||
|
[ { CHAR: b 233 CHAR: r } ] [ { CHAR: b 233 CHAR: r } latin1 decode >array ] unit-test
|
|
@ -6,7 +6,4 @@ IN: io.encodings.latin1
|
||||||
TUPLE: latin1 ;
|
TUPLE: latin1 ;
|
||||||
|
|
||||||
M: latin1 stream-write-encoded
|
M: latin1 stream-write-encoded
|
||||||
drop 255 encode-check<= ;
|
drop 256 encode-check< ;
|
||||||
|
|
||||||
M: latin1 decode-step
|
|
||||||
drop dup 256 >= [ decode-error ] [ swap push ] if ;
|
|
||||||
|
|
Loading…
Reference in New Issue