Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
0e3fe64c
Commit
0e3fe64c
authored
Aug 20, 2015
by
Sergey Shcherbina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added TestMapGet
parent
d9184077
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
0 deletions
+77
-0
templatefunc_test.go
templatefunc_test.go
+77
-0
No files found.
templatefunc_test.go
View file @
0e3fe64c
...
...
@@ -244,3 +244,80 @@ func TestParseFormTag(t *testing.T) {
t
.
Errorf
(
"Form Tag that should be ignored was not correctly parsed."
)
}
}
func
TestMapGet
(
t
*
testing
.
T
)
{
// test one level map
m1
:=
map
[
string
]
int64
{
"a"
:
1
,
"1"
:
2
,
}
if
res
,
err
:=
MapGet
(
m1
,
"a"
);
err
==
nil
{
if
res
.
(
int64
)
!=
1
{
t
.
Errorf
(
"Should return 1, but return %v"
,
res
)
}
}
else
{
t
.
Errorf
(
"Error happens %v"
,
err
)
}
if
res
,
err
:=
MapGet
(
m1
,
"1"
);
err
==
nil
{
if
res
.
(
int64
)
!=
2
{
t
.
Errorf
(
"Should return 2, but return %v"
,
res
)
}
}
else
{
t
.
Errorf
(
"Error happens %v"
,
err
)
}
if
res
,
err
:=
MapGet
(
m1
,
1
);
err
==
nil
{
if
res
.
(
int64
)
!=
2
{
t
.
Errorf
(
"Should return 2, but return %v"
,
res
)
}
}
else
{
t
.
Errorf
(
"Error happens %v"
,
err
)
}
// test 2 level map
m2
:=
map
[
string
]
interface
{}{
"1"
:
map
[
string
]
float64
{
"2"
:
3.5
,
},
}
if
res
,
err
:=
MapGet
(
m2
,
1
,
2
);
err
==
nil
{
if
res
.
(
float64
)
!=
3.5
{
t
.
Errorf
(
"Should return 3.5, but return %v"
,
res
)
}
}
else
{
t
.
Errorf
(
"Error happens %v"
,
err
)
}
// test 5 level map
m5
:=
map
[
string
]
interface
{}{
"1"
:
map
[
string
]
interface
{}{
"2"
:
map
[
string
]
interface
{}{
"3"
:
map
[
string
]
interface
{}{
"4"
:
map
[
string
]
interface
{}{
"5"
:
1.2
,
},
},
},
},
}
if
res
,
err
:=
MapGet
(
m5
,
1
,
2
,
3
,
4
,
5
);
err
==
nil
{
if
res
.
(
float64
)
!=
1.2
{
t
.
Errorf
(
"Should return 1.2, but return %v"
,
res
)
}
}
else
{
t
.
Errorf
(
"Error happens %v"
,
err
)
}
// check whether element not exists in map
if
res
,
err
:=
MapGet
(
m5
,
5
,
4
,
3
,
2
,
1
);
err
==
nil
{
if
res
!=
nil
{
t
.
Errorf
(
"Should return nil, but return %v"
,
res
)
}
}
else
{
t
.
Errorf
(
"Error happens %v"
,
err
)
}
}
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