| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package writers |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "github.com/vvval/go-metadata-scanner/vars" |
||
| 5 | "github.com/vvval/go-metadata-scanner/vars/metadata" |
||
| 6 | "reflect" |
||
| 7 | "testing" |
||
| 8 | ) |
||
| 9 | |||
| 10 | func TestTagsByGroups(t *testing.T) { |
||
| 11 | type check struct { |
||
| 12 | f vars.File |
||
| 13 | groups []string |
||
| 14 | exp map[string]map[string]string |
||
| 15 | ok bool |
||
| 16 | } |
||
| 17 | |||
| 18 | set := []check{ |
||
| 19 | { |
||
| 20 | vars.NewFile("", metadata.Tags{"test:tag": "some test tag", "XMP:tag1": "xmp tag1", "iptc:tag2": "iptc tag2"}), |
||
| 21 | []string{"xmp", "iptc"}, |
||
| 22 | map[string]map[string]string{"XMP": {"tag1": "xmp tag1"}, "iptc": {"tag2": "iptc tag2"}}, |
||
| 23 | true, |
||
| 24 | }, |
||
| 25 | { |
||
| 26 | vars.NewFile("", metadata.Tags{"test:tag": "some test tag", "XMP:tag1": "xmp tag1", "iptc:tag2": "iptc tag2"}), |
||
| 27 | []string{"xmp", "iptc"}, |
||
| 28 | map[string]map[string]string{"xmp": {"tag1": "xmp tag1"}, "IPTC": {"tag2": "iptc tag2"}}, |
||
| 29 | false, |
||
| 30 | }, |
||
| 31 | } |
||
| 32 | |||
| 33 | //Case sensitive comparison |
||
| 34 | for i, s := range set { |
||
| 35 | c := tagsByGroups(&s.f, s.groups) |
||
| 36 | if !reflect.DeepEqual(c, s.exp) && s.ok { |
||
| 37 | t.Errorf("grouping tags failed (line `%d`) (wrong inequality):\ngot `%v`\nexpected `%t` `%v`", i, c, s.ok, s.exp) |
||
| 38 | } else if reflect.DeepEqual(c, s.exp) && !s.ok { |
||
| 39 | t.Errorf("grouping tags failed (line `%d`) (wrong equality):\ngot `%v`\nexpected `%t` `%v`", i, c, s.ok, s.exp) |
||
| 40 | } |
||
| 43 |