From 71ab417a568bdebfbbfcf2fa865b6524db40bcf5 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Mon, 6 May 2024 15:32:44 +0200 Subject: [PATCH] funcs_test.go: added many new tests --- funcs_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/funcs_test.go b/funcs_test.go index b984b12..1103378 100644 --- a/funcs_test.go +++ b/funcs_test.go @@ -38,6 +38,25 @@ func TestFuncs(t *testing.T) { /* 25 */ {`f=func(@y){g=func(){@x=5}; g(); @z=x; @x=@y+@z}; f(2); y+x`, int64(9), nil}, /* 26 */ {`builtin "import"; importAll("./test-funcs.expr"); six()`, int64(6), nil}, /* 27 */ {`builtin "import"; import("./sample-export-all.expr"); six()`, int64(6), nil}, + /* 28 */ {`builtin "string"; joinStr("-", "one", "two", "three")`, "one-two-three", nil}, + /* 29 */ {`builtin "string"; joinStr("-", ["one", "two", "three"])`, "one-two-three", nil}, + /* 30 */ {`builtin "string"; ls= ["one", "two", "three"]; joinStr("-", ls)`, "one-two-three", nil}, + /* 31 */ {`builtin "string"; ls= ["one", "two", "three"]; joinStr(1, ls)`, nil, errors.New(`joinStr() the "separator" parameter must be a string, got a int64 (1)`)}, + /* 32 */ {`builtin "string"; ls= ["one", 2, "three"]; joinStr("-", ls)`, nil, errors.New(`joinStr() expected string, got int64 (2)`)}, + /* 33 */ {`builtin "string"; "<"+trimStr(" bye bye ")+">"`, "", nil}, + /* 34 */ {`builtin "string"; subStr("0123456789", 1,2)`, "12", nil}, + /* 35 */ {`builtin "string"; subStr("0123456789", -3,2)`, "78", nil}, + /* 36 */ {`builtin "string"; subStr("0123456789", -3)`, "789", nil}, + /* 37 */ {`builtin "string"; subStr("0123456789")`, "0123456789", nil}, + /* 38 */ {`builtin "string"; startsWithStr("0123456789", "xyz", "012")`, true, nil}, + /* 39 */ {`builtin "string"; startsWithStr("0123456789", "xyz", "0125")`, false, nil}, + /* 40 */ {`builtin "string"; startsWithStr("0123456789")`, nil, errors.New(`too few params -- expected 2 or more, got 1`)}, + /* 41 */ {`builtin "string"; endsWithStr("0123456789", "xyz", "789")`, true, nil}, + /* 42 */ {`builtin "string"; endsWithStr("0123456789", "xyz", "0125")`, false, nil}, + /* 43 */ {`builtin "string"; endsWithStr("0123456789")`, nil, errors.New(`too few params -- expected 2 or more, got 1`)}, + /* 44 */ {`builtin "string"; splitStr("one-two-three", "-", )`, newListA("one","two","three"), nil}, + /* 45 */ {`["a", "b", "c"]`, newListA("a","b","c"), nil}, + /* 46 */ {`["a", "b", "c"]`, newList([]any{"a","b","c"}), nil}, } t.Setenv("EXPR_PATH", ".")