github.com/elves/elvish@v0.15.0/pkg/eval/errs/errs_test.go (about) 1 package errs 2 3 import ( 4 "testing" 5 ) 6 7 var errorMessageTests = []struct { 8 err error 9 wantMsg string 10 }{ 11 { 12 OutOfRange{What: "list index here", ValidLow: "0", ValidHigh: "2", Actual: "3"}, 13 "out of range: list index here must be from 0 to 2, but is 3", 14 }, 15 { 16 OutOfRange{What: "list index here", ValidLow: "1", ValidHigh: "0", Actual: "0"}, 17 "out of range: list index here has no valid value, but is 0", 18 }, 19 { 20 BadValue{What: "command", Valid: "callable", Actual: "number"}, 21 "bad value: command must be callable, but is number", 22 }, 23 { 24 ArityMismatch{What: "arguments here", ValidLow: 2, ValidHigh: 2, Actual: 3}, 25 "arity mismatch: arguments here must be 2 values, but is 3 values", 26 }, 27 { 28 ArityMismatch{What: "arguments here", ValidLow: 2, ValidHigh: -1, Actual: 1}, 29 "arity mismatch: arguments here must be 2 or more values, but is 1 value", 30 }, 31 { 32 ArityMismatch{What: "arguments here", ValidLow: 2, ValidHigh: 3, Actual: 1}, 33 "arity mismatch: arguments here must be 2 to 3 values, but is 1 value", 34 }, 35 } 36 37 func TestErrorMessages(t *testing.T) { 38 for _, test := range errorMessageTests { 39 if gotMsg := test.err.Error(); gotMsg != test.wantMsg { 40 t.Errorf("got message %v, want %v", gotMsg, test.wantMsg) 41 } 42 } 43 }