Skip to content

Commit

Permalink
Add Path tests (FerretDB#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry authored Jul 22, 2022
1 parent 1b9a571 commit 77e4370
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions internal/types/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,73 @@ func TestGetByPath(t *testing.T) {
})
}
}

func TestPathTrimSuffixPrefix(t *testing.T) {
t.Parallel()

pathOneElement := NewPath([]string{"1"})
pathZeroElement := Path{s: []string{}}

type testCase struct {
name string
f func() Path
}

for _, tc := range []testCase{{
name: "prefixOne",
f: pathOneElement.TrimPrefix,
}, {
name: "suffixOne",
f: pathOneElement.TrimSuffix,
}, {
name: "prefixZero",
f: pathZeroElement.TrimPrefix,
}, {
name: "suffixZero",
f: pathZeroElement.TrimSuffix,
}} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

require.Panics(t, func() {
tc.f()
})
})
}
}

func TestPathSuffixPrefix(t *testing.T) {
t.Parallel()

pathOneElement := NewPath([]string{"1"})
pathZeroElement := Path{s: []string{}}

type testCase struct {
name string
f func() string
}

for _, tc := range []testCase{{
name: "prefixOne",
f: pathOneElement.Prefix,
}, {
name: "suffixOne",
f: pathOneElement.Suffix,
}, {
name: "prefixZero",
f: pathZeroElement.Prefix,
}, {
name: "suffixZero",
f: pathZeroElement.Suffix,
}} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

require.Panics(t, func() {
tc.f()
})
})
}
}

0 comments on commit 77e4370

Please sign in to comment.