| 1 |
package swift |
| 2 |
|
| 3 |
import ( |
| 4 |
"reflect" |
| 5 |
"testing" |
| 6 |
) |
| 7 |
|
| 8 |
func TestTagExtractorExtract(t *testing.T) { |
| 9 |
tests := []struct { |
| 10 |
marshaled string |
| 11 |
result [][]byte |
| 12 |
}{ |
| 13 |
{ |
| 14 |
"\r\n:20:abcde\r\n:21:def\r\n-", |
| 15 |
[][]byte{ |
| 16 |
[]byte(":20:abcde"), |
| 17 |
[]byte(":21:def"), |
| 18 |
}, |
| 19 |
}, |
| 20 |
{ |
| 21 |
"\r\n:20:abc\r\nde\r\n:21:def\r\n-", |
| 22 |
[][]byte{ |
| 23 |
[]byte(":20:abc\r\nde"), |
| 24 |
[]byte(":21:def"), |
| 25 |
}, |
| 26 |
}, |
| 27 |
} |
| 28 |
for _, test := range tests { |
| 29 |
extractor := newTagExtractor([]byte(test.marshaled)) |
| 30 |
|
| 31 |
tags, err := extractor.Extract() |
| 32 |
|
| 33 |
if err != nil { |
| 34 |
t.Logf("Expected no error, got %T:%v\n", err, err) |
| 35 |
t.Fail() |
| 36 |
} |
| 37 |
|
| 38 |
if tags == nil { |
| 39 |
t.Logf("Expected tags not to be nil") |
| 40 |
t.Fail() |
| 41 |
} |
| 42 |
|
| 43 |
if !reflect.DeepEqual(test.result, tags) { |
| 44 |
t.Logf("Expected result to equal\n%q\n\tgot\n%q\n", test.result, tags) |
| 45 |
t.Fail() |
| 46 |
} |
| 47 |
} |
| 48 |
} |