-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocument_test.go
106 lines (91 loc) · 1.81 KB
/
document_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package ps
import (
"log"
"os"
"path/filepath"
"reflect"
"runtime"
"testing"
)
// wd is the working directory
var wd string
func init() {
_, file, _, ok := runtime.Caller(0)
if !ok {
log.Fatal("runtime.Caller(0) returned !ok")
}
wd = filepath.Dir(file)
f, err := os.Create("test.log")
if err != nil {
log.Fatal(err)
}
log.SetOutput(f)
}
func TestDocument_Dump(t *testing.T) {
// Must be true for test to be valid.
Mode = Normal
tests := []struct {
name string
}{
{"Test"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Get rid of old Dump.
os.Remove(filepath.Join(wd, tt.name+".json"))
// Generate a fresh Doc (loaded slowly).
want, err := Open(filepath.Join(wd, tt.name+".psd"))
if err != nil {
t.Fatal(err)
}
// Dump the contents.
want.Dump()
// Grab a new version of the doc (loaded from json).
got, err := Open(filepath.Join(wd, tt.name+".psd"))
if err != nil {
t.Fatal(err)
}
got.layerSets[0].current = true
if !reflect.DeepEqual(got, want) {
t.Errorf("wanted: %+v\ngot: %+v", want, got)
}
})
}
}
func TestDocument_Save(t *testing.T) {
file := filepath.Join(wd, "Test.psd")
d, err := Open(file)
if err != nil {
t.Fatal(err)
}
layerName := "Group 1"
lyr := d.LayerSet(layerName)
if lyr == nil {
t.Fatalf("LayerSet '%s' was not found", layerName)
}
// Change a layer name.
_, err = DoJS(filepath.Join("SetName"), JSLayer(lyr.Path()), "Group 2")
if err != nil {
t.Error(err)
}
defer func() {
if err = DoAction("DK", "Undo"); err != nil {
t.Error(err)
}
err = d.Save()
if err != nil {
t.Fatal(err)
}
}()
err = d.Save()
if err != nil {
t.Fatal(err)
}
d2, err := Open(file)
if err != nil {
t.Fatal(err)
}
if reflect.DeepEqual(d, d2) {
t.Errorf("wanted: %+v\ngot: %+v", d, d2)
}
}