Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
og-rek
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
og-rek
Commits
19945465
Commit
19945465
authored
Oct 07, 2012
by
Kamil Kisiel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
0 deletions
+95
-0
ogórek.go
ogórek.go
+0
-0
ogórek_test.go
ogórek_test.go
+95
-0
No files found.
ogórek.go
0 → 100644
View file @
19945465
This diff is collapsed.
Click to expand it.
ogórek_test.go
0 → 100644
View file @
19945465
package
ogórek
import
(
"bytes"
"math/big"
"reflect"
"testing"
)
func
bigInt
(
s
string
)
*
big
.
Int
{
i
:=
new
(
big
.
Int
)
i
.
SetString
(
s
,
10
)
return
i
}
func
equal
(
a
,
b
interface
{})
bool
{
if
reflect
.
TypeOf
(
a
)
!=
reflect
.
TypeOf
(
b
)
{
return
false
}
switch
a
.
(
type
)
{
case
[]
interface
{}
:
ia
:=
a
.
([]
interface
{})
ib
:=
b
.
([]
interface
{})
if
len
(
ia
)
!=
len
(
ib
)
{
return
false
}
for
i
:=
0
;
i
<
len
(
ia
);
i
++
{
if
!
equal
(
ia
[
i
],
ib
[
i
])
{
return
false
}
}
return
true
case
map
[
interface
{}]
interface
{}
:
ia
:=
a
.
(
map
[
interface
{}]
interface
{})
ib
:=
b
.
(
map
[
interface
{}]
interface
{})
if
len
(
ia
)
!=
len
(
ib
)
{
return
false
}
for
k
:=
range
ia
{
if
!
equal
(
ia
[
k
],
ib
[
k
])
{
return
false
}
}
return
true
case
*
big
.
Int
:
return
a
.
(
*
big
.
Int
)
.
Cmp
(
b
.
(
*
big
.
Int
))
==
0
default
:
return
a
==
b
}
return
false
}
func
TestMarker
(
t
*
testing
.
T
)
{
buf
:=
bytes
.
Buffer
{}
dec
:=
NewDecoder
(
&
buf
)
dec
.
mark
()
if
dec
.
marker
()
!=
0
{
t
.
Error
(
"no marker found"
)
}
}
func
TestDecode
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
input
string
expected
interface
{}
}{
{
"int"
,
"I5
\n
."
,
int64
(
5
)},
{
"float"
,
"F1.23
\n
."
,
float64
(
1.23
)},
{
"long"
,
"L12321231232131231231L
\n
."
,
bigInt
(
"12321231232131231231"
)},
{
"None"
,
"N."
,
None
{}},
{
"empty tuple"
,
"(t."
,
[]
interface
{}{}},
{
"tuple of two ints"
,
"(I1
\n
I2
\n
tp0
\n
."
,
[]
interface
{}{
int64
(
1
),
int64
(
2
)}},
{
"nested tuples"
,
"((I1
\n
I2
\n
tp0
\n
(I3
\n
I4
\n
tp1
\n
tp2
\n
."
,
[]
interface
{}{[]
interface
{}{
int64
(
1
),
int64
(
2
)},
[]
interface
{}{
int64
(
3
),
int64
(
4
)}}},
{
"empty list"
,
"(lp0
\n
."
,
[]
interface
{}{}},
{
"list of numbers"
,
"(lp0
\n
I1
\n
aI2
\n
aI3
\n
aI4
\n
a."
,
[]
interface
{}{
int64
(
1
),
int64
(
2
),
int64
(
3
),
int64
(
4
)}},
{
"string"
,
"S'abc'
\n
p0
\n
."
,
string
(
"abc"
)},
{
"unicode"
,
"V
\\
u65e5
\\
u672c
\\
u8a9e
\n
p0
\n
."
,
string
(
"日本語"
)},
{
"empty dict"
,
"(dp0
\n
."
,
make
(
map
[
interface
{}]
interface
{})},
{
"dict with strings"
,
"(dp0
\n
S'a'
\n
p1
\n
S'1'
\n
p2
\n
sS'b'
\n
p3
\n
S'2'
\n
p4
\n
s."
,
map
[
interface
{}]
interface
{}{
"a"
:
"1"
,
"b"
:
"2"
}},
}
for
_
,
test
:=
range
tests
{
buf
:=
bytes
.
NewBufferString
(
test
.
input
)
dec
:=
NewDecoder
(
buf
)
v
,
err
:=
dec
.
Decode
()
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
!
equal
(
v
,
test
.
expected
)
{
t
.
Errorf
(
"%s: got %q expected %q"
,
test
.
name
,
v
,
test
.
expected
)
}
}
}
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