diff --git a/hello-world.md b/hello-world.md index 5c110a97c..f24cafef2 100644 --- a/hello-world.md +++ b/hello-world.md @@ -64,7 +64,7 @@ func TestHello(t *testing.T) { want := "Hello, world" if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } } ``` @@ -94,7 +94,9 @@ We're declaring some variables with the syntax `varName := value`, which lets us #### `t.Errorf` -We are calling the `Errorf` _method_ on our `t` which will print out a message and fail the test. The `f` stands for format which allows us to build a string with values inserted into the placeholder values `%s`. When you made the test fail it should be clear how it works. +We are calling the `Errorf` _method_ on our `t` which will print out a message and fail the test. The `f` stands for format which allows us to build a string with values inserted into the placeholder values `%q`. When you made the test fail it should be clear how it works. + +You can read more about the placeholder strings in the [fmt go doc](https://golang.org/pkg/fmt/#hdr-Printing). For tests `%q` is very useful as it wraps your values in double quotes. We will later explore the difference between methods and functions. @@ -124,7 +126,7 @@ func TestHello(t *testing.T) { want := "Hello, Chris" if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } } ``` @@ -223,7 +225,7 @@ func TestHello(t *testing.T) { want := "Hello, Chris" if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } }) @@ -232,7 +234,7 @@ func TestHello(t *testing.T) { want := "Hello, World" if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } }) @@ -257,7 +259,7 @@ func TestHello(t *testing.T) { assertCorrectMessage := func(t *testing.T, got, want string) { t.Helper() if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } } diff --git a/hello-world/v2/hello_test.go b/hello-world/v2/hello_test.go index 6deed63b3..0531825af 100644 --- a/hello-world/v2/hello_test.go +++ b/hello-world/v2/hello_test.go @@ -7,6 +7,6 @@ func TestHello(t *testing.T) { want := "Hello, world" if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } } diff --git a/hello-world/v3/hello_test.go b/hello-world/v3/hello_test.go index 66d190fda..c11ea0ce5 100644 --- a/hello-world/v3/hello_test.go +++ b/hello-world/v3/hello_test.go @@ -7,6 +7,6 @@ func TestHello(t *testing.T) { want := "Hello, Chris" if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } } diff --git a/hello-world/v4/hello_test.go b/hello-world/v4/hello_test.go index 66d190fda..c11ea0ce5 100644 --- a/hello-world/v4/hello_test.go +++ b/hello-world/v4/hello_test.go @@ -7,6 +7,6 @@ func TestHello(t *testing.T) { want := "Hello, Chris" if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } } diff --git a/hello-world/v5/hello_test.go b/hello-world/v5/hello_test.go index e871c461f..5f2e56712 100644 --- a/hello-world/v5/hello_test.go +++ b/hello-world/v5/hello_test.go @@ -7,7 +7,7 @@ func TestHello(t *testing.T) { assertCorrectMessage := func(t *testing.T, got, want string) { t.Helper() if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } } diff --git a/hello-world/v6/hello_test.go b/hello-world/v6/hello_test.go index ca9f43349..02ac6fd3f 100644 --- a/hello-world/v6/hello_test.go +++ b/hello-world/v6/hello_test.go @@ -7,7 +7,7 @@ func TestHello(t *testing.T) { assertCorrectMessage := func(t *testing.T, got, want string) { t.Helper() if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } } diff --git a/hello-world/v7/hello_test.go b/hello-world/v7/hello_test.go index de665ae02..d96cd9cf5 100644 --- a/hello-world/v7/hello_test.go +++ b/hello-world/v7/hello_test.go @@ -7,7 +7,7 @@ func TestHello(t *testing.T) { assertCorrectMessage := func(got, want string) { t.Helper() if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } } diff --git a/hello-world/v8/hello_test.go b/hello-world/v8/hello_test.go index ca9f43349..02ac6fd3f 100644 --- a/hello-world/v8/hello_test.go +++ b/hello-world/v8/hello_test.go @@ -7,7 +7,7 @@ func TestHello(t *testing.T) { assertCorrectMessage := func(t *testing.T, got, want string) { t.Helper() if got != want { - t.Errorf("got '%s' want '%s'", got, want) + t.Errorf("got %q want %q", got, want) } }