| 1 |
package segment |
| 2 |
|
| 3 |
import ( |
| 4 |
"reflect" |
| 5 |
"testing" |
| 6 |
) |
| 7 |
|
| 8 |
func Test_ExtractElements(t *testing.T) { |
| 9 |
type testData struct { |
| 10 |
in string |
| 11 |
out []string |
| 12 |
err error |
| 13 |
} |
| 14 |
tests := []testData{ |
| 15 |
{ |
| 16 |
"abcde+123+012+de+'", |
| 17 |
[]string{ |
| 18 |
"abcde", |
| 19 |
"123", |
| 20 |
"012", |
| 21 |
"de", |
| 22 |
}, |
| 23 |
nil, |
| 24 |
}, |
| 25 |
{ |
| 26 |
"abcde:123:012+de+'", |
| 27 |
[]string{ |
| 28 |
"abcde:123:012", |
| 29 |
"de", |
| 30 |
}, |
| 31 |
nil, |
| 32 |
}, |
| 33 |
} |
| 34 |
|
| 35 |
for _, test := range tests { |
| 36 |
extracted, err := ExtractElements([]byte(test.in)) |
| 37 |
|
| 38 |
if err != nil { |
| 39 |
t.Logf("Expected no error, got %T:%v\n", err, err) |
| 40 |
t.Fail() |
| 41 |
} |
| 42 |
|
| 43 |
if extracted == nil { |
| 44 |
t.Logf("Expected result not to be nil\n") |
| 45 |
t.Fail() |
| 46 |
} |
| 47 |
|
| 48 |
actual := make([]string, len(extracted)) |
| 49 |
for i, b := range extracted { |
| 50 |
actual[i] = string(b) |
| 51 |
} |
| 52 |
|
| 53 |
if !reflect.DeepEqual(test.out, actual) { |
| 54 |
t.Logf("Extract: \n%q\n", extracted) |
| 55 |
t.Logf("Expected result to equal\n%q\n\tgot\n%q\n", test.out, actual) |
| 56 |
t.Fail() |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
} |