diff options
| author | s-ol <s+removethis@s-ol.nu> | 2022-02-05 12:20:36 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:24:49 +0000 |
| commit | 7470fee507f49a7b26dd6ecfb262cc4e0da73f18 (patch) | |
| tree | 407eb2d1a4377f1ddea462f2764981c34c08e03d /spec/lib | |
| parent | base.match: predicate fn matching (diff) | |
| download | alive-7470fee507f49a7b26dd6ecfb262cc4e0da73f18.tar.gz alive-7470fee507f49a7b26dd6ecfb262cc4e0da73f18.zip | |
lib: test and extend string module
Diffstat (limited to 'spec/lib')
| -rw-r--r-- | spec/lib/string_spec.moon | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/lib/string_spec.moon b/spec/lib/string_spec.moon new file mode 100644 index 0000000..859c402 --- /dev/null +++ b/spec/lib/string_spec.moon @@ -0,0 +1,70 @@ +import TestPilot from require 'spec.test_setup' +import T, Array from require 'alv' + +describe "string", -> + test = TestPilot '', '(import* testing) (import string)\n' + + describe "str", -> + it "stringifies all primitives", -> + COPILOT\eval_once ' + (expect= "hello" (string/str "hello")) + (expect= "1" (string/str 1)) + (expect= "0.5" (string/str 0.5)) + (expect= "true" (string/str true)) + (expect= "false" (string/str false)) + ' + + it "stringifies arrays", -> + COPILOT\eval_once ' + (expect= "[1 2 3]" (string/str (array 1 2 3))) + (expect= \'["a" "b" "c"]\' (string/str (array "a" "b" "c"))) + ' + + it "stringifies structs", -> + COPILOT\eval_once ' + (expect= \'{a: 1 b: true c: "hello"}\' + (string/str (struct "a" 1 + "b" true + "c" "hello"))) + ' + + it "stringifies deeply", -> + COPILOT\eval_once ' + (expect= "{a: {b: [1 2 3]}}" + (string/str (struct "a" (struct "b" (array 1 2 3))))) + ' + + it "joins multiple arguments", -> + COPILOT\eval_once ' + (expect= "helloworld" (string/str "hello" "world")) + (expect= "here is 1 apple" (string/str "here is " 1 " apple")) + (expect= "this statement is true" (string/str "this statement is " true)) + (expect= "false is a word." (string/str false " is a word.")) + ' + + it "is aliased as ..", -> + COPILOT\eval_once '(expect= string/str string/..)' + + describe "concat", -> + it "concatenates string-arrays", -> + COPILOT\eval_once ' + (expect= "hello" (string/concat (array "hello"))) + (expect= "helloworld" (string/concat (array "hello" "world"))) + (expect= "helloobeautifulworld" (string/concat (array "hello" "o" "beautiful" "world"))) + ' + + it "takes custom separator", -> + COPILOT\eval_once ' + (expect= "a, b, c" (string/concat ", " (array "a" "b" "c"))) + (expect= "hello world" (string/concat " " (array "hello" "world"))) + (expect= "hello o beautiful world" (string/concat " " (array "hello" "o" "beautiful" "world"))) + ' + + describe "join", -> + it "concatenates and stringifies", -> + COPILOT\eval_once ' + (expect= "that is 1 beautiful tree" (string/join " " "that is" 1 "beautiful tree")) + (expect= "my favorite color is [0.9 0.2 1]" (string/join " " "my favorite color is" (array 0.9 0.2 1))) + (expect= "i_am_snek" (string/join "_" "i" "am" "snek")) + ' + |
