Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
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
Libraries
json
Commits
16b91d49
Commit
16b91d49
authored
Feb 08, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more test cases
parent
d0df796a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
155 additions
and
4 deletions
+155
-4
src/json.hpp
src/json.hpp
+2
-2
src/json.hpp.re2c
src/json.hpp.re2c
+2
-2
test/unit.cpp
test/unit.cpp
+151
-0
No files found.
src/json.hpp
View file @
16b91d49
...
...
@@ -519,13 +519,13 @@ class basic_json
}
}
/// return the type of the object
explicitly
/// return the type of the object
(explicit)
inline
value_t
type
()
const
noexcept
{
return
m_type
;
}
/// return the type of the object
implicitly
/// return the type of the object
(implicit)
operator
value_t
()
const
noexcept
{
return
m_type
;
...
...
src/json.hpp.re2c
View file @
16b91d49
...
...
@@ -519,13 +519,13 @@ class basic_json
}
}
/// return the type of the object
explicitly
/// return the type of the object
(explicit)
inline value_t type() const noexcept
{
return m_type;
}
/// return the type of the object
implicitly
/// return the type of the object
(implicit)
operator value_t() const noexcept
{
return m_type;
...
...
test/unit.cpp
View file @
16b91d49
...
...
@@ -1031,3 +1031,154 @@ TEST_CASE("other constructors and destructor")
}
}
}
TEST_CASE
(
"object inspection"
)
{
SECTION
(
"dump"
)
{
json
j
{{
"object"
,
json
::
object
()},
{
"array"
,
{
1
,
2
,
3
,
4
}},
{
"number"
,
42
},
{
"boolean"
,
false
},
{
"null"
,
nullptr
},
{
"string"
,
"Hello world"
}
};
SECTION
(
"no indent"
)
{
CHECK
(
j
.
dump
()
==
R"({"array":[1,2,3,4],"boolean":false,"null":null,"number":42,"object":{},"string":"Hello world"})"
);
}
SECTION
(
"indent=0"
)
{
CHECK
(
j
.
dump
(
0
)
==
R"({
"array": [
1,
2,
3,
4
],
"boolean": false,
"null": null,
"number": 42,
"object": {},
"string": "Hello world"
})"
);
}
SECTION
(
"indent=4"
)
{
CHECK
(
j
.
dump
(
4
)
==
R"({
"array": [
1,
2,
3,
4
],
"boolean": false,
"null": null,
"number": 42,
"object": {},
"string": "Hello world"
})"
);
}
SECTION
(
"dump and floating-point numbers"
)
{
auto
s
=
json
(
42.23
).
dump
();
CHECK
(
s
.
find
(
"42.23"
)
!=
std
::
string
::
npos
);
}
}
SECTION
(
"return the type of the object (explicit)"
)
{
SECTION
(
"null"
)
{
json
j
=
nullptr
;
CHECK
(
j
.
type
()
==
json
::
value_t
::
null
);
}
SECTION
(
"object"
)
{
json
j
=
{{
"foo"
,
"bar"
}};
CHECK
(
j
.
type
()
==
json
::
value_t
::
object
);
}
SECTION
(
"array"
)
{
json
j
=
{
1
,
2
,
3
,
4
};
CHECK
(
j
.
type
()
==
json
::
value_t
::
array
);
}
SECTION
(
"boolean"
)
{
json
j
=
true
;
CHECK
(
j
.
type
()
==
json
::
value_t
::
boolean
);
}
SECTION
(
"string"
)
{
json
j
=
"Hello world"
;
CHECK
(
j
.
type
()
==
json
::
value_t
::
string
);
}
SECTION
(
"number (integer)"
)
{
json
j
=
23
;
CHECK
(
j
.
type
()
==
json
::
value_t
::
number_integer
);
}
SECTION
(
"number (floating-point)"
)
{
json
j
=
42.23
;
CHECK
(
j
.
type
()
==
json
::
value_t
::
number_float
);
}
}
SECTION
(
"return the type of the object (implicit)"
)
{
SECTION
(
"null"
)
{
json
j
=
nullptr
;
json
::
value_t
t
=
j
;
CHECK
(
t
==
j
.
type
());
}
SECTION
(
"object"
)
{
json
j
=
{{
"foo"
,
"bar"
}};
json
::
value_t
t
=
j
;
CHECK
(
t
==
j
.
type
());
}
SECTION
(
"array"
)
{
json
j
=
{
1
,
2
,
3
,
4
};
json
::
value_t
t
=
j
;
CHECK
(
t
==
j
.
type
());
}
SECTION
(
"boolean"
)
{
json
j
=
true
;
json
::
value_t
t
=
j
;
CHECK
(
t
==
j
.
type
());
}
SECTION
(
"string"
)
{
json
j
=
"Hello world"
;
json
::
value_t
t
=
j
;
CHECK
(
t
==
j
.
type
());
}
SECTION
(
"number (integer)"
)
{
json
j
=
23
;
json
::
value_t
t
=
j
;
CHECK
(
t
==
j
.
type
());
}
SECTION
(
"number (floating-point)"
)
{
json
j
=
42.23
;
json
::
value_t
t
=
j
;
CHECK
(
t
==
j
.
type
());
}
}
}
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