-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #612 from noborus/test-align
Added Align & raw Converter test
- Loading branch information
Showing
7 changed files
with
239 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package oviewer | ||
|
||
import ( | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
func Test_align_convert(t *testing.T) { | ||
type fields struct { | ||
es *escapeSequence | ||
maxWidths []int | ||
orgWidths []int | ||
WidthF bool | ||
delimiter string | ||
delimiterReg *regexp.Regexp | ||
count int | ||
} | ||
type args struct { | ||
st *parseState | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want bool | ||
wantStr string | ||
}{ | ||
{ | ||
name: "convertAlignDelm", | ||
fields: fields{ | ||
es: newESConverter(), | ||
maxWidths: []int{1, 2}, | ||
WidthF: false, | ||
delimiter: ",", | ||
count: 0, | ||
}, | ||
args: args{ | ||
st: &parseState{ | ||
lc: StrToContents("a,b,c\n", 8), | ||
mainc: '\n', | ||
}, | ||
}, | ||
want: false, | ||
wantStr: "a ,b ,c\n", | ||
}, | ||
{ | ||
name: "convertAlignWidth", | ||
fields: fields{ | ||
es: newESConverter(), | ||
maxWidths: []int{3, 3}, | ||
orgWidths: []int{2, 5}, | ||
WidthF: true, | ||
count: 0, | ||
}, | ||
args: args{ | ||
st: &parseState{ | ||
lc: StrToContents("a b c\n", 8), | ||
mainc: '\n', | ||
}, | ||
}, | ||
want: false, | ||
wantStr: "a b c\n", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
a := &align{ | ||
es: tt.fields.es, | ||
maxWidths: tt.fields.maxWidths, | ||
orgWidths: tt.fields.orgWidths, | ||
WidthF: tt.fields.WidthF, | ||
delimiter: tt.fields.delimiter, | ||
delimiterReg: tt.fields.delimiterReg, | ||
count: tt.fields.count, | ||
} | ||
if got := a.convert(tt.args.st); got != tt.want { | ||
t.Errorf("align.convert() = %v, want %v", got, tt.want) | ||
} | ||
goStr, _ := ContentsToStr(tt.args.st.lc) | ||
if goStr != tt.wantStr { | ||
t.Errorf("align.convert() = %v, want %v", goStr, tt.wantStr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package oviewer | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_rawConverter_convert(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
r rawConverter | ||
st *parseState | ||
str string | ||
want bool | ||
wantStr string | ||
}{ | ||
{ | ||
name: "convertABC", | ||
r: *newRawConverter(), | ||
str: "abc", | ||
st: &parseState{ | ||
mainc: '\n', | ||
}, | ||
want: false, | ||
wantStr: "abc", | ||
}, | ||
{ | ||
name: "convertEscape", | ||
r: *newRawConverter(), | ||
str: "abc", | ||
st: &parseState{ | ||
mainc: 0x1b, | ||
}, | ||
want: true, | ||
wantStr: "abc^[", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt.st.lc = StrToContents(tt.str, tt.st.tabWidth) | ||
if got := tt.r.convert(tt.st); got != tt.want { | ||
t.Errorf("rawConverter.convert() = %v, want %v", got, tt.want) | ||
} | ||
gotStr, _ := ContentsToStr(tt.st.lc) | ||
if !reflect.DeepEqual(gotStr, tt.wantStr) { | ||
t.Errorf("rawConverter.convert() = %v, want %v", gotStr, tt.wantStr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
a,1234,c,d | ||
|
||
d,e,f,g | ||
g,h,i,j | ||
a,"b,c",d,k | ||
a,b"c,d,l |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
id name age | ||
1 tsst 21 | ||
2 test2 20 | ||
123 test3 123 |