-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
82 lines (74 loc) · 1.68 KB
/
parser_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
package csljson
import (
"encoding/json"
"fmt"
"testing"
)
// func TestParseFile(t *testing.T) {
// tests := []struct {
// path string
// wantErr bool
// title string //tests info.title
// citationPrefix string
// }{
// {"styles/apa-6th-edition.csl", false, "American Psychological Association 6th edition", "("},
// }
// for _, tt := range tests {
// t.Run(tt.path, func(t *testing.T) {
// s, err := ParseFile(tt.path)
// if (err != nil) != tt.wantErr {
// t.Errorf("ParseFile() error = %v, wantErr %v", err, tt.wantErr)
// }
// if s.Info.Title != tt.title {
// t.Errorf("ParseFile() wanted = %v, got %v", tt.title, s.Info.Title)
// }
// if s.Citation.Layout.Prefix != tt.citationPrefix {
// t.Errorf("ParseFile() wanted = %v, got %v", tt.citationPrefix, s.Citation.Layout.Prefix)
// }
// })
// }
// }
//ExampleParseFile tests parser against sample csljson files
func ExampleParseFile2() {
s, err := ParseFile("test/previews.json")
if err != nil {
fmt.Printf("ParseFile() error = %v", err)
return
}
fmt.Println(s.Items[0].DOI)
fmt.Println(s.Items[0].Author[0].Given)
fmt.Println(s.Items[0].Issued.DateParts[0][0])
// output:
// 10.1016/j.cub.2016.05.047
// Rumi
// 2016
}
// Variant json testing
type CustomerAddress struct {
Variable Variant `json:"variable"`
}
var js = []byte(`[
{
"variable": 55555
},
{
"variable": "55555"
},
{
"variable": true
},
{
"variable": null
},
{
"variable": ""
}
]`)
func TestVariantJson(t *testing.T) {
var addresses []CustomerAddress
err := json.Unmarshal(js, &addresses)
if err != nil {
t.Fatal(err)
}
fmt.Printf("addr : %#v\n", addresses)
}