github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/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", ValidLow: 2, ValidHigh: 2, Actual: 3}, 25 "arity mismatch: arguments must be 2 values, but is 3 values", 26 }, 27 { 28 ArityMismatch{What: "arguments", ValidLow: 2, ValidHigh: -1, Actual: 1}, 29 "arity mismatch: arguments must be 2 or more values, but is 1 value", 30 }, 31 { 32 ArityMismatch{What: "arguments", ValidLow: 2, ValidHigh: 3, Actual: 1}, 33 "arity mismatch: arguments must be 2 to 3 values, but is 1 value", 34 }, 35 { 36 SetReadOnlyVar{VarName: "x"}, 37 "cannot set read-only variable $x", 38 }, 39 { 40 ReaderGone{}, 41 "reader gone", 42 }, 43 } 44 45 func TestErrorMessages(t *testing.T) { 46 for _, test := range errorMessageTests { 47 if gotMsg := test.err.Error(); gotMsg != test.wantMsg { 48 t.Errorf("got message %v, want %v", gotMsg, test.wantMsg) 49 } 50 } 51 }