xkcd-go

Golang tool to read latest, random, or a specific xkcd comic (and download it too).
git clone http://git.hanabi.in/repos/xkcd-go.git
Log | Files | Refs | README | LICENSE

get-options_test.go (1137B)


      1 package xkcd
      2 
      3 import (
      4 	"fmt"
      5 	"testing"
      6 )
      7 
      8 func TestNoArgs(t *testing.T) {
      9 	input := []string{"bin"}
     10 	option, num, err := GetOption(input)
     11 	if option != "" || num != 0 || err != nil {
     12 		msg := fmt.Sprintf("Expected return empty string, 0 and nil error, got `%s', `%d', `%v'.\n", option, num, err)
     13 		t.Error(msg)
     14 	}
     15 }
     16 
     17 func TestOneValidArg(t *testing.T) {
     18 	var input = []string{"bin", "alif"}
     19 	option, num, err := GetOption(input)
     20 	if option != "alif" || num != 0 || err != nil {
     21 		msg := fmt.Sprintf("Expected return `alif', 0, and nil error, got `%s', `%d', `%v'.\n", option, num, err)
     22 		t.Error(msg)
     23 	}
     24 }
     25 
     26 func TestTwoValidArgs(t *testing.T) {
     27 	var input = []string{"bin", "alif", "465"}
     28 	option, num, err := GetOption(input)
     29 	if option != "alif" || num != 465 || err != nil {
     30 		msg := fmt.Sprintf("Expected return `alif', 465, and nil error, got `%s', `%d', `%v'.\n", option, num, err)
     31 		t.Error(msg)
     32 	}
     33 }
     34 
     35 func TestOneValidOtherInvalidArg(t *testing.T) {
     36 	var input = []string{"bin", "alif", "bet"}
     37 	_, _, err := GetOption(input)
     38 	if err == nil {
     39 		msg := fmt.Sprintf("Expected some err, received `%v'.\n", err)
     40 		t.Error(msg)
     41 	}
     42 }