11package main
22
33import (
4+ "errors"
45 "fmt"
56 "testing"
67)
@@ -23,29 +24,32 @@ func TestParseModifiers(t *testing.T) {
2324}
2425
2526func TestComputeRoll (t * testing.T ) {
26- testInputs := []string {
27- "!roll 2d2+100 foo biz baz" ,
28- "!roll 2d2 + 100" ,
29- "!roll 2d2 +100" ,
30- "!roll 2d2+ 100" ,
31- "!roll 2d2-100" ,
32- "!roll 2d2 - 100" ,
33- "!roll 2d2 -100" ,
34- "!roll 2d2- 100" ,
35- "!roll 2d2- 100 foo biz baz" ,
36- "!roll 23904823904823904823490d20 +1" ,
37- "!roll 2d20" ,
38- "!roll 20" ,
39- "!roll 20+10" }
27+ testInputs := []struct {
28+ input string
29+ err error
30+ }{
31+ {input : "!roll 2d2+100 foo biz baz" },
32+ {input : "!roll 2d2 + 100" },
33+ {input : "!roll 2d2 +100" },
34+ {input : "!roll 2d2+ 100" },
35+ {input : "!roll 2d2-100" },
36+ {input : "!roll 2d2 - 100" },
37+ {input : "!roll 2d2 -100" },
38+ {input : "!roll 2d2- 100" },
39+ {input : "!roll 2d2- 100 foo biz baz" },
40+ {input : "!roll 2d20" },
41+ {input : "!roll 20" },
42+ {input : "!roll 20+10" },
43+ {input : "!roll 1d9223372036854775807" },
44+ {input : "!roll 1d9223372036854775807+1" , err : errResultRangeBounds },
45+ {input : "!roll 9223372036854775807d1" , err : errInputBounds },
46+ }
4047
41- for _ , input := range testInputs {
42- result , err := computeRoll (input )
43- errorMessage := fmt .Sprintf ("%v" , err )
44- if err != nil {
45- if errorMessage != "Sides, count or modifier too large" {
46- t .Error (fmt .Sprintf ("Error: %v\n %d" , err , result ))
47- }
48+ for _ , c := range testInputs {
49+ _ , err := computeRoll (c .input )
50+ if ! errors .Is (err , c .err ) {
51+ fmt .Printf (`"%s": unexpected error %s\n` , c .input , err )
52+ t .FailNow ()
4853 }
4954 }
50-
5155}
0 commit comments