Skip to content

Conversation

@gkampitakis
Copy link
Owner

No description provided.

Comment on lines 230 to 234
v := fmt.Sprintf("`%s`", s)
if isSingleline(s) {
// Use double quotes if the string can be safely represented as a Go string literal (no unescaped newlines, backquotes, etc.)
if !hasEscapable(s) {
v = fmt.Sprintf("%q", s)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to do not use strconv.CanQuote ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the CanBackQuote ? For the examples I am checking with it's always returning true resulting to this.

t.Run("should make an inline snapshot", func(t *testing.T) {
		u := struct {
			User string
			Age  int
		}{
			User: "mock-name",
			Age:  30,
		}

		snaps.MatchInlineSnapshot(
			t,
			u, 
- 		snaps.Inline("struct { User string; Age int }{User:\"mock-name\", Age:30}"),
+			snaps.Inline(`struct { User string; Age int }{User:"mock-name", Age:30}`),
		)
	})

@gkampitakis gkampitakis force-pushed the gkampitakis/inline_snaps_backticks branch from 658ec76 to a4c3f2b Compare December 24, 2025 14:50
@gkampitakis gkampitakis marked this pull request as ready for review December 24, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants