factor/core/strings/strings-tests.factor

137 lines
3.3 KiB
Factor
Raw Normal View History

USING: arrays continuations io.streams.null kernel
kernel.private literals make math math.order memory namespaces
prettyprint sbufs sequences strings strings.private tools.test
vectors ;
2007-09-20 18:09:08 -04:00
{ CHAR: b } [ 1 >bignum "abc" nth ] unit-test
2007-09-20 18:09:08 -04: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
2007-09-20 18:09:08 -04:00
{ "abc" } [ "ab" "c" append ] unit-test
{ "abc" } [ "a" "b" "c" 3append ] unit-test
2007-09-20 18:09:08 -04:00
{ 3 } [ "a" "hola" subseq-start ] unit-test
{ f } [ "x" "hola" subseq-start ] unit-test
{ 0 } [ "" "a" subseq-start ] unit-test
{ 0 } [ "" "" subseq-start ] unit-test
{ 0 } [ "hola" "hola" subseq-start ] unit-test
{ 1 } [ "ol" "hola" subseq-start ] unit-test
{ f } [ "amigo" "hola" subseq-start ] unit-test
{ f } [ "holaa" "hola" subseq-start ] unit-test
2007-09-20 18:09:08 -04:00
{ "Beginning" } [ "Beginning and end" 9 head ] unit-test
2007-09-20 18:09:08 -04:00
{ f } [ CHAR: I "team" member? ] unit-test
{ t } [ "ea" "team" subseq? ] unit-test
{ f } [ "actore" "Factor" subseq? ] unit-test
2007-09-20 18:09:08 -04:00
{ "end" } [ "Beginning and end" 14 tail ] unit-test
2007-09-20 18:09:08 -04:00
{ t } [ "abc" "abd" before? ] unit-test
{ t } [ "z" "abd" after? ] unit-test
{ "abc" } [ "abc" "abd" min ] unit-test
{ "z" } [ "z" "abd" max ] unit-test
2007-09-20 18:09:08 -04:00
[ 0 10 "hello" subseq ] must-fail
2007-09-20 18:09:08 -04:00
{ "Replacing+spaces+with+plus" }
2007-09-20 18:09:08 -04:00
[
"Replacing spaces with plus"
[ dup CHAR: \s = [ drop CHAR: + ] when ] map
]
unit-test
{ "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
[ 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
2007-09-20 18:09:08 -04:00
{ "ab" } [ 2 "abc" resize-string ] unit-test
{ "abc\0\0\0" } [ 6 "abc" resize-string ] unit-test
2007-09-20 18:09:08 -04:00
{ "\u001234b" } [ 2 "\u001234bc" resize-string ] unit-test
{ "\u001234bc\0\0\0" } [ 6 "\u001234bc" resize-string ] unit-test
2008-02-01 19:36:13 -05:00
2007-09-20 18:09:08 -04:00
! Random tester found this
[ 2 -7 resize-string ]
[ ${ KERNEL-ERROR ERROR-TYPE 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
{ } [ 0x1234 1 "s" get set-nth ] unit-test
{ 0x1234 } [ 1 "s" get nth ] unit-test
{ } [ 0x4321 3 "s" get set-nth ] unit-test
{ 0x4321 } [ 3 "s" get nth ] unit-test
2008-02-01 00:00:08 -05:00
{ } [ 0x654321 5 "s" get set-nth ] unit-test
{ 0x654321 } [ 5 "s" get nth ] unit-test
{
2008-02-01 00:00:08 -05:00
{
CHAR: h
2011-11-23 21:49:33 -05:00
0x1234
2008-02-01 00:00:08 -05:00
CHAR: l
2011-11-23 21:49:33 -05:00
0x4321
2008-02-01 00:00:08 -05:00
CHAR: o
2011-11-23 21:49:33 -05:00
0x654321
2008-02-01 00:00:08 -05:00
CHAR: w
CHAR: o
CHAR: r
CHAR: l
CHAR: d
}
} [
2008-02-01 00:00:08 -05:00
"s" get >array
] unit-test
2008-02-01 17:02:02 -05:00
! Make sure string initialization works
{ 0x123456 } [ 100 0x123456 <string> first ] unit-test
2008-02-01 17:02:02 -05:00
! Make sure we clear aux vector when storing octets
{ "\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
! Regressions
{ } [
[
4 [
100 [ "obdurak" clone ] replicate
gc
dup [
1234 0 rot set-string-nth
] each
1000 [
1000 f <array> drop
] times
.
] times
] with-null-writer
] 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?
] unit-test
"X" "s" set
{ } [ 0x100,0000 0 "s" get set-nth ] unit-test
{ 0 } [ 0 "s" get nth ] unit-test
{ } [ -1 0 "s" get set-nth ] unit-test
{ 0x7fffff } [ 0 "s" get nth ] unit-test