Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xs-test
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patrick Chen
xs-test
Commits
af54a7e8
Commit
af54a7e8
authored
Aug 28, 2018
by
Patrick Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrap expected info as object in config
parent
337ed1f3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
24 deletions
+31
-24
greeting.json
example/greeting.json
+3
-1
Expectation.h
include/test/Expectation.h
+0
-3
Expectation.cc
src/test/Expectation.cc
+28
-20
No files found.
example/greeting.json
View file @
af54a7e8
...
...
@@ -11,9 +11,11 @@
"script"
:
[
{
"command"
:
"GetMessage"
,
"expect"
:
"Hello, Master!"
,
"expect"
:
{
"response"
:
"Hello, Master!"
,
"runs"
:
[
"GetName"
],
"posts"
:
[
"NotifyGetMessage"
]
}
}
]
}
include/test/Expectation.h
View file @
af54a7e8
...
...
@@ -23,9 +23,6 @@ namespace xs { namespace test
explicit
Expectation
(
const
nlohmann
::
json
&
object
);
static
bool
verify
(
const
nlohmann
::
json
&
object
)
noexcept
;
private
:
Expectation
(
std
::
string
name
,
nlohmann
::
json
value
)
noexcept
;
public
:
std
::
string
name_
;
nlohmann
::
json
value_
;
...
...
src/test/Expectation.cc
View file @
af54a7e8
...
...
@@ -7,10 +7,13 @@
namespace
xs
{
namespace
test
{
Expectation
::
Expectation
(
const
nlohmann
::
json
&
object
)
:
Expectation
(
object
[
"command"
].
get
<
std
::
string
>
(),
object
[
"expect"
]
)
:
name_
(
object
[
"command"
].
get
<
std
::
string
>
()
)
{
if
(
object
.
count
(
"runs"
))
{
for
(
const
auto
&
element
:
object
[
"runs"
])
{
const
auto
&
expect
=
object
[
"expect"
];
value_
=
expect
[
"response"
];
if
(
expect
.
count
(
"runs"
))
{
for
(
const
auto
&
element
:
expect
[
"runs"
])
{
if
(
!
element
.
is_string
())
{
throw
std
::
runtime_error
(
"element in
\"
runs
\"
is not string"
);
}
...
...
@@ -18,8 +21,8 @@ namespace xs { namespace test
}
}
if
(
obj
ect
.
count
(
"posts"
))
{
for
(
const
auto
&
element
:
obj
ect
[
"posts"
])
{
if
(
exp
ect
.
count
(
"posts"
))
{
for
(
const
auto
&
element
:
exp
ect
[
"posts"
])
{
if
(
!
element
.
is_string
())
{
throw
std
::
runtime_error
(
"element in
\"
posts
\"
is not string"
);
}
...
...
@@ -30,30 +33,35 @@ namespace xs { namespace test
bool
Expectation
::
verify
(
const
nlohmann
::
json
&
object
)
noexcept
{
if
(
!
(
object
.
is_object
()
&&
object
.
count
(
"command"
)
&&
object
.
count
(
"expect"
)))
{
if
(
!
object
.
is_object
())
{
return
false
;
}
if
(
!
(
object
.
count
(
"command"
)
&&
object
[
"command"
].
is_string
()))
{
return
false
;
}
if
(
!
(
object
.
count
(
"expect"
)
&&
object
[
"expect"
].
is_object
()))
{
return
false
;
}
const
auto
&
expect
=
object
[
"expect"
];
if
(
!
expect
.
count
(
"response"
))
{
return
false
;
}
if
(
object
.
count
(
"runs"
)
&&
!
object
[
"runs"
].
is_array
(
))
{
if
(
!
(
expect
[
"response"
].
is_string
()
||
expect
[
"response"
].
is_object
()
))
{
return
false
;
}
if
(
object
.
count
(
"posts"
)
&&
!
object
[
"post
s"
].
is_array
())
{
if
(
expect
.
count
(
"runs"
)
&&
!
expect
[
"run
s"
].
is_array
())
{
return
false
;
}
return
(
object
[
"command"
].
is_string
()
&&
(
object
[
"expect"
].
is_string
()
||
object
[
"expect"
].
is_object
()
)
);
if
(
expect
.
count
(
"posts"
)
&&
!
expect
[
"posts"
].
is_array
())
{
return
false
;
}
Expectation
::
Expectation
(
std
::
string
name
,
nlohmann
::
json
value
)
noexcept
:
name_
(
std
::
move
(
name
))
,
value_
(
std
::
move
(
value
))
{
}
return
true
;
}
}
}
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