|
1
|
|
|
package writers |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"encoding/json" |
|
5
|
|
|
"fmt" |
|
6
|
|
|
"github.com/vvval/go-metadata-scanner/vars" |
|
7
|
|
|
"github.com/vvval/go-metadata-scanner/vars/metadata" |
|
8
|
|
|
"reflect" |
|
9
|
|
|
"testing" |
|
10
|
|
|
) |
|
11
|
|
|
|
|
12
|
|
|
func TestPackLine(t *testing.T) { |
|
13
|
|
|
type check struct { |
|
14
|
|
|
f vars.File |
|
15
|
|
|
groups []string |
|
16
|
|
|
exp map[string]map[string]string |
|
17
|
|
|
ok bool |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
set := []check{ |
|
21
|
|
|
{ |
|
22
|
|
|
vars.NewFile("file1.jpg", metadata.Tags{"test:tag": "some test tag", "XMP:tag1": "xmp tag1", "XMP:tag2": "xmp tag2", "iptc:tag3": "iptc tag3"}), |
|
23
|
|
|
[]string{"filename", "XMP", "iptc"}, |
|
24
|
|
|
map[string]map[string]string{"XMP": {"tag1": "xmp tag1", "tag2": "xmp tag2"}, "iptc": {"tag3": "iptc tag3"}}, |
|
25
|
|
|
true, |
|
26
|
|
|
}, |
|
27
|
|
|
{ |
|
28
|
|
|
vars.NewFile("file2.png", metadata.Tags{"test:tag": "some test tag", "XMP:tag1": "xmp tag1", "XMP:tag2": "xmp tag2", "iptc:tag2": "iptc tag2"}), |
|
29
|
|
|
[]string{"filename", "XMP", "iptc"}, |
|
30
|
|
|
map[string]map[string]string{"xmp": {"tag1": "xmp tag1"}, "IPTC": {"tag2": "iptc tag2"}}, |
|
31
|
|
|
false, |
|
32
|
|
|
}, |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
//Case sensitive comparison |
|
36
|
|
|
for i, s := range set { |
|
37
|
|
|
p := packCSVLine(&s.f, s.groups) |
|
38
|
|
|
fmt.Printf("ppp %+v\n", p) |
|
39
|
|
|
exp := convertMap(s.exp) |
|
40
|
|
|
if !reflect.DeepEqual(p[1:], exp) && s.ok { |
|
41
|
|
|
t.Errorf("grouping tags failed (line `%d`) (wrong inequality):\ngot `%v`\nexpected `%t` `%v`", i, p, s.ok, exp) |
|
42
|
|
|
} else if reflect.DeepEqual(p[1:], exp) && !s.ok { |
|
43
|
|
|
t.Errorf("grouping tags failed (line `%d`) (wrong equality):\ngot `%v`\nexpected `%t` `%v`", i, p, s.ok, exp) |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
func convertMap(i map[string]map[string]string) []string { |
|
49
|
|
|
var o []string |
|
50
|
|
|
for _, v := range i { |
|
51
|
|
|
s, _ := json.Marshal(v) |
|
52
|
|
|
o = append(o, string(s)) |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return o |
|
56
|
|
|
} |
|
57
|
|
|
|