Debian Codegraph @

execution/func_trim_test.go

raw symbols SCIP
1 package execution_test
2
3 import (
4 "testing"
5
6 "github.com/tomwright/dasel/v3/model"
7 )
8
9 func TestFuncTrim(t *testing.T) {
10 t.Run("chained input", testCase{
11 s: `" hello ".trim()`,
12 out: model.NewStringValue("hello"),
13 }.run)
14 t.Run("arg input", testCase{
15 s: `trim(" hello ")`,
16 out: model.NewStringValue("hello"),
17 }.run)
18 t.Run("tabs and newlines", testCase{
19 s: `trim("\n\thello\t\n")`,
20 out: model.NewStringValue("hello"),
21 }.run)
22 t.Run("no whitespace", testCase{
23 s: `"hello".trim()`,
24 out: model.NewStringValue("hello"),
25 }.run)
26 }
27
28 func TestFuncTrimPrefix(t *testing.T) {
29 t.Run("chained input", testCase{
30 s: `"hello world".trimPrefix("hello ")`,
31 out: model.NewStringValue("world"),
32 }.run)
33 t.Run("arg input", testCase{
34 s: `trimPrefix("hello world", "hello ")`,
35 out: model.NewStringValue("world"),
36 }.run)
37 t.Run("no match", testCase{
38 s: `"hello world".trimPrefix("xyz")`,
39 out: model.NewStringValue("hello world"),
40 }.run)
41 }
42
43 func TestFuncTrimSuffix(t *testing.T) {
44 t.Run("chained input", testCase{
45 s: `"hello world".trimSuffix(" world")`,
46 out: model.NewStringValue("hello"),
47 }.run)
48 t.Run("arg input", testCase{
49 s: `trimSuffix("hello world", " world")`,
50 out: model.NewStringValue("hello"),
51 }.run)
52 t.Run("no match", testCase{
53 s: `"hello world".trimSuffix("xyz")`,
54 out: model.NewStringValue("hello world"),
55 }.run)
56 }