explain-xkcd_test.go (870B)
1 package xkcd 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 func TestExplainLatest(t *testing.T) { 9 received := ExplainXKCD(0) 10 expected := "https://www.explainxkcd.com/wiki/index.php/Main_Page\n" 11 if received != expected { 12 msg := fmt.Sprintf("Expected `%s', received `%s'.\n", expected, received) 13 t.Error(msg) 14 } 15 } 16 17 func TestExplainSpecific(t *testing.T) { 18 received := ExplainXKCD(413) 19 expected := "https://www.explainxkcd.com/wiki/index.php/413\n" 20 if received != expected { 21 msg := fmt.Sprintf("Expected `%s', received `%s'.\n", expected, received) 22 t.Error(msg) 23 } 24 } 25 26 func TestExplain404(t *testing.T) { // No reason 404 explain xkcd should not be printed. 27 received := ExplainXKCD(404) 28 expected := "https://www.explainxkcd.com/wiki/index.php/404\n" 29 if received != expected { 30 msg := fmt.Sprintf("Expected `%s', received `%s'.\n", expected, received) 31 t.Error(msg) 32 } 33 }