forked from quii/learn-go-with-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding else, subtest syntax and first class functions oh my
- Loading branch information
Showing
7 changed files
with
121 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
const helloPrefix = "Hello, " | ||
|
||
func Hello(name string) string { | ||
if name == "" { | ||
name = "World" | ||
} | ||
return helloPrefix + name | ||
} | ||
|
||
func main() { | ||
fmt.Println(Hello("world")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestHello(t *testing.T) { | ||
|
||
assertCorrectMessage := func(expected, actual string) { | ||
if expected != actual { | ||
t.Errorf("expected '%s' but got '%s'", expected, actual) | ||
} | ||
} | ||
|
||
t.Run("saying hello to people", func(t *testing.T) { | ||
message := Hello("Chris") | ||
expected := "Hello, Chris" | ||
assertCorrectMessage(expected, message) | ||
}) | ||
|
||
t.Run("say hello world when an empty string is supplied", func(t *testing.T) { | ||
message := Hello("") | ||
expected := "Hello, World" | ||
assertCorrectMessage(expected, message) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters