Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefane Fermigier
neo
Commits
ef5d4305
Commit
ef5d4305
authored
Apr 28, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
1fb615dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
5 deletions
+111
-5
go/zodb/str.go
go/zodb/str.go
+59
-0
go/zodb/str_test.go
go/zodb/str_test.go
+52
-5
No files found.
go/zodb/str.go
View file @
ef5d4305
...
...
@@ -66,6 +66,16 @@ func (xid Xid) String() string {
return
xid
.
XTid
.
String
()
+
":"
+
xid
.
Oid
.
String
()
// XXX use "·" instead of ":" ?
}
/* TODO reenable
func (xtid XTid) XFmtString(b []byte) []byte {
b .C("=<"[bint(xtid.TidBefore)]) .V(xtid.Tid)
}
func (xid Xid) XFmtString(b xfmt.Buffer) xfmt.Buffer {
b .V(xid.XTid) .C(':') .V(xid.Oid)
}
*/
// parseHex64 decode 16-character-wide hex-encoded string into uint64
// XXX -> xfmt ?
...
...
@@ -93,6 +103,55 @@ func ParseOid(s string) (Oid, error) {
return
Oid
(
x
),
err
}
func
ParseXTid
(
s
string
)
(
XTid
,
error
)
{
if
len
(
s
)
<
1
{
goto
Error
}
{
var
tidBefore
bool
switch
s
[
0
]
{
case
'<'
:
tidBefore
=
true
case
'='
:
tidBefore
=
false
default
:
goto
Error
}
tid
,
err
:=
ParseTid
(
s
[
1
:
])
if
err
!=
nil
{
goto
Error
}
return
XTid
{
tid
,
tidBefore
},
nil
}
Error
:
return
XTid
{},
fmt
.
Errorf
(
"xtid %q invalid"
,
s
)
}
func
ParseXid
(
s
string
)
(
Xid
,
error
)
{
xtids
,
oids
,
err
:=
xstrings
.
Split2
(
s
,
":"
)
if
err
!=
nil
{
goto
Error
}
{
xtid
,
err1
:=
ParseXTid
(
xtids
)
oid
,
err2
:=
ParseOid
(
oids
)
if
err1
!=
nil
||
err2
!=
nil
{
goto
Error
}
return
Xid
{
xtid
,
oid
},
nil
}
Error
:
return
Xid
{},
fmt
.
Errorf
(
"xid %q invalid"
,
s
)
}
// ParseTidRange parses string of form "<tidmin>..<tidmax>" into tidMin, tidMax pair
// both <tidmin> and <tidmax> can be empty, in which case defaults 0 and TidMax are returned
// XXX also check tidMin < tidMax here? or allow reverse ranges ?
...
...
go/zodb/str_test.go
View file @
ef5d4305
...
...
@@ -19,6 +19,14 @@ package zodb
import
"testing"
// estr returns string corresponding to error or "" for nil
func
estr
(
err
error
)
string
{
if
err
==
nil
{
return
""
}
return
err
.
Error
()
}
func
TestParseHex64
(
t
*
testing
.
T
)
{
var
testv
=
[]
struct
{
in
string
;
out
uint64
;
estr
string
}
{
{
""
,
0
,
`tid "" invalid`
},
...
...
@@ -29,13 +37,52 @@ func TestParseHex64(t *testing.T) {
for
_
,
tt
:=
range
testv
{
x
,
err
:=
parseHex64
(
"tid"
,
tt
.
in
)
estr
:=
""
if
err
!=
nil
{
estr
=
err
.
Error
()
if
!
(
x
==
tt
.
out
&&
estr
(
err
)
==
tt
.
estr
)
{
t
.
Errorf
(
"parsehex64: %v: test error:
\n
have: %v %q
\n
want: %v %q"
,
tt
.
in
,
x
,
err
,
tt
.
out
,
tt
.
estr
)
}
}
}
func
TestParseXTid
(
t
*
testing
.
T
)
{
var
testv
=
[]
struct
{
in
string
;
xtid
XTid
;
estr
string
}
{
{
""
,
XTid
{},
`xtid "" invalid`
},
{
"a"
,
XTid
{},
`xtid "a" invalid`
},
{
"0123456789abcdef"
,
XTid
{},
`xtid "0123456789abcdef" invalid`
},
// XXX or let it be < by default ?
{
"z0123456789abcdef"
,
XTid
{},
`xtid "z0123456789abcdef" invalid`
},
{
"=0123456789abcdef"
,
XTid
{
0x0123456789abcdef
,
false
},
""
},
{
"<0123456789abcdef"
,
XTid
{
0x0123456789abcdef
,
true
},
""
},
}
for
_
,
tt
:=
range
testv
{
xtid
,
err
:=
ParseXTid
(
tt
.
in
)
if
!
(
xtid
==
tt
.
xtid
&&
estr
(
err
)
==
tt
.
estr
)
{
t
.
Errorf
(
"parsextid: %v: test error:
\n
have: %v %q
\n
want: %v %q"
,
tt
.
in
,
xtid
,
err
,
tt
.
xtid
,
tt
.
estr
)
}
}
}
if
!
(
x
==
tt
.
out
&&
estr
==
tt
.
estr
)
{
t
.
Errorf
(
"parsehex64: %v: test error:
\n
have: %v %q
\n
want: %v %q"
,
tt
.
in
,
x
,
estr
,
tt
.
out
,
tt
.
estr
)
func
TestParseXid
(
t
*
testing
.
T
)
{
var
testv
=
[]
struct
{
in
string
;
xid
Xid
;
estr
string
}
{
{
""
,
Xid
{},
`xid "" invalid`
},
{
"a"
,
Xid
{},
`xid "a" invalid`
},
{
"0123456789abcdef"
,
Xid
{},
`xid "0123456789abcdef" invalid`
},
// XXX or let it be < by default ?
{
"z0123456789abcdef"
,
Xid
{},
`xid "z0123456789abcdef" invalid`
},
{
"=0123456789abcdef"
,
Xid
{},
`xid "=0123456789abcdef" invalid`
},
{
"<0123456789abcdef"
,
Xid
{},
`xid "<0123456789abcdef" invalid`
},
{
"=0123456789abcdef|fedcba9876543210"
,
Xid
{},
`xid "=0123456789abcdef|fedcba9876543210" invalid`
},
{
"<0123456789abcdef|fedcba9876543210"
,
Xid
{},
`xid "<0123456789abcdef|fedcba9876543210" invalid`
},
{
"=0123456789abcdef:fedcba9876543210"
,
Xid
{
XTid
{
0x0123456789abcdef
,
false
},
0xfedcba9876543210
},
""
},
{
"<0123456789abcdef:fedcba9876543210"
,
Xid
{
XTid
{
0x0123456789abcdef
,
true
},
0xfedcba9876543210
},
""
},
}
for
_
,
tt
:=
range
testv
{
xid
,
err
:=
ParseXid
(
tt
.
in
)
if
!
(
xid
==
tt
.
xid
&&
estr
(
err
)
==
tt
.
estr
)
{
t
.
Errorf
(
"parsexid: %v: test error:
\n
have: %v %q
\n
want: %v %q"
,
tt
.
in
,
xid
,
err
,
tt
.
xid
,
tt
.
estr
)
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment