...

Source file src/cuelang.org/go/cue/errors/errors_test.go

Documentation: cuelang.org/go/cue/errors

     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_Len(t *testing.T) {
    70  	tests := []struct {
    71  		name string
    72  		p    list
    73  		want int
    74  	}{
    75  		// TODO: Add test cases.
    76  	}
    77  	for _, tt := range tests {
    78  		if got := tt.p.Len(); got != tt.want {
    79  			t.Errorf("%q. list.Len() = %v, want %v", tt.name, got, tt.want)
    80  		}
    81  	}
    82  }
    83  
    84  func TestErrorList_Swap(t *testing.T) {
    85  	type args struct {
    86  		i int
    87  		j int
    88  	}
    89  	tests := []struct {
    90  		name string
    91  		p    list
    92  		args args
    93  	}{
    94  		// TODO: Add test cases.
    95  	}
    96  	for _, tt := range tests {
    97  		tt.p.Swap(tt.args.i, tt.args.j)
    98  	}
    99  }
   100  
   101  func TestErrorList_Less(t *testing.T) {
   102  	type args struct {
   103  		i int
   104  		j int
   105  	}
   106  	tests := []struct {
   107  		name string
   108  		p    list
   109  		args args
   110  		want bool
   111  	}{
   112  		// TODO: Add test cases.
   113  	}
   114  	for _, tt := range tests {
   115  		if got := tt.p.Less(tt.args.i, tt.args.j); got != tt.want {
   116  			t.Errorf("%q. list.Less() = %v, want %v", tt.name, got, tt.want)
   117  		}
   118  	}
   119  }
   120  
   121  func TestErrorList_Sort(t *testing.T) {
   122  	tests := []struct {
   123  		name string
   124  		p    list
   125  	}{
   126  		// TODO: Add test cases.
   127  	}
   128  	for _, tt := range tests {
   129  		tt.p.Sort()
   130  	}
   131  }
   132  
   133  func TestErrorList_RemoveMultiples(t *testing.T) {
   134  	tests := []struct {
   135  		name string
   136  		p    *list
   137  	}{
   138  		// TODO: Add test cases.
   139  	}
   140  	for _, tt := range tests {
   141  		tt.p.RemoveMultiples()
   142  	}
   143  }
   144  
   145  func TestErrorList_Error(t *testing.T) {
   146  	tests := []struct {
   147  		name string
   148  		p    list
   149  		want string
   150  	}{
   151  		// TODO: Add test cases.
   152  	}
   153  	for _, tt := range tests {
   154  		if got := tt.p.Error(); got != tt.want {
   155  			t.Errorf("%q. list.Error() = %v, want %v", tt.name, got, tt.want)
   156  		}
   157  	}
   158  }
   159  
   160  func TestErrorList_Err(t *testing.T) {
   161  	tests := []struct {
   162  		name    string
   163  		p       list
   164  		wantErr bool
   165  	}{
   166  		// TODO: Add test cases.
   167  	}
   168  	for _, tt := range tests {
   169  		if err := tt.p.Err(); (err != nil) != tt.wantErr {
   170  			t.Errorf("%q. list.Err() error = %v, wantErr %v", tt.name, err, tt.wantErr)
   171  		}
   172  	}
   173  }
   174  
   175  func TestPrintError(t *testing.T) {
   176  	tests := []struct {
   177  		name  string
   178  		err   error
   179  		wantW string
   180  	}{{
   181  		name:  "SimplePromoted",
   182  		err:   Promote(fmt.Errorf("hello"), "msg"),
   183  		wantW: "msg: hello\n",
   184  	}, {
   185  		name:  "PromoteWithPercent",
   186  		err:   Promote(fmt.Errorf("hello"), "msg%s"),
   187  		wantW: "msg%s: hello\n",
   188  	}, {
   189  		name:  "PromoteWithEmptyString",
   190  		err:   Promote(fmt.Errorf("hello"), ""),
   191  		wantW: "hello\n",
   192  	}, {
   193  		name:  "TwoErrors",
   194  		err:   Append(Promote(fmt.Errorf("hello"), "x"), Promote(fmt.Errorf("goodbye"), "y")),
   195  		wantW: "x: hello\ny: goodbye\n",
   196  	}, {
   197  		name:  "WrappedSingle",
   198  		err:   fmt.Errorf("wrap: %w", Promote(fmt.Errorf("hello"), "x")),
   199  		wantW: "x: hello\n",
   200  	}, {
   201  		name: "WrappedMultiple",
   202  		err: fmt.Errorf("wrap: %w",
   203  			Append(Promote(fmt.Errorf("hello"), "x"), Promote(fmt.Errorf("goodbye"), "y")),
   204  		),
   205  		wantW: "x: hello\ny: goodbye\n",
   206  	}}
   207  	// TODO tests for errors with positions.
   208  	for _, tt := range tests {
   209  		t.Run(tt.name, func(t *testing.T) {
   210  			w := &bytes.Buffer{}
   211  			Print(w, tt.err, nil)
   212  			if gotW := w.String(); gotW != tt.wantW {
   213  				t.Errorf("unexpected PrintError result\ngot %q\nwant %q", gotW, tt.wantW)
   214  			}
   215  		})
   216  	}
   217  }
   218  

View as plain text