(t *testing.T)
| 30 | } |
| 31 | |
| 32 | func Test_createNewBufferWithData(t *testing.T) { |
| 33 | type args struct { |
| 34 | ss [][]string |
| 35 | strict bool |
| 36 | } |
| 37 | wantBuffer := createNewBuffer() |
| 38 | wantBuffer.colLen = 3 |
| 39 | wantBuffer.rowLen = 4 |
| 40 | wantBuffer.cont = [][]string{{"a", "b", "c"}, {"1", "2", "3"}, {"4", "5", "6"}, {"7", "8", "9"}} |
| 41 | wantBuffer.colType = []int{0, 0, 0, 0} |
| 42 | // Don't compare memory usage as it varies |
| 43 | wantBuffer.memoryUsage = 0 |
| 44 | tests := []struct { |
| 45 | name string |
| 46 | args args |
| 47 | want *Buffer |
| 48 | wantErr bool |
| 49 | }{ |
| 50 | {"Valid data strict mode", args{ss: [][]string{{"a", "b", "c"}, {"1", "2", "3"}, {"4", "5", "6"}, {"7", "8", "9"}}, strict: true}, wantBuffer, false}, |
| 51 | {"Inconsistent columns strict mode", args{ss: [][]string{{"a", "b", "c"}, {"1", "2", "3"}, {"4", "5"}, {"7", "8", "9"}}, strict: true}, nil, true}, |
| 52 | } |
| 53 | for _, tt := range tests { |
| 54 | t.Run(tt.name, func(t *testing.T) { |
| 55 | got, err := createNewBufferWithData(tt.args.ss, tt.args.strict) |
| 56 | if (err != nil) != tt.wantErr { |
| 57 | t.Errorf("createNewBufferWithData() error = %v, wantErr %v", err, tt.wantErr) |
| 58 | return |
| 59 | } |
| 60 | // Skip deep equal check for non-error cases (memory usage makes comparison tricky) |
| 61 | if err == nil && got != nil { |
| 62 | if got.rowLen != tt.want.rowLen { |
| 63 | t.Errorf("rowLen = %v, want %v", got.rowLen, tt.want.rowLen) |
| 64 | } |
| 65 | if got.colLen != tt.want.colLen { |
| 66 | t.Errorf("colLen = %v, want %v", got.colLen, tt.want.colLen) |
| 67 | } |
| 68 | } |
| 69 | }) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // ======================================== |
| 74 | // Buffer Data Manipulation Tests |
nothing calls this directly
no test coverage detected