src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/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 BadValue{What: "command", Valid: "callable", Actual: "number"}, 17 "bad value: command must be callable, but is number", 18 }, 19 { 20 ArityMismatch{What: "arguments", ValidLow: 2, ValidHigh: 2, Actual: 3}, 21 "arity mismatch: arguments must be 2 values, but is 3 values", 22 }, 23 { 24 ArityMismatch{What: "arguments", ValidLow: 2, ValidHigh: -1, Actual: 1}, 25 "arity mismatch: arguments must be 2 or more values, but is 1 value", 26 }, 27 { 28 ArityMismatch{What: "arguments", ValidLow: 2, ValidHigh: 3, Actual: 1}, 29 "arity mismatch: arguments must be 2 to 3 values, but is 1 value", 30 }, 31 { 32 SetReadOnlyVar{VarName: "x"}, 33 "cannot set read-only variable $x", 34 }, 35 { 36 ReaderGone{}, 37 "reader gone", 38 }, 39 } 40 41 func TestErrorMessages(t *testing.T) { 42 for _, test := range errorMessageTests { 43 if gotMsg := test.err.Error(); gotMsg != test.wantMsg { 44 t.Errorf("got message %v, want %v", gotMsg, test.wantMsg) 45 } 46 } 47 }