-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_test.go
58 lines (54 loc) · 1.17 KB
/
node_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
package rdf
import (
"encoding/json"
"fmt"
"testing"
)
const (
exampleURI = "https://example.org/"
exampleBlankNode = "_:example"
)
func TestFromObject_blankNode(t *testing.T) {
for _, test := range []string{
fmt.Sprintf("%q", exampleBlankNode),
fmt.Sprintf(`{ "@id": %q }`, exampleBlankNode),
} {
var m any
if err := json.Unmarshal([]byte(test), &m); err != nil {
t.Fatal(err)
}
n, err := fromObject(m, false)
if err != nil {
t.Fatal(err)
}
bn, ok := n.(*BlankNode)
if !ok {
t.Errorf("expected BlankNode, got %T", n)
}
if bn.Attribute != exampleBlankNode {
t.Errorf("expected %q, got %q", exampleBlankNode, bn.Attribute)
}
}
}
func TestFromObject_iriReference(t *testing.T) {
for _, test := range []string{
fmt.Sprintf("%q", exampleURI),
fmt.Sprintf(`{ "@id": %q }`, exampleURI),
} {
var m any
if err := json.Unmarshal([]byte(test), &m); err != nil {
t.Fatal(err)
}
n, err := fromObject(m, false)
if err != nil {
t.Fatal(err)
}
r, ok := n.(*IRIReference)
if !ok {
t.Errorf("expected IRIReference, got %T", n)
}
if r.Value != exampleURI {
t.Errorf("expected %q, got %q", exampleURI, r.Value)
}
}
}