MCPcopy
hub / github.com/TomWright/dasel / TestStringIndexRange

Function TestStringIndexRange

model/value_literal_test.go:16–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14}
15
16func TestStringIndexRange(t *testing.T) {
17 t.Run("positive range", func(t *testing.T) {
18 v := model.NewStringValue("hello")
19 got, err := v.StringIndexRange(1, 3)
20 if err != nil {
21 t.Fatal(err)
22 }
23 s, _ := got.StringValue()
24 if s != "ell" {
25 t.Errorf("expected 'ell', got %q", s)
26 }
27 })
28 t.Run("negative indices", func(t *testing.T) {
29 v := model.NewStringValue("hello")
30 got, err := v.StringIndexRange(-3, -1)
31 if err != nil {
32 t.Fatal(err)
33 }
34 s, _ := got.StringValue()
35 if s != "llo" {
36 t.Errorf("expected 'llo', got %q", s)
37 }
38 })
39 t.Run("reverse range", func(t *testing.T) {
40 v := model.NewStringValue("hello")
41 got, err := v.StringIndexRange(3, 1)
42 if err != nil {
43 t.Fatal(err)
44 }
45 s, _ := got.StringValue()
46 if s != "lle" {
47 t.Errorf("expected 'lle', got %q", s)
48 }
49 })
50}

Callers

nothing calls this directly

Calls 4

NewStringValueFunction · 0.92
StringIndexRangeMethod · 0.80
StringValueMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected