Debian Codegraph @

rdfloader/parser/node_test.go

raw symbols SCIP
1 package parser
2
3 import (
4 "testing"
5 )
6
7 func TestBlankNodeGetter_Get(t *testing.T) {
8 // default blank node getter:
9 blankNodeGetter := BlankNodeGetter{}
10
11 // by default, node id starts with N1.
12 firstBlankNode := blankNodeGetter.Get()
13 if firstBlankNode.ID != "N1" {
14 t.Errorf("expected first node to be N1, found %v", firstBlankNode.ID)
15 }
16 if nodeType := firstBlankNode.NodeType; nodeType != BLANK {
17 t.Errorf("blank node must be of type %v. Found %v", BLANK, nodeType)
18 }
19
20 secondBlankNode := blankNodeGetter.Get()
21 if secondBlankNode.ID != "N2" {
22 t.Errorf("expected node to be N2, found %v", secondBlankNode.ID)
23 }
24
25 // blank node getter with custom lastid.
26 blankNodeGetter = BlankNodeGetter{
27 lastid: -1,
28 }
29 // last id -1 means that first node should start from N0
30 firstBlankNode = blankNodeGetter.Get()
31 if firstBlankNode.ID != "N0" {
32 t.Errorf("Expected node to be %v, found %v", "N0", firstBlankNode.ID)
33 }
34 }
35
36 func TestBlankNodeGetter_GetFromId(t *testing.T) {
37 // default blank node getter:
38 getter := BlankNodeGetter{} // id starts with 1
39 blankNode := getter.Get()
40
41 if blankNode.ID != "N1" {
42 t.Errorf("expected first node's id to be N1, found %v", blankNode.ID)
43 }
44
45 blankNodeA0 := getter.GetFromId("A0")
46 if blankNodeA0.ID != "NA0" {
47 t.Errorf("expected first node's id to be NA0, found %v", blankNodeA0.ID)
48 }
49 }
50
51 func TestNode_String(t *testing.T) {
52 // a node is wrapped in a tuple with (NodeType, ID)
53 node := Node{
54 BLANK,
55 "",
56 }
57 if node.String() != "(BNODE, )" {
58 t.Errorf("String representation of blank node with empty id should be (BNODE, ). Found %v", node.String())
59 }
60 }