Skip to content

Commit 9f6c19b

Browse files
committed
fix(Grep,Last,First): String() does not show expected value
Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
1 parent 3621586 commit 9f6c19b

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

td/td_grep.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/maxatome/go-testdeep/internal/ctxerr"
1313
"github.com/maxatome/go-testdeep/internal/types"
14+
"github.com/maxatome/go-testdeep/internal/util"
1415
)
1516

1617
const grepUsage = "(FILTER_FUNC|FILTER_TESTDEEP_OPERATOR, TESTDEEP_OPERATOR|EXPECTED_VALUE)"
@@ -97,9 +98,15 @@ func (g *tdGrepBase) String() string {
9798
return g.stringError()
9899
}
99100
if g.argType == nil {
100-
return S("%s(%s)", g.GetLocation().Func, g.filter.Interface().(TestDeep))
101+
return S("%s(%s, %s)",
102+
g.GetLocation().Func,
103+
g.filter.Interface().(TestDeep),
104+
util.ToString(g.expectedValue))
101105
}
102-
return S("%s(%s)", g.GetLocation().Func, g.filter.Type())
106+
return S("%s(%s, %s)",
107+
g.GetLocation().Func,
108+
g.filter.Type(),
109+
util.ToString(g.expectedValue))
103110
}
104111

105112
func (g *tdGrepBase) TypeBehind() reflect.Type {

td/td_grep_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ func TestGrepTypeBehind(t *testing.T) {
276276
func TestGrepString(t *testing.T) {
277277
test.EqualStr(t,
278278
td.Grep(func(n int) bool { return true }, []int{}).String(),
279-
"Grep(func(int) bool)")
279+
"Grep(func(int) bool, ([]int) {\n})")
280280

281-
test.EqualStr(t, td.Grep(td.Gt(0), []int{}).String(), "Grep(> 0)")
281+
test.EqualStr(t, td.Grep(td.Gt(0), []int{}).String(), "Grep(> 0, ([]int) {\n})")
282282

283283
// Erroneous op
284284
test.EqualStr(t, td.Grep(42, []int{}).String(), "Grep(<ERROR>)")
@@ -323,7 +323,7 @@ func TestFirst(t *testing.T) {
323323
Message: mustBe("item not found"),
324324
Path: mustBe("DATA"),
325325
Got: mustContain(`]int) (len=7 `),
326-
Expected: mustBe("First(> 666)"),
326+
Expected: mustBe(`First(> 666, "never reached")`),
327327
})
328328
})
329329
}
@@ -444,7 +444,7 @@ func TestFirst(t *testing.T) {
444444
Message: mustBe("item not found"),
445445
Path: mustBe("DATA"),
446446
Got: mustBe("([]int) <nil>"),
447-
Expected: mustBe("First(> 666)"),
447+
Expected: mustBe(`First(> 666, "never reached")`),
448448
})
449449
})
450450
}
@@ -530,9 +530,9 @@ func TestFirst(t *testing.T) {
530530
func TestFirstString(t *testing.T) {
531531
test.EqualStr(t,
532532
td.First(func(n int) bool { return true }, 33).String(),
533-
"First(func(int) bool)")
533+
"First(func(int) bool, 33)")
534534

535-
test.EqualStr(t, td.First(td.Gt(0), 33).String(), "First(> 0)")
535+
test.EqualStr(t, td.First(td.Gt(0), 33).String(), "First(> 0, 33)")
536536

537537
// Erroneous op
538538
test.EqualStr(t, td.First(42, 33).String(), "First(<ERROR>)")
@@ -585,7 +585,7 @@ func TestLast(t *testing.T) {
585585
Message: mustBe("item not found"),
586586
Path: mustBe("DATA"),
587587
Got: mustContain(`]int) (len=7 `),
588-
Expected: mustBe("Last(> 666)"),
588+
Expected: mustBe(`Last(> 666, "never reached")`),
589589
})
590590
})
591591
}
@@ -706,7 +706,7 @@ func TestLast(t *testing.T) {
706706
Message: mustBe("item not found"),
707707
Path: mustBe("DATA"),
708708
Got: mustBe("([]int) <nil>"),
709-
Expected: mustBe("Last(> 666)"),
709+
Expected: mustBe(`Last(> 666, "never reached")`),
710710
})
711711
})
712712
}
@@ -792,9 +792,9 @@ func TestLast(t *testing.T) {
792792
func TestLastString(t *testing.T) {
793793
test.EqualStr(t,
794794
td.Last(func(n int) bool { return true }, 33).String(),
795-
"Last(func(int) bool)")
795+
"Last(func(int) bool, 33)")
796796

797-
test.EqualStr(t, td.Last(td.Gt(0), 33).String(), "Last(> 0)")
797+
test.EqualStr(t, td.Last(td.Gt(0), 33).String(), "Last(> 0, 33)")
798798

799799
// Erroneous op
800800
test.EqualStr(t, td.Last(42, 33).String(), "Last(<ERROR>)")

0 commit comments

Comments
 (0)