-
Notifications
You must be signed in to change notification settings - Fork 11
/
rdf_test.go
77 lines (66 loc) · 3.68 KB
/
rdf_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
package triplestore
import (
"testing"
)
func TestEquality(t *testing.T) {
emptyTriple := new(triple)
tcases := []struct {
one, other Triple
exp bool
}{
{one: SubjPred("", "").Resource(""), other: SubjPred("", "").Resource(""), exp: true},
{one: SubjPred("sub", "pred").Resource("Bonobo"), other: SubjPred("sub", "pred").Resource("Bonobo"), exp: true},
{one: SubjPred("sub", "pred").Resource("Bonobo"), other: SubjPred("sub", "pred").Resource("Banaba"), exp: false},
{one: SubjPred("sub", "pred").Resource("Bonobo"), other: SubjPred("sub", "newpred").Resource("Bonobo"), exp: false},
{one: SubjPred("sub", "pred").Resource("Bonobo"), other: SubjPred("newsub", "pred").Resource("Bonobo"), exp: false},
{one: SubjPred("sub", "pred").StringLiteral("Bonobo"), other: SubjPred("sub", "pred").StringLiteral("Bonobo"), exp: true},
{one: SubjPred("sub", "pred").BooleanLiteral(true), other: SubjPred("sub", "pred").BooleanLiteral(true), exp: true},
{one: SubjPred("sub", "pred").IntegerLiteral(42), other: SubjPred("sub", "pred").IntegerLiteral(42), exp: true},
{one: SubjPred("", "").StringLiteral(""), other: SubjPred("", "").StringLiteral(""), exp: true},
{one: SubjPred("sub", "pred").Resource("Bonobo"), other: SubjPred("sub", "pred").StringLiteral("Bonobo"), exp: false},
{one: SubjPred("sub", "pred").StringLiteral("true"), other: SubjPred("sub", "pred").BooleanLiteral(true), exp: false},
{one: SubjPred("sub", "pred").StringLiteral("2"), other: SubjPred("sub", "pred").IntegerLiteral(2), exp: false},
// langtag
{one: SubjPred("sub", "pred").StringLiteralWithLang("obj", "en"), other: SubjPred("sub", "pred").StringLiteralWithLang("obj", "fr"), exp: false},
{one: SubjPred("sub", "pred").StringLiteralWithLang("obj", "en"), other: SubjPred("sub", "pred").StringLiteralWithLang("obj", "en"), exp: true},
{one: SubjPred("sub", "pred").Resource("Bonobo"), other: emptyTriple, exp: false},
{one: emptyTriple, other: emptyTriple, exp: true},
}
for i, tcase := range tcases {
if got, want := tcase.one.Equal(tcase.other), tcase.exp; got != want {
t.Errorf("%d: got %t, want %t", i+1, got, want)
}
if got, want := tcase.other.Equal(tcase.one), tcase.exp; got != want {
t.Errorf("%d: got %t, want %t", i, got, want)
}
}
}
func TestTripleKey(t *testing.T) {
tcases := []struct {
one *triple
exp string
}{
{one: SubjPred("", "").Resource(""), exp: "<><><>"},
{one: SubjPred("", "").StringLiteral(""), exp: "<><>\"\"^^<xsd:string>"},
{one: SubjPred("sub", "pred").Resource("Bonobo"), exp: "<sub><pred><Bonobo>"},
{one: SubjPred("su<b", "pr>ed").Resource("Bonobo"), exp: "<su<b><pr>ed><Bonobo>"},
{one: SubjPred("sub", "pred").StringLiteral("Bonobo"), exp: "<sub><pred>\"Bonobo\"^^<xsd:string>"},
{one: SubjPred("sub", "pred").BooleanLiteral(true), exp: "<sub><pred>\"true\"^^<xsd:boolean>"},
{one: SubjPred("sub", "pred").StringLiteral("true"), exp: "<sub><pred>\"true\"^^<xsd:string>"},
{one: SubjPred("sub", "pred").IntegerLiteral(42), exp: "<sub><pred>\"42\"^^<xsd:integer>"},
{one: SubjPred("sub", "pred").StringLiteral("42"), exp: "<sub><pred>\"42\"^^<xsd:string>"},
// bnodes
{one: BnodePred("", "").Resource(""), exp: "_:<><>"},
{one: BnodePred("", "").StringLiteral(""), exp: "_:<>\"\"^^<xsd:string>"},
{one: BnodePred("sub", "pred").Resource("Bonobo"), exp: "_:sub<pred><Bonobo>"},
{one: SubjPred("", "").Bnode(""), exp: "<><>_:"},
{one: SubjPred("", "").Bnode("any"), exp: "<><>_:any"},
// langtag
{one: SubjPred("sub", "pred").StringLiteralWithLang("obj", "en"), exp: "<sub><pred>\"obj\"@en"},
}
for i, tcase := range tcases {
if got, want := tcase.one.key(), tcase.exp; got != want {
t.Errorf("%d: got %s, want %s", i+1, got, want)
}
}
}