diff --git a/snaps/matchInline.go b/snaps/matchInlineSnapshot.go similarity index 70% rename from snaps/matchInline.go rename to snaps/matchInlineSnapshot.go index 27287d1..4ed2cbb 100644 --- a/snaps/matchInline.go +++ b/snaps/matchInlineSnapshot.go @@ -15,12 +15,49 @@ import ( type InlineSnapshot *string +// Inline representation of snapshot func Inline(s string) InlineSnapshot { return &s } +/* +MatchInlineSnapshot verifies the value matches the inline snapshot +First you call it with nil + + MatchInlineSnapshot(t, "mysnapshot", nil) + +and it populates with the snapshot + + MatchInlineSnapshot(t, "mysnapshot", snaps.Inline("mysnapshot")) + +the on every subsequent call it verifies the value matches the snapshot +*/ +func (c *config) MatchInlineSnapshot(t testingT, received interface{}, inlineSnap InlineSnapshot) { + t.Helper() + + matchInlineSnapshot(c, t, received, inlineSnap) +} + +/* +MatchInlineSnapshot verifies the value matches the inline snapshot +First you call it with nil + + MatchInlineSnapshot(t, "mysnapshot", nil) + +and it populates with the snapshot + + MatchInlineSnapshot(t, "mysnapshot", snaps.Inline("mysnapshot")) + +the on every subsequent call it verifies the value matches the snapshot +*/ func MatchInlineSnapshot(t testingT, received interface{}, inlineSnap InlineSnapshot) { t.Helper() + + matchInlineSnapshot(&defaultConfig, t, received, inlineSnap) +} + +func matchInlineSnapshot(c *config, t testingT, received interface{}, inlineSnap InlineSnapshot) { + t.Helper() snapshot := pretty.Sprint(received) filename, line := baseCaller(1) @@ -42,7 +79,7 @@ func MatchInlineSnapshot(t testingT, received interface{}, inlineSnap InlineSnap return } - if !shouldUpdateSingle(t.Name()) { + if !shouldUpdate(c.update) { handleError(t, diff) return } diff --git a/snaps/matchInlineSnapshot_test.go b/snaps/matchInlineSnapshot_test.go new file mode 100644 index 0000000..5a0181b --- /dev/null +++ b/snaps/matchInlineSnapshot_test.go @@ -0,0 +1,7 @@ +package snaps + +import "testing" + +func TestMatchInlineSnapshot(t *testing.T) { + t.Error("unimplemented") +}