cuelang.org/go@v0.10.1/cue/errors/errors_test.go (about) 1 // Copyright 2018 The CUE Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package errors 16 17 import ( 18 "bytes" 19 "fmt" 20 "testing" 21 22 "cuelang.org/go/cue/token" 23 ) 24 25 func TestError_Error(t *testing.T) { 26 tests := []struct { 27 name string 28 e Error 29 want string 30 }{ 31 // TODO: Add test cases. 32 } 33 for _, tt := range tests { 34 if got := tt.e.Error(); got != tt.want { 35 t.Errorf("%q. Error.Error() = %v, want %v", tt.name, got, tt.want) 36 } 37 } 38 } 39 40 func TestErrorList_Add(t *testing.T) { 41 type args struct { 42 pos token.Pos 43 msg string 44 } 45 tests := []struct { 46 name string 47 p *list 48 args args 49 }{ 50 // TODO: Add test cases. 51 } 52 for _, tt := range tests { 53 tt.p.AddNewf(tt.args.pos, tt.args.msg) 54 } 55 } 56 57 func TestErrorList_Reset(t *testing.T) { 58 tests := []struct { 59 name string 60 p *list 61 }{ 62 // TODO: Add test cases. 63 } 64 for _, tt := range tests { 65 tt.p.Reset() 66 } 67 } 68 69 func TestErrorList_Sort(t *testing.T) { 70 tests := []struct { 71 name string 72 p list 73 }{ 74 // TODO: Add test cases. 75 } 76 for _, tt := range tests { 77 tt.p.Sort() 78 } 79 } 80 81 func TestErrorList_RemoveMultiples(t *testing.T) { 82 tests := []struct { 83 name string 84 p *list 85 }{ 86 // TODO: Add test cases. 87 } 88 for _, tt := range tests { 89 tt.p.RemoveMultiples() 90 } 91 } 92 93 func TestErrorList_Error(t *testing.T) { 94 tests := []struct { 95 name string 96 p list 97 want string 98 }{ 99 // TODO: Add test cases. 100 } 101 for _, tt := range tests { 102 if got := tt.p.Error(); got != tt.want { 103 t.Errorf("%q. list.Error() = %v, want %v", tt.name, got, tt.want) 104 } 105 } 106 } 107 108 func TestErrorList_Err(t *testing.T) { 109 tests := []struct { 110 name string 111 p list 112 wantErr bool 113 }{ 114 // TODO: Add test cases. 115 } 116 for _, tt := range tests { 117 if err := tt.p.Err(); (err != nil) != tt.wantErr { 118 t.Errorf("%q. list.Err() error = %v, wantErr %v", tt.name, err, tt.wantErr) 119 } 120 } 121 } 122 123 func TestPrintError(t *testing.T) { 124 tests := []struct { 125 name string 126 err error 127 wantW string 128 }{{ 129 name: "SimplePromoted", 130 err: Promote(fmt.Errorf("hello"), "msg"), 131 wantW: "msg: hello\n", 132 }, { 133 name: "PromoteWithPercent", 134 err: Promote(fmt.Errorf("hello"), "msg%s"), 135 wantW: "msg%s: hello\n", 136 }, { 137 name: "PromoteWithEmptyString", 138 err: Promote(fmt.Errorf("hello"), ""), 139 wantW: "hello\n", 140 }, { 141 name: "TwoErrors", 142 err: Append(Promote(fmt.Errorf("hello"), "x"), Promote(fmt.Errorf("goodbye"), "y")), 143 wantW: "x: hello\ny: goodbye\n", 144 }, { 145 name: "WrappedSingle", 146 err: fmt.Errorf("wrap: %w", Promote(fmt.Errorf("hello"), "x")), 147 wantW: "x: hello\n", 148 }, { 149 name: "WrappedMultiple", 150 err: fmt.Errorf("wrap: %w", 151 Append(Promote(fmt.Errorf("hello"), "x"), Promote(fmt.Errorf("goodbye"), "y")), 152 ), 153 wantW: "x: hello\ny: goodbye\n", 154 }} 155 // TODO tests for errors with positions. 156 for _, tt := range tests { 157 t.Run(tt.name, func(t *testing.T) { 158 w := &bytes.Buffer{} 159 Print(w, tt.err, nil) 160 if gotW := w.String(); gotW != tt.wantW { 161 t.Errorf("unexpected PrintError result\ngot %q\nwant %q", gotW, tt.wantW) 162 } 163 }) 164 } 165 }