aboutsummaryrefslogtreecommitdiffstats
path: root/skate/unstructured_test.go
blob: 1727430e14e9c412d3305b68cc506b5a2a127f9e (plain)
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
package skate

import (
	"reflect"
	"testing"
)

func TestParseUnstructured(t *testing.T) {
	// XXX: add more cases, maybe move this into files.
	var cases = []struct {
		ref    *Ref
		result *Ref
		err    error
	}{
		{
			&Ref{
				Biblio: Biblio{
					Unstructured: "Hello 10.1111/j.1550-7408.1968.tb02138.x-BIB5",
				},
			},
			&Ref{
				Biblio: Biblio{
					DOI:          "10.1111/j.1550-7408.1968.tb02138.x-bib5",
					Unstructured: "Hello 10.1111/j.1550-7408.1968.tb02138.x-BIB5",
				},
			},
			nil,
		},
		{
			&Ref{
				Biblio: Biblio{
					Unstructured: "https://arxiv.org/pdf/0808.3320v3.pdf Hello 10.1111/j.1550-7408.1968.tb02138.x-BIB5",
				},
			},
			&Ref{
				Biblio: Biblio{
					ArxivId:      "0808.3320",
					DOI:          "10.1111/j.1550-7408.1968.tb02138.x-bib5",
					Unstructured: "https://arxiv.org/pdf/0808.3320v3.pdf Hello 10.1111/j.1550-7408.1968.tb02138.x-BIB5",
				},
			},
			nil,
		},
	}
	for _, c := range cases {
		err := ParseUnstructured(c.ref)
		if err != c.err {
			t.Fatalf("got %v, want %v", err, c.err)
		}
		if !reflect.DeepEqual(c.ref, c.result) {
			t.Fatalf("got %#v, want %#v", c.ref, c.result)
		}
	}
}

func BenchmarkParseUnstructured(b *testing.B) {
	ref := Ref{
		Biblio: Biblio{
			Unstructured: "https://arxiv.org/pdf/0808.3320v3.pdf Hello 10.1111/j.1550-7408.1968.tb02138.x-BIB5",
		},
	}
	for n := 0; n < b.N; n++ {
		ParseUnstructured(&ref)
	}
}