| 1 |
package gherkin |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/stretchr/testify/assert" |
| 7 |
) |
| 8 |
|
| 9 |
func TestStringDataToTable(t *testing.T) { |
| 10 |
s := StringData("| a | b |\n| 1 | 2 |\n| 3 | 4 |") |
| 11 |
tab := TabularData{ |
| 12 |
[]string{"a", "b"}, |
| 13 |
[]string{"1", "2"}, |
| 14 |
[]string{"3", "4"}, |
| 15 |
} |
| 16 |
|
| 17 |
assert.Equal(t, tab, s.ToTable()) |
| 18 |
} |
| 19 |
|
| 20 |
func TestTabularDataToMap(t *testing.T) { |
| 21 |
tab := TabularData{ |
| 22 |
[]string{"a", "b", "c", "d"}, |
| 23 |
[]string{"1", "2", "3", "4"}, |
| 24 |
[]string{"5", "6", "7", "8"}, |
| 25 |
[]string{"9", "A", "B", "C"}, |
| 26 |
} |
| 27 |
|
| 28 |
m := TabularDataMap{ |
| 29 |
"a": []string{"1", "5", "9"}, |
| 30 |
"b": []string{"2", "6", "A"}, |
| 31 |
"c": []string{"3", "7", "B"}, |
| 32 |
"d": []string{"4", "8", "C"}, |
| 33 |
} |
| 34 |
|
| 35 |
assert.Equal(t, m, tab.ToMap()) |
| 36 |
assert.Equal(t, 3, m.NumRows()) |
| 37 |
} |
| 38 |
|
| 39 |
func TestTabularDataMapEmpty(t *testing.T) { |
| 40 |
var tab TabularData |
| 41 |
var m TabularDataMap |
| 42 |
|
| 43 |
// only headers |
| 44 |
tab = TabularData{[]string{"a", "b", "c", "d"}} |
| 45 |
m = TabularDataMap{} |
| 46 |
assert.Equal(t, m, tab.ToMap()) |
| 47 |
assert.Equal(t, 0, m.NumRows()) |
| 48 |
|
| 49 |
// completely empty |
| 50 |
tab = TabularData{} |
| 51 |
m = TabularDataMap{} |
| 52 |
assert.Equal(t, m, tab.ToMap()) |
| 53 |
assert.Equal(t, 0, m.NumRows()) |
| 54 |
} |
| 55 |
|
| 56 |
func TestScenarioFilters(t *testing.T) { |
| 57 |
f := &Feature{Tags: []string{}} |
| 58 |
s := Scenario{Tags: []string{"@a", "@b"}} |
| 59 |
assert.True(t, s.FilterMatched(f)) |
| 60 |
assert.False(t, s.FilterMatched(f, "a")) |
| 61 |
assert.True(t, s.FilterMatched(f, "@a")) |
| 62 |
assert.True(t, s.FilterMatched(f, "@c", "@a")) |
| 63 |
assert.False(t, s.FilterMatched(f, "~@a")) |
| 64 |
assert.False(t, s.FilterMatched(f, "@a,@c")) |
| 65 |
assert.True(t, s.FilterMatched(f, "@a,@b", "@c")) |
| 66 |
|
| 67 |
s = Scenario{Tags: []string{}} |
| 68 |
assert.False(t, s.FilterMatched(f, "@a")) |
| 69 |
} |
| 70 |
|
| 71 |
func TestFeatureFilters(t *testing.T) { |
| 72 |
s := Feature{Tags: []string{"@a", "@b"}} |
| 73 |
assert.True(t, s.FilterMatched()) |
| 74 |
assert.False(t, s.FilterMatched("a")) |
| 75 |
assert.True(t, s.FilterMatched("@a")) |
| 76 |
assert.True(t, s.FilterMatched("@c", "@a")) |
| 77 |
assert.False(t, s.FilterMatched("~@a")) |
| 78 |
assert.False(t, s.FilterMatched("@a,@c")) |
| 79 |
assert.True(t, s.FilterMatched("@a,@b", "@c")) |
| 80 |
} |