Skip to content

Commit 011d84f

Browse files
committed
test: add td.Smuggle tests
Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
1 parent 6226d9d commit 011d84f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

td/td_smuggle_private_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func TestFieldsPath(t *testing.T) {
5353
t.Errorf("Failed:\n got: %v\n expected: %v", got, fp)
5454
}
5555

56+
check("[foo][bar]", "foo", "bar")
57+
check("[0][foo][bar]", "0", "foo", "bar")
58+
5659
//
5760
// Errors
5861
checkErr := func(in, expectedErr string) {

td/td_smuggle_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,24 @@ func TestSmuggleFieldsPath(t *testing.T) {
745745
checkOK(t, x, td.Lax(td.Smuggle("PppA", nil)))
746746
checkOK(t, x, td.Smuggle("PppA", td.Nil()))
747747

748+
checkOK(t, x.Iface, td.Smuggle("[test][1]", 3))
749+
checkError(t, x.Iface, td.Smuggle("[unknown][1]", 42),
750+
expectedError{
751+
Message: mustBe("ran smuggle code with %% as argument"),
752+
Path: mustBe("DATA"),
753+
Summary: mustContain(`
754+
it failed coz: field "[unknown]", "unknown" map key not found`),
755+
})
756+
757+
checkOK(t, x.C.Iface1, td.Smuggle("[0][66][1]", "bar"))
758+
checkError(t, x.C.Iface1, td.Smuggle("[42][66][1]", "bar"),
759+
expectedError{
760+
Message: mustBe("ran smuggle code with %% as argument"),
761+
Path: mustBe("DATA"),
762+
Summary: mustContain(`
763+
it failed coz: field "[42]", 42 is out of slice/array range (len 13)`),
764+
})
765+
748766
//
749767
type D struct {
750768
Iface any

0 commit comments

Comments
 (0)