the example always fails if the string contains a trailing space before a newline

48 views
Skip to first unread message

David M

unread,
Dec 19, 2022, 2:31:47 PM12/19/22
to golang-nuts
Not quite sure if this is a bug but it's annoying:

If the example tested string contains a trailing space before a newline, the test always fails no matter how.

// this test passes 
func ExampleFormat() {
    fmt.Println("a\nb")
    // Output:
    // a 
    // b 
}
// this test fails no matter we put "a" or "a " in the first output line. 
func ExampleFormat() { 
    fmt.Println("a \nb") 
    // Output:
    // a
    // b
 }

The doc says "The comparison ignores leading and trailing space." I guess what's going on here is that it cut the trailing space in the desired output, but doesn't handle the space in the practical output if it's before a newline. Because the practical output may come from a 3rd party library, we have to respect how they print things.

Sean Liao

unread,
Dec 19, 2022, 2:39:14 PM12/19/22
to golang-nuts

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c24ffdb6-bde2-43be-b2ed-9735752bfb95n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages