Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dgraph
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
dgraph
Commits
00e88fea
Commit
00e88fea
authored
9 years ago
by
Manish R Jain
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for parser
parent
1d92022e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
rdf/parse.go
+11
-0
11 additions, 0 deletions
rdf/parse.go
rdf/parse_test.go
+57
-1
57 additions, 1 deletion
rdf/parse_test.go
rdf/state.go
+8
-1
8 additions, 1 deletion
rdf/state.go
with
76 additions
and
2 deletions
rdf/parse.go
+
11
−
0
View file @
00e88fea
...
...
@@ -45,6 +45,7 @@ func Parse(line string) (rnq NQuad, rerr error) {
l
:=
lex
.
NewLexer
(
line
)
go
run
(
l
)
var
oval
string
var
vend
bool
for
item
:=
range
l
.
Items
{
if
item
.
Typ
==
itemSubject
{
rnq
.
Subject
=
stripBracketsIfPresent
(
item
.
Val
)
...
...
@@ -62,12 +63,22 @@ func Parse(line string) (rnq NQuad, rerr error) {
rnq
.
Language
=
item
.
Val
}
if
item
.
Typ
==
itemObjectType
{
// TODO: Strictly parse common types like integers, floats etc.
if
len
(
oval
)
==
0
{
glog
.
Fatalf
(
"itemObject should be emitted before itemObjectType. Input: %q"
,
line
)
}
oval
+=
"@@"
+
stripBracketsIfPresent
(
item
.
Val
)
}
if
item
.
Typ
==
lex
.
ItemError
{
return
rnq
,
fmt
.
Errorf
(
item
.
Val
)
}
if
item
.
Typ
==
itemValidEnd
{
vend
=
true
}
}
if
!
vend
{
return
rnq
,
fmt
.
Errorf
(
"Invalid end of input"
)
}
if
len
(
oval
)
>
0
{
rnq
.
ObjectValue
=
oval
...
...
This diff is collapsed.
Click to expand it.
rdf/parse_test.go
+
57
−
1
View file @
00e88fea
...
...
@@ -100,6 +100,56 @@ var testNQuads = []struct {
ObjectValue
:
nil
,
},
},
{
input
:
"_:alice ."
,
hasErr
:
true
,
},
{
input
:
"_:alice knows ."
,
hasErr
:
true
,
},
{
input
:
`_:alice "knows" stuff .`
,
hasErr
:
true
,
},
{
input
:
"_:alice <knows> stuff ."
,
hasErr
:
true
,
},
{
input
:
"_:alice <knows> <stuff>"
,
hasErr
:
true
,
},
{
input
:
`"_:alice" <knows> <stuff> .`
,
hasErr
:
true
,
},
{
input
:
`_:alice <knows> "stuff .`
,
hasErr
:
true
,
},
{
input
:
`_:alice <knows> "stuff"@-en .`
,
hasErr
:
true
,
},
{
input
:
`_:alice <knows> "stuff"^<string> .`
,
hasErr
:
true
,
},
{
input
:
`_:alice <knows> "stuff"^^xs:string .`
,
hasErr
:
true
,
},
{
input
:
`_:alice <knows> "stuff"^^<xs:string> .`
,
nq
:
NQuad
{
Subject
:
"_:alice"
,
Predicate
:
"knows"
,
ObjectId
:
""
,
ObjectValue
:
"stuff@@xs:string"
,
},
hasErr
:
false
,
},
}
func
TestLex
(
t
*
testing
.
T
)
{
...
...
@@ -107,9 +157,15 @@ func TestLex(t *testing.T) {
rnq
,
err
:=
Parse
(
test
.
input
)
if
test
.
hasErr
{
if
err
==
nil
{
t
.
Errorf
(
"Expected error for input: %q"
,
test
.
input
)
t
.
Errorf
(
"Expected error for input: %q. Output: %+v"
,
test
.
input
,
rnq
)
}
continue
}
else
{
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
}
if
!
reflect
.
DeepEqual
(
rnq
,
test
.
nq
)
{
t
.
Errorf
(
"Expected %v. Got: %v"
,
test
.
nq
,
rnq
)
}
...
...
This diff is collapsed.
Click to expand it.
rdf/state.go
+
8
−
1
View file @
00e88fea
...
...
@@ -32,6 +32,7 @@ const (
itemLiteral
// literal, 10
itemLanguage
// language, 11
itemObjectType
// object type, 12
itemValidEnd
// end with dot, 13
)
const
(
...
...
@@ -82,7 +83,13 @@ Loop:
l
.
Emit
(
itemText
)
return
lexObject
case
r
==
'.'
||
r
==
lex
.
EOF
:
case
r
==
lex
.
EOF
:
break
Loop
case
r
==
'.'
:
if
l
.
Depth
>
AT_OBJECT
{
l
.
Emit
(
itemValidEnd
)
}
break
Loop
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment