-
Notifications
You must be signed in to change notification settings - Fork 0
/
crossref_test.go
83 lines (79 loc) · 2.14 KB
/
crossref_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
package eprinttools
import (
"io/ioutil"
"testing"
)
func TestCrossRefWorksToEPrint(t *testing.T) {
t.Errorf("TestCrossRefWorksToEPrints() not implemented")
}
func TestIssue35(t *testing.T) {
doi := `10.1093/mnras/stab2505`
testFile := `srctest/issue-35.json`
src, err := ioutil.ReadFile(testFile)
if err != nil {
t.Errorf(`Missing %q, %s`, testFile, err)
t.FailNow()
}
obj := make(map[string]interface{})
err = jsonDecode(src, &obj)
if err != nil {
t.Errorf(`Failed to unmarhsal %q, %s`, testFile, err)
t.FailNow()
}
eprint, err := CrossRefWorksToEPrint(obj)
if err != nil {
t.Errorf(`Expected to crosswalk CrossRef for %q, %s`, doi, err)
t.FailNow()
}
if eprint == nil {
t.Errorf(`Should have a EPrint data structure populated.`)
t.FailNow()
}
if eprint.Abstract == `` {
t.Errorf(`Expected to have Abstract populated for %q`, doi)
}
if eprint.Subjects == nil || eprint.Subjects.Length() == 0 {
t.Errorf(`Should have subjects populated for %q`, doi)
}
if eprint.Subjects.Length() != 2 {
t.Errorf(`Expected 2 subjects for doi %q, got %d`, doi, eprint.Subjects.Length())
}
}
func TestIssue36(t *testing.T) {
doi := `10.1093/mnras/stab2505`
testFile := `srctest/issue-35.json`
src, err := ioutil.ReadFile(testFile)
if err != nil {
t.Errorf(`Missing %q, %s`, testFile, err)
t.FailNow()
}
obj := make(map[string]interface{})
err = jsonDecode(src, &obj)
if err != nil {
t.Errorf(`Failed to unmarhsal %q, %s`, testFile, err)
t.FailNow()
}
eprint, err := CrossRefWorksToEPrint(obj)
if err != nil {
t.Errorf(`Expected to crosswalk CrossRef for %q, %s`, doi, err)
t.FailNow()
}
if eprint == nil {
t.Errorf(`Should have a EPrint data structure populated.`)
t.FailNow()
}
if eprint.Funders == nil || eprint.Funders.Length() == 0 {
t.Errorf(`Missing funders for %q`, doi)
t.FailNow()
}
// Expected two National Science foundation grant numbers
cnt := 0 // fount the grant numbers found for NSF
for _, item := range eprint.Funders.Items {
if item.Agency == `National Science Foundation` && item.GrantNumber != `` {
cnt++
}
}
if cnt != 2 {
t.Errorf(`Execpted 2 grant number entry for NSF, got %d`, cnt)
}
}