2008-09-11 01:20:06 -04:00
|
|
|
USING: continuations kernel math math.order namespaces make
|
|
|
|
strings strings.private sbufs tools.test sequences vectors
|
|
|
|
arrays memory prettyprint io.streams.null ;
|
2008-03-01 17:00:45 -05:00
|
|
|
IN: strings.tests
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
[ CHAR: b ] [ 1 >bignum "abc" nth ] unit-test
|
|
|
|
|
2008-02-06 14:47:19 -05:00
|
|
|
[ ] [ 10 [ [ -1000000 <sbuf> ] ignore-errors ] times ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
[ "abc" ] [ [ "a" "b" "c" ] [ [ % ] each ] "" make ] unit-test
|
|
|
|
|
|
|
|
[ "abc" ] [ "ab" "c" append ] unit-test
|
|
|
|
[ "abc" ] [ "a" "b" "c" 3append ] unit-test
|
|
|
|
|
|
|
|
[ 3 ] [ "a" "hola" start ] unit-test
|
|
|
|
[ f ] [ "x" "hola" start ] unit-test
|
|
|
|
[ 0 ] [ "" "a" start ] unit-test
|
|
|
|
[ 0 ] [ "" "" start ] unit-test
|
|
|
|
[ 0 ] [ "hola" "hola" start ] unit-test
|
|
|
|
[ 1 ] [ "ol" "hola" start ] unit-test
|
|
|
|
[ f ] [ "amigo" "hola" start ] unit-test
|
|
|
|
[ f ] [ "holaa" "hola" start ] unit-test
|
|
|
|
|
|
|
|
[ "Beginning" ] [ "Beginning and end" 9 head ] unit-test
|
|
|
|
|
|
|
|
[ f ] [ CHAR: I "team" member? ] unit-test
|
|
|
|
[ t ] [ "ea" "team" subseq? ] unit-test
|
|
|
|
[ f ] [ "actore" "Factor" subseq? ] unit-test
|
|
|
|
|
|
|
|
[ "end" ] [ "Beginning and end" 14 tail ] unit-test
|
|
|
|
|
2008-02-26 18:33:48 -05:00
|
|
|
[ t ] [ "abc" "abd" before? ] unit-test
|
|
|
|
[ t ] [ "z" "abd" after? ] unit-test
|
2008-04-26 19:45:03 -04:00
|
|
|
[ "abc" ] [ "abc" "abd" min ] unit-test
|
|
|
|
[ "z" ] [ "z" "abd" max ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-06 14:47:19 -05:00
|
|
|
[ 0 10 "hello" subseq ] must-fail
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
[ "Replacing+spaces+with+plus" ]
|
|
|
|
[
|
|
|
|
"Replacing spaces with plus"
|
|
|
|
[ dup CHAR: \s = [ drop CHAR: + ] when ] map
|
|
|
|
]
|
|
|
|
unit-test
|
|
|
|
|
2009-01-29 23:19:07 -05:00
|
|
|
[ "05" ] [ "5" 2 CHAR: 0 pad-head ] unit-test
|
|
|
|
[ "666" ] [ "666" 2 CHAR: 0 pad-head ] unit-test
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-06 14:47:19 -05:00
|
|
|
[ 1 "" nth ] must-fail
|
|
|
|
[ -6 "hello" nth ] must-fail
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
[ t ] [ "hello world" dup >vector >string = ] unit-test
|
|
|
|
|
|
|
|
[ "ab" ] [ 2 "abc" resize-string ] unit-test
|
|
|
|
[ "abc\0\0\0" ] [ 6 "abc" resize-string ] unit-test
|
|
|
|
|
2008-02-01 19:36:13 -05:00
|
|
|
[ "\u001234b" ] [ 2 "\u001234bc" resize-string ] unit-test
|
|
|
|
[ "\u001234bc\0\0\0" ] [ 6 "\u001234bc" resize-string ] unit-test
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
! Random tester found this
|
2009-04-30 23:56:15 -04:00
|
|
|
[ 2 -7 resize-string ] [ { "kernel-error" 3 11 -7 } = ] must-fail-with
|
2008-02-01 00:00:08 -05:00
|
|
|
|
2008-02-01 17:02:02 -05:00
|
|
|
! Make sure 24-bit strings work
|
2008-02-01 00:00:08 -05:00
|
|
|
"hello world" "s" set
|
|
|
|
|
|
|
|
[ ] [ HEX: 1234 1 "s" get set-nth ] unit-test
|
|
|
|
[ ] [ HEX: 4321 3 "s" get set-nth ] unit-test
|
|
|
|
[ ] [ HEX: 654321 5 "s" get set-nth ] unit-test
|
|
|
|
|
2011-07-20 16:52:42 -04:00
|
|
|
[ ] [ HEX: -1 5 "s" get set-nth ] unit-test
|
|
|
|
[ ] [ HEX: 80,0000 5 "s" get set-nth ] unit-test
|
|
|
|
[ ] [ HEX: 100,0000 5 "s" get set-nth ] unit-test
|
|
|
|
|
2008-02-01 00:00:08 -05:00
|
|
|
[
|
|
|
|
{
|
|
|
|
CHAR: h
|
|
|
|
HEX: 1234
|
|
|
|
CHAR: l
|
|
|
|
HEX: 4321
|
|
|
|
CHAR: o
|
|
|
|
HEX: 654321
|
|
|
|
CHAR: w
|
|
|
|
CHAR: o
|
|
|
|
CHAR: r
|
|
|
|
CHAR: l
|
|
|
|
CHAR: d
|
|
|
|
}
|
|
|
|
] [
|
|
|
|
"s" get >array
|
|
|
|
] unit-test
|
2008-02-01 17:02:02 -05:00
|
|
|
|
2010-04-25 20:19:50 -04:00
|
|
|
! Make sure string initialization works
|
|
|
|
[ HEX: 123456 ] [ 100 HEX: 123456 <string> first ] unit-test
|
|
|
|
|
2008-02-01 17:02:02 -05:00
|
|
|
! Make sure we clear aux vector when storing octets
|
2009-10-28 15:40:15 -04:00
|
|
|
[ "\u123456hi" ] [ "ih\u123456" clone reverse! ] unit-test
|
2008-02-01 17:02:02 -05:00
|
|
|
|
|
|
|
! Make sure aux vector is not shared
|
|
|
|
[ "\udeadbe" ] [
|
2008-02-02 16:00:05 -05:00
|
|
|
"\udeadbe" clone
|
|
|
|
CHAR: \u123456 over clone set-first
|
2008-02-01 17:02:02 -05:00
|
|
|
] unit-test
|
2008-04-13 10:20:19 -04:00
|
|
|
|
|
|
|
! Regressions
|
|
|
|
[ ] [
|
|
|
|
[
|
|
|
|
4 [
|
2008-06-13 02:51:46 -04:00
|
|
|
100 [ "obdurak" clone ] replicate
|
2008-04-13 10:20:19 -04:00
|
|
|
gc
|
|
|
|
dup [
|
|
|
|
1234 0 rot set-string-nth
|
|
|
|
] each
|
|
|
|
1000 [
|
|
|
|
1000 f <array> drop
|
|
|
|
] times
|
|
|
|
.
|
|
|
|
] times
|
2009-01-13 20:25:44 -05:00
|
|
|
] with-null-writer
|
2008-04-13 10:20:19 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
10000 [
|
|
|
|
drop
|
|
|
|
300 100 CHAR: \u123456
|
|
|
|
[ <string> clone resize-string first ] keep =
|
2010-01-14 10:10:13 -05:00
|
|
|
] all-integers?
|
2008-04-13 10:20:19 -04:00
|
|
|
] unit-test
|