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
4a0ce180
Commit
4a0ce180
authored
Feb 08, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more test cases
parent
27eab94e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
138 additions
and
0 deletions
+138
-0
test/unit.cpp
test/unit.cpp
+138
-0
No files found.
test/unit.cpp
View file @
4a0ce180
...
@@ -2055,4 +2055,142 @@ TEST_CASE("element access")
...
@@ -2055,4 +2055,142 @@ TEST_CASE("element access")
}
}
}
}
}
}
SECTION
(
"object"
)
{
json
j
=
{{
"integer"
,
1
},
{
"floating"
,
42.23
},
{
"null"
,
nullptr
},
{
"string"
,
"hello world"
},
{
"boolean"
,
true
},
{
"object"
,
json
::
object
()},
{
"array"
,
{
1
,
2
,
3
}}};
const
json
j_const
=
j
;
SECTION
(
"access specified element with bounds checking"
)
{
SECTION
(
"access within bounds"
)
{
CHECK
(
j
.
at
(
"integer"
)
==
json
(
1
));
CHECK
(
j
.
at
(
"boolean"
)
==
json
(
true
));
CHECK
(
j
.
at
(
"null"
)
==
json
(
nullptr
));
CHECK
(
j
.
at
(
"string"
)
==
json
(
"hello world"
));
CHECK
(
j
.
at
(
"floating"
)
==
json
(
42.23
));
CHECK
(
j
.
at
(
"object"
)
==
json
(
json
::
object
()));
CHECK
(
j
.
at
(
"array"
)
==
json
({
1
,
2
,
3
}));
CHECK
(
j_const
.
at
(
"integer"
)
==
json
(
1
));
CHECK
(
j_const
.
at
(
"boolean"
)
==
json
(
true
));
CHECK
(
j_const
.
at
(
"null"
)
==
json
(
nullptr
));
CHECK
(
j_const
.
at
(
"string"
)
==
json
(
"hello world"
));
CHECK
(
j_const
.
at
(
"floating"
)
==
json
(
42.23
));
CHECK
(
j_const
.
at
(
"object"
)
==
json
(
json
::
object
()));
CHECK
(
j_const
.
at
(
"array"
)
==
json
({
1
,
2
,
3
}));
}
SECTION
(
"access outside bounds"
)
{
CHECK_THROWS_AS
(
j
.
at
(
"foo"
),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j_const
.
at
(
"foo"
),
std
::
out_of_range
);
}
SECTION
(
"access on non-object type"
)
{
SECTION
(
"null"
)
{
json
j_nonobject
(
json
::
value_t
::
null
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime_error
);
}
SECTION
(
"boolean"
)
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime_error
);
}
SECTION
(
"string"
)
{
json
j_nonobject
(
json
::
value_t
::
string
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime_error
);
}
SECTION
(
"array"
)
{
json
j_nonobject
(
json
::
value_t
::
array
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime_error
);
}
SECTION
(
"number (integer)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime_error
);
}
SECTION
(
"number (floating-point)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime_error
);
}
}
}
SECTION
(
"access specified element"
)
{
SECTION
(
"access within bounds"
)
{
CHECK
(
j
[
"integer"
]
==
json
(
1
));
CHECK
(
j
[
"boolean"
]
==
json
(
true
));
CHECK
(
j
[
"null"
]
==
json
(
nullptr
));
CHECK
(
j
[
"string"
]
==
json
(
"hello world"
));
CHECK
(
j
[
"floating"
]
==
json
(
42.23
));
CHECK
(
j
[
"object"
]
==
json
(
json
::
object
()));
CHECK
(
j
[
"array"
]
==
json
({
1
,
2
,
3
}));
}
SECTION
(
"access on non-object type"
)
{
SECTION
(
"null"
)
{
json
j_nonobject
(
json
::
value_t
::
null
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
runtime_error
);
}
SECTION
(
"boolean"
)
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
runtime_error
);
}
SECTION
(
"string"
)
{
json
j_nonobject
(
json
::
value_t
::
string
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
runtime_error
);
}
SECTION
(
"array"
)
{
json
j_nonobject
(
json
::
value_t
::
array
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
runtime_error
);
}
SECTION
(
"number (integer)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
runtime_error
);
}
SECTION
(
"number (floating-point)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
runtime_error
);
}
}
}
}
}
}
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