2017-12-18 18:19:29 +03:00
|
|
|
(use String)
|
|
|
|
|
|
|
|
(load "Test.carp")
|
|
|
|
(use Test)
|
|
|
|
|
|
|
|
(defn main []
|
|
|
|
(with-test test
|
2018-05-20 05:45:34 +03:00
|
|
|
(assert-true test
|
|
|
|
(= @"hello world" @"hello world")
|
|
|
|
"string = works as expected"
|
|
|
|
)
|
2018-05-20 05:45:59 +03:00
|
|
|
(assert-true test
|
|
|
|
(/= @"hello world" @"bob")
|
|
|
|
"string /= works as expected"
|
|
|
|
)
|
2017-12-18 18:19:29 +03:00
|
|
|
(assert-equal test
|
|
|
|
\s
|
|
|
|
(char-at "lisp" 2)
|
|
|
|
"char-at works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
\s
|
|
|
|
(head "silk")
|
|
|
|
"head works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"ilk"
|
|
|
|
&(tail "silk")
|
|
|
|
"tail works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"sshello"
|
|
|
|
&(pad-left 7 \s "hello")
|
|
|
|
"pad-left works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"helloss"
|
|
|
|
&(pad-right 7 \s "hello")
|
|
|
|
"pad-right works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
5
|
|
|
|
(count-char "lisssssp" \s)
|
|
|
|
"count-char works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"olleh"
|
|
|
|
&(reverse "hello")
|
|
|
|
"reverse works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
false
|
|
|
|
(empty? "lisp")
|
|
|
|
"empty? returns false on non-empty string"
|
|
|
|
)
|
2018-03-13 13:59:48 +03:00
|
|
|
(assert-true test
|
|
|
|
(empty? "")
|
|
|
|
"empty? returns true on empty string"
|
2017-12-18 18:19:29 +03:00
|
|
|
)
|
2018-05-20 05:43:04 +03:00
|
|
|
(assert-true test
|
|
|
|
(empty? &(zero))
|
|
|
|
"empty? returns true on (zero)"
|
|
|
|
)
|
2017-12-19 19:32:26 +03:00
|
|
|
(assert-equal test
|
|
|
|
&[\e \r \i \k]
|
|
|
|
&(chars "erik")
|
|
|
|
"chars works as expected"
|
|
|
|
)
|
2018-01-03 14:49:46 +03:00
|
|
|
(assert-equal test
|
|
|
|
"erik"
|
2018-03-12 16:56:05 +03:00
|
|
|
&(from-chars &[\e \r \i \k])
|
2018-01-03 14:49:46 +03:00
|
|
|
"from-chars works as expected"
|
|
|
|
)
|
2018-01-02 20:13:52 +03:00
|
|
|
(assert-equal test
|
|
|
|
"edan"
|
|
|
|
&(substring "svedang" 2 6)
|
|
|
|
"substring works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"sved"
|
|
|
|
&(prefix-string "svedang" 4)
|
|
|
|
"prefix-string works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"dang"
|
|
|
|
&(suffix-string "svedang" 3)
|
|
|
|
"suffix-string works as expected"
|
|
|
|
)
|
2018-03-13 13:59:48 +03:00
|
|
|
(assert-true test
|
|
|
|
(ends-with? "heller" "ler")
|
|
|
|
"ends-with? works as expected"
|
|
|
|
)
|
|
|
|
(assert-true test
|
|
|
|
(ends-with? "ller" "ler")
|
|
|
|
"ends-with? works (regression test for #157)"
|
|
|
|
)
|
|
|
|
(assert-true test
|
|
|
|
(starts-with? "heller" "hell")
|
|
|
|
"starts-with? works as expected"
|
|
|
|
)
|
|
|
|
(assert-true test
|
|
|
|
(in? "metacarpenter" "carp")
|
|
|
|
"in? works on matching pattern"
|
|
|
|
)
|
|
|
|
(assert-false test
|
|
|
|
(in? "metabolism" "carp")
|
|
|
|
"in? works on non-matching pattern"
|
|
|
|
)
|
|
|
|
(assert-true test
|
|
|
|
(upper? "I AM SCREAMING!")
|
|
|
|
"upper? works on matching pattern"
|
|
|
|
)
|
|
|
|
(assert-false test
|
|
|
|
(upper? "I am not screaming.")
|
|
|
|
"upper? works on non-matching pattern"
|
|
|
|
)
|
|
|
|
(assert-true test
|
|
|
|
(lower? "i am not screaming.")
|
|
|
|
"lower? works on matching pattern"
|
|
|
|
)
|
|
|
|
(assert-false test
|
|
|
|
(lower? "I am not screaming!")
|
|
|
|
"lower? works on non-matching pattern"
|
|
|
|
)
|
|
|
|
(assert-true test
|
|
|
|
(num? "11123456789123")
|
|
|
|
"num? works on matching pattern"
|
|
|
|
)
|
|
|
|
(assert-false test
|
|
|
|
(num? "111l23456789123")
|
|
|
|
"num? works on non-matching pattern"
|
|
|
|
)
|
|
|
|
(assert-true test
|
|
|
|
(alpha? "abcdefghijklmz")
|
|
|
|
"alpha? works on matching pattern"
|
|
|
|
)
|
|
|
|
(assert-false test
|
|
|
|
(alpha? "abcdefghijklm1234567")
|
|
|
|
"alpha? works on non-matching pattern"
|
|
|
|
)
|
|
|
|
(assert-true test
|
|
|
|
(alphanum? "abcdefghijklm1234567")
|
|
|
|
"alphanum? works on matching pattern"
|
|
|
|
)
|
|
|
|
(assert-false test
|
|
|
|
(alphanum? "abcdefghijklm1234567?")
|
|
|
|
"alphanum? works on non-matching pattern"
|
|
|
|
)
|
|
|
|
(assert-true test
|
|
|
|
(hex? "c0ffee")
|
|
|
|
"hex? works on matching pattern"
|
|
|
|
)
|
|
|
|
(assert-false test
|
|
|
|
(hex? "c0ffeebar")
|
|
|
|
"hex? works on non-matching pattern"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"string "
|
|
|
|
&(trim-left " string ")
|
|
|
|
"trim-left works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
" string"
|
|
|
|
&(trim-right " string ")
|
|
|
|
"trim-right works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"string"
|
|
|
|
&(trim " string ")
|
|
|
|
"trim works as expected"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"string"
|
|
|
|
&(chomp "string\n")
|
|
|
|
"chomp works as expected I"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"string\n"
|
|
|
|
&(chomp "string\n\n")
|
|
|
|
"chomp works as expected II"
|
|
|
|
)
|
2018-01-02 20:13:52 +03:00
|
|
|
(assert-equal test
|
2018-03-13 13:59:48 +03:00
|
|
|
"string"
|
|
|
|
&(chomp "string\r\n")
|
|
|
|
"chomp works as expected III"
|
2018-01-02 20:13:52 +03:00
|
|
|
)
|
2018-01-03 14:49:46 +03:00
|
|
|
(assert-equal test
|
2018-03-13 13:59:48 +03:00
|
|
|
"string"
|
|
|
|
&(chomp "string\r")
|
|
|
|
"chomp works as expected IV"
|
2018-01-03 14:49:46 +03:00
|
|
|
)
|
2018-01-02 20:13:52 +03:00
|
|
|
(assert-equal test
|
2018-03-13 13:59:48 +03:00
|
|
|
"too much whitespace."
|
|
|
|
&(collapse-whitespace "too much whitespace.")
|
|
|
|
"collapse-whitespace works as expected"
|
2018-01-02 20:13:52 +03:00
|
|
|
)
|
2018-03-13 17:15:31 +03:00
|
|
|
(assert-equal test
|
|
|
|
&[@"erik" @"sved" @"hej" @"foo"]
|
|
|
|
&(words "erik sved hej\tfoo")
|
|
|
|
"words works correctly"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
&[@"erik" @"sved" @"hej" @"foo"]
|
|
|
|
&(lines "erik\nsved\nhej\nfoo")
|
|
|
|
"lines works correctly"
|
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
&[@"erik" @"sved" @"hej" @"foo"]
|
|
|
|
&(split-by "erikmsvedlhejxfoo" &[\m \l \x])
|
|
|
|
"split-by works correctly"
|
|
|
|
)
|
2018-05-20 05:38:59 +03:00
|
|
|
(assert-equal test
|
|
|
|
"hello world"
|
|
|
|
&(append @"hello " @"world")
|
|
|
|
"append works correctly"
|
|
|
|
)
|
2018-05-19 06:20:56 +03:00
|
|
|
(assert-equal test
|
|
|
|
"hello world"
|
2018-05-19 09:02:03 +03:00
|
|
|
&(concat &[@"hello" @" " @"world"])
|
|
|
|
"concat works correctly"
|
2018-05-19 06:20:56 +03:00
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"hello world"
|
2018-05-19 09:02:03 +03:00
|
|
|
&(join "" &[@"hello" @" " @"world"])
|
|
|
|
"join works correctly I"
|
2018-05-19 06:20:56 +03:00
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"hello world"
|
2018-05-19 09:02:03 +03:00
|
|
|
&(join " " &[@"hello" @"world"])
|
|
|
|
"join works correctly II"
|
2018-05-19 06:20:56 +03:00
|
|
|
)
|
|
|
|
(assert-equal test
|
|
|
|
"hello aaaa there aaaa world"
|
2018-05-19 09:02:03 +03:00
|
|
|
&(join " aaaa " &[@"hello" @"there" @"world"])
|
|
|
|
"join works correctly III"
|
2018-05-19 06:20:56 +03:00
|
|
|
)
|
2018-05-20 05:41:02 +03:00
|
|
|
(assert-equal test
|
|
|
|
"hellohellohello"
|
|
|
|
&(repeat 3 "hello")
|
|
|
|
"repeat works correctly"
|
|
|
|
)
|
2017-12-18 18:19:29 +03:00
|
|
|
(print-test-results test)
|
2018-03-13 13:59:48 +03:00
|
|
|
)
|
|
|
|
)
|