owa-rs/modules/core/tests/str.owa
2026-05-06 12:21:06 +03:00

67 lines
1.6 KiB
Text

(namespace tests.str
(test.case "str.len"
(assert.eq! (str.len "") 0)
(assert.eq! (str.len "hello") 5)
)
(test.case "str.empty?"
(assert.ok! (str.empty? ""))
(assert.not! (str.empty? "a"))
)
(test.case "str.is-empty?"
(assert.ok! (str.is-empty? ""))
(assert.not! (str.is-empty? "a"))
)
(test.case "str.first"
(assert.eq! (str.first "hello") "h")
)
(test.case "str.last"
(assert.eq! (str.last "hello") "o")
)
(test.case "str.concat"
(assert.eq! (str.concat "hello" " " "world") "hello world")
)
(test.case "str.substring"
(assert.eq! (str.substring "hello" 0 3) "hel")
(assert.eq! (str.substring "hello" 1 4) "ell")
)
(test.case "str.take"
(assert.eq! (str.take "hello" 3) "hel")
)
(test.case "str.drop"
(assert.eq! (str.drop "hello" 2) "llo")
)
(test.case "str.reverse"
(assert.eq! (str.reverse "hello") "olleh")
)
(test.case "str.starts-with?"
(assert.ok! (str.starts-with? "hello" "hel"))
(assert.not! (str.starts-with? "hello" "xyz"))
)
(test.case "str.ends-with?"
(assert.ok! (str.ends-with? "hello" "lo"))
(assert.not! (str.ends-with? "hello" "xyz"))
)
(test.case "str.split"
(assert.eq! (str.split "hello world" " ") ["hello" "world"])
(assert.eq! (str.split "hello world" "w") ["hello " "orld"])
(assert.eq! (str.split "hello world" "x") ["hello world"])
)
(test.case "str.join"
(assert.eq! (str.join " " ["hello" "world"]) "hello world")
(assert.eq! (str.join "w" ["hello " "orld"]) "hello world")
(assert.eq! (str.join "x" ["hello world"]) "hello world")
)
)