-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfile_test.go
63 lines (47 loc) · 1.24 KB
/
file_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
package figma
import (
"io/ioutil"
"os"
"testing"
)
func TestUnmarshalFile(t *testing.T) {
jsonFile, err := os.Open("testdata/file.json")
// if we os.Open returns an error then handle it
if err != nil {
t.Errorf("test failed with unexpected reason")
}
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
byteValue, err := ioutil.ReadAll(jsonFile)
if err != nil {
t.Errorf("test failed with unexpected reason")
}
f, err := UnmarshalFile(byteValue)
if f.Name != "App Colors" {
t.Errorf("test failed")
}
d := f.Document
if d.Children[0].Name != "Page 1" {
t.Errorf("test failed")
}
}
func TestUnmarshalNode(t *testing.T) {
jsonFile, err := os.Open("testdata/filenode.json")
// if we os.Open returns an error then handle it
if err != nil {
t.Errorf("test failed with unexpected reason")
}
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
byteValue, err := ioutil.ReadAll(jsonFile)
if err != nil {
t.Errorf("test failed with unexpected reason")
}
f, err := UnmarshalFileNodes(byteValue)
if f.Name != "App Colors" {
t.Errorf("test failed")
}
if f.Nodes["1:2"].Styles["2:2"].Key != "12345678910" {
t.Errorf("invalid key value")
}
}