Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
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
Chen Yisong
json
Commits
24b6e028
Unverified
Commit
24b6e028
authored
Oct 22, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
improved test coverage
parent
b27a142e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
204 additions
and
72 deletions
+204
-72
unit-capacity.cpp
test/src/unit-capacity.cpp
+33
-33
unit-comparison.cpp
test/src/unit-comparison.cpp
+9
-5
unit-constructor1.cpp
test/src/unit-constructor1.cpp
+5
-0
unit-meta.cpp
test/src/unit-meta.cpp
+5
-0
unit-modifiers.cpp
test/src/unit-modifiers.cpp
+7
-3
unit-reference_access.cpp
test/src/unit-reference_access.cpp
+145
-31
No files found.
test/src/unit-capacity.cpp
View file @
24b6e028
...
@@ -38,7 +38,7 @@ TEST_CASE("capacity")
...
@@ -38,7 +38,7 @@ TEST_CASE("capacity")
SECTION
(
"boolean"
)
SECTION
(
"boolean"
)
{
{
json
j
=
true
;
json
j
=
true
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of empty"
)
SECTION
(
"result of empty"
)
{
{
...
@@ -56,7 +56,7 @@ TEST_CASE("capacity")
...
@@ -56,7 +56,7 @@ TEST_CASE("capacity")
SECTION
(
"string"
)
SECTION
(
"string"
)
{
{
json
j
=
"hello world"
;
json
j
=
"hello world"
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of empty"
)
SECTION
(
"result of empty"
)
{
{
...
@@ -76,7 +76,7 @@ TEST_CASE("capacity")
...
@@ -76,7 +76,7 @@ TEST_CASE("capacity")
SECTION
(
"empty array"
)
SECTION
(
"empty array"
)
{
{
json
j
=
json
::
array
();
json
j
=
json
::
array
();
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of empty"
)
SECTION
(
"result of empty"
)
{
{
...
@@ -94,7 +94,7 @@ TEST_CASE("capacity")
...
@@ -94,7 +94,7 @@ TEST_CASE("capacity")
SECTION
(
"filled array"
)
SECTION
(
"filled array"
)
{
{
json
j
=
{
1
,
2
,
3
};
json
j
=
{
1
,
2
,
3
};
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of empty"
)
SECTION
(
"result of empty"
)
{
{
...
@@ -115,7 +115,7 @@ TEST_CASE("capacity")
...
@@ -115,7 +115,7 @@ TEST_CASE("capacity")
SECTION
(
"empty object"
)
SECTION
(
"empty object"
)
{
{
json
j
=
json
::
object
();
json
j
=
json
::
object
();
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of empty"
)
SECTION
(
"result of empty"
)
{
{
...
@@ -133,7 +133,7 @@ TEST_CASE("capacity")
...
@@ -133,7 +133,7 @@ TEST_CASE("capacity")
SECTION
(
"filled object"
)
SECTION
(
"filled object"
)
{
{
json
j
=
{{
"one"
,
1
},
{
"two"
,
2
},
{
"three"
,
3
}};
json
j
=
{{
"one"
,
1
},
{
"two"
,
2
},
{
"three"
,
3
}};
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of empty"
)
SECTION
(
"result of empty"
)
{
{
...
@@ -151,8 +151,8 @@ TEST_CASE("capacity")
...
@@ -151,8 +151,8 @@ TEST_CASE("capacity")
SECTION
(
"number (integer)"
)
SECTION
(
"number (integer)"
)
{
{
json
j
=
23
;
json
j
=
-
23
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of empty"
)
SECTION
(
"result of empty"
)
{
{
...
@@ -170,7 +170,7 @@ TEST_CASE("capacity")
...
@@ -170,7 +170,7 @@ TEST_CASE("capacity")
SECTION
(
"number (unsigned)"
)
SECTION
(
"number (unsigned)"
)
{
{
json
j
=
23u
;
json
j
=
23u
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of empty"
)
SECTION
(
"result of empty"
)
{
{
...
@@ -188,7 +188,7 @@ TEST_CASE("capacity")
...
@@ -188,7 +188,7 @@ TEST_CASE("capacity")
SECTION
(
"number (float)"
)
SECTION
(
"number (float)"
)
{
{
json
j
=
23.42
;
json
j
=
23.42
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of empty"
)
SECTION
(
"result of empty"
)
{
{
...
@@ -206,7 +206,7 @@ TEST_CASE("capacity")
...
@@ -206,7 +206,7 @@ TEST_CASE("capacity")
SECTION
(
"null"
)
SECTION
(
"null"
)
{
{
json
j
=
nullptr
;
json
j
=
nullptr
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of empty"
)
SECTION
(
"result of empty"
)
{
{
...
@@ -227,7 +227,7 @@ TEST_CASE("capacity")
...
@@ -227,7 +227,7 @@ TEST_CASE("capacity")
SECTION
(
"boolean"
)
SECTION
(
"boolean"
)
{
{
json
j
=
true
;
json
j
=
true
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of size"
)
SECTION
(
"result of size"
)
{
{
...
@@ -247,7 +247,7 @@ TEST_CASE("capacity")
...
@@ -247,7 +247,7 @@ TEST_CASE("capacity")
SECTION
(
"string"
)
SECTION
(
"string"
)
{
{
json
j
=
"hello world"
;
json
j
=
"hello world"
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of size"
)
SECTION
(
"result of size"
)
{
{
...
@@ -269,7 +269,7 @@ TEST_CASE("capacity")
...
@@ -269,7 +269,7 @@ TEST_CASE("capacity")
SECTION
(
"empty array"
)
SECTION
(
"empty array"
)
{
{
json
j
=
json
::
array
();
json
j
=
json
::
array
();
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of size"
)
SECTION
(
"result of size"
)
{
{
...
@@ -289,7 +289,7 @@ TEST_CASE("capacity")
...
@@ -289,7 +289,7 @@ TEST_CASE("capacity")
SECTION
(
"filled array"
)
SECTION
(
"filled array"
)
{
{
json
j
=
{
1
,
2
,
3
};
json
j
=
{
1
,
2
,
3
};
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of size"
)
SECTION
(
"result of size"
)
{
{
...
@@ -312,7 +312,7 @@ TEST_CASE("capacity")
...
@@ -312,7 +312,7 @@ TEST_CASE("capacity")
SECTION
(
"empty object"
)
SECTION
(
"empty object"
)
{
{
json
j
=
json
::
object
();
json
j
=
json
::
object
();
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of size"
)
SECTION
(
"result of size"
)
{
{
...
@@ -332,7 +332,7 @@ TEST_CASE("capacity")
...
@@ -332,7 +332,7 @@ TEST_CASE("capacity")
SECTION
(
"filled object"
)
SECTION
(
"filled object"
)
{
{
json
j
=
{{
"one"
,
1
},
{
"two"
,
2
},
{
"three"
,
3
}};
json
j
=
{{
"one"
,
1
},
{
"two"
,
2
},
{
"three"
,
3
}};
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of size"
)
SECTION
(
"result of size"
)
{
{
...
@@ -352,8 +352,8 @@ TEST_CASE("capacity")
...
@@ -352,8 +352,8 @@ TEST_CASE("capacity")
SECTION
(
"number (integer)"
)
SECTION
(
"number (integer)"
)
{
{
json
j
=
23
;
json
j
=
-
23
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of size"
)
SECTION
(
"result of size"
)
{
{
...
@@ -373,7 +373,7 @@ TEST_CASE("capacity")
...
@@ -373,7 +373,7 @@ TEST_CASE("capacity")
SECTION
(
"number (unsigned)"
)
SECTION
(
"number (unsigned)"
)
{
{
json
j
=
23u
;
json
j
=
23u
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of size"
)
SECTION
(
"result of size"
)
{
{
...
@@ -393,7 +393,7 @@ TEST_CASE("capacity")
...
@@ -393,7 +393,7 @@ TEST_CASE("capacity")
SECTION
(
"number (float)"
)
SECTION
(
"number (float)"
)
{
{
json
j
=
23.42
;
json
j
=
23.42
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of size"
)
SECTION
(
"result of size"
)
{
{
...
@@ -413,7 +413,7 @@ TEST_CASE("capacity")
...
@@ -413,7 +413,7 @@ TEST_CASE("capacity")
SECTION
(
"null"
)
SECTION
(
"null"
)
{
{
json
j
=
nullptr
;
json
j
=
nullptr
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of size"
)
SECTION
(
"result of size"
)
{
{
...
@@ -436,7 +436,7 @@ TEST_CASE("capacity")
...
@@ -436,7 +436,7 @@ TEST_CASE("capacity")
SECTION
(
"boolean"
)
SECTION
(
"boolean"
)
{
{
json
j
=
true
;
json
j
=
true
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of max_size"
)
SECTION
(
"result of max_size"
)
{
{
...
@@ -448,7 +448,7 @@ TEST_CASE("capacity")
...
@@ -448,7 +448,7 @@ TEST_CASE("capacity")
SECTION
(
"string"
)
SECTION
(
"string"
)
{
{
json
j
=
"hello world"
;
json
j
=
"hello world"
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of max_size"
)
SECTION
(
"result of max_size"
)
{
{
...
@@ -462,7 +462,7 @@ TEST_CASE("capacity")
...
@@ -462,7 +462,7 @@ TEST_CASE("capacity")
SECTION
(
"empty array"
)
SECTION
(
"empty array"
)
{
{
json
j
=
json
::
array
();
json
j
=
json
::
array
();
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of max_size"
)
SECTION
(
"result of max_size"
)
{
{
...
@@ -474,7 +474,7 @@ TEST_CASE("capacity")
...
@@ -474,7 +474,7 @@ TEST_CASE("capacity")
SECTION
(
"filled array"
)
SECTION
(
"filled array"
)
{
{
json
j
=
{
1
,
2
,
3
};
json
j
=
{
1
,
2
,
3
};
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of max_size"
)
SECTION
(
"result of max_size"
)
{
{
...
@@ -489,7 +489,7 @@ TEST_CASE("capacity")
...
@@ -489,7 +489,7 @@ TEST_CASE("capacity")
SECTION
(
"empty object"
)
SECTION
(
"empty object"
)
{
{
json
j
=
json
::
object
();
json
j
=
json
::
object
();
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of max_size"
)
SECTION
(
"result of max_size"
)
{
{
...
@@ -501,7 +501,7 @@ TEST_CASE("capacity")
...
@@ -501,7 +501,7 @@ TEST_CASE("capacity")
SECTION
(
"filled object"
)
SECTION
(
"filled object"
)
{
{
json
j
=
{{
"one"
,
1
},
{
"two"
,
2
},
{
"three"
,
3
}};
json
j
=
{{
"one"
,
1
},
{
"two"
,
2
},
{
"three"
,
3
}};
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of max_size"
)
SECTION
(
"result of max_size"
)
{
{
...
@@ -513,8 +513,8 @@ TEST_CASE("capacity")
...
@@ -513,8 +513,8 @@ TEST_CASE("capacity")
SECTION
(
"number (integer)"
)
SECTION
(
"number (integer)"
)
{
{
json
j
=
23
;
json
j
=
-
23
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of max_size"
)
SECTION
(
"result of max_size"
)
{
{
...
@@ -526,7 +526,7 @@ TEST_CASE("capacity")
...
@@ -526,7 +526,7 @@ TEST_CASE("capacity")
SECTION
(
"number (unsigned)"
)
SECTION
(
"number (unsigned)"
)
{
{
json
j
=
23u
;
json
j
=
23u
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of max_size"
)
SECTION
(
"result of max_size"
)
{
{
...
@@ -538,7 +538,7 @@ TEST_CASE("capacity")
...
@@ -538,7 +538,7 @@ TEST_CASE("capacity")
SECTION
(
"number (float)"
)
SECTION
(
"number (float)"
)
{
{
json
j
=
23.42
;
json
j
=
23.42
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of max_size"
)
SECTION
(
"result of max_size"
)
{
{
...
@@ -550,7 +550,7 @@ TEST_CASE("capacity")
...
@@ -550,7 +550,7 @@ TEST_CASE("capacity")
SECTION
(
"null"
)
SECTION
(
"null"
)
{
{
json
j
=
nullptr
;
json
j
=
nullptr
;
json
j_const
(
j
);
const
json
j_const
(
j
);
SECTION
(
"result of max_size"
)
SECTION
(
"result of max_size"
)
{
{
...
...
test/src/unit-comparison.cpp
View file @
24b6e028
...
@@ -88,7 +88,7 @@ TEST_CASE("lexicographical comparison operators")
...
@@ -88,7 +88,7 @@ TEST_CASE("lexicographical comparison operators")
json
j_values
=
json
j_values
=
{
{
nullptr
,
nullptr
,
nullptr
,
nullptr
,
17
,
42
,
-
17
,
42
,
8u
,
13u
,
8u
,
13u
,
3.14159
,
23.42
,
3.14159
,
23.42
,
"foo"
,
"bar"
,
"foo"
,
"bar"
,
...
@@ -125,6 +125,8 @@ TEST_CASE("lexicographical comparison operators")
...
@@ -125,6 +125,8 @@ TEST_CASE("lexicographical comparison operators")
{
{
CAPTURE
(
i
);
CAPTURE
(
i
);
CAPTURE
(
j
);
CAPTURE
(
j
);
CAPTURE
(
j_values
[
i
]);
CAPTURE
(
j_values
[
j
]);
// check precomputed values
// check precomputed values
CHECK
(
(
j_values
[
i
]
==
j_values
[
j
])
==
expected
[
i
][
j
]
);
CHECK
(
(
j_values
[
i
]
==
j_values
[
j
])
==
expected
[
i
][
j
]
);
}
}
...
@@ -172,11 +174,11 @@ TEST_CASE("lexicographical comparison operators")
...
@@ -172,11 +174,11 @@ TEST_CASE("lexicographical comparison operators")
{
{
{
false
,
false
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
},
{
false
,
false
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
},
{
false
,
false
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
},
{
false
,
false
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
,
true
},
{
false
,
false
,
false
,
true
,
false
,
false
,
fals
e
,
true
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
false
,
true
,
true
,
true
,
tru
e
,
true
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
tru
e
,
true
,
false
,
true
,
false
,
true
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
fals
e
,
true
,
false
,
true
,
false
,
true
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
tru
e
,
true
,
false
,
false
,
false
,
true
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
fals
e
,
true
,
false
,
false
,
false
,
true
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
tru
e
,
true
,
true
,
true
,
false
,
true
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
fals
e
,
true
,
true
,
true
,
false
,
true
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
false
,
true
,
false
,
false
,
false
,
false
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
false
,
true
,
false
,
false
,
false
,
false
,
true
,
true
,
false
,
false
,
true
,
true
,
true
,
true
},
{
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
},
{
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
},
{
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
true
,
false
,
false
,
false
,
false
,
false
,
false
,
false
},
{
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
,
true
,
false
,
false
,
false
,
false
,
false
,
false
,
false
},
...
@@ -194,6 +196,8 @@ TEST_CASE("lexicographical comparison operators")
...
@@ -194,6 +196,8 @@ TEST_CASE("lexicographical comparison operators")
{
{
CAPTURE
(
i
);
CAPTURE
(
i
);
CAPTURE
(
j
);
CAPTURE
(
j
);
CAPTURE
(
j_values
[
i
]);
CAPTURE
(
j_values
[
j
]);
// check precomputed values
// check precomputed values
CHECK
(
(
j_values
[
i
]
<
j_values
[
j
])
==
expected
[
i
][
j
]
);
CHECK
(
(
j_values
[
i
]
<
j_values
[
j
])
==
expected
[
i
][
j
]
);
}
}
...
...
test/src/unit-constructor1.cpp
View file @
24b6e028
...
@@ -77,6 +77,7 @@ TEST_CASE("constructors")
...
@@ -77,6 +77,7 @@ TEST_CASE("constructors")
auto
t
=
json
::
value_t
::
boolean
;
auto
t
=
json
::
value_t
::
boolean
;
json
j
(
t
);
json
j
(
t
);
CHECK
(
j
.
type
()
==
t
);
CHECK
(
j
.
type
()
==
t
);
CHECK
(
j
==
false
);
}
}
SECTION
(
"string"
)
SECTION
(
"string"
)
...
@@ -84,6 +85,7 @@ TEST_CASE("constructors")
...
@@ -84,6 +85,7 @@ TEST_CASE("constructors")
auto
t
=
json
::
value_t
::
string
;
auto
t
=
json
::
value_t
::
string
;
json
j
(
t
);
json
j
(
t
);
CHECK
(
j
.
type
()
==
t
);
CHECK
(
j
.
type
()
==
t
);
CHECK
(
j
==
""
);
}
}
SECTION
(
"number_integer"
)
SECTION
(
"number_integer"
)
...
@@ -91,6 +93,7 @@ TEST_CASE("constructors")
...
@@ -91,6 +93,7 @@ TEST_CASE("constructors")
auto
t
=
json
::
value_t
::
number_integer
;
auto
t
=
json
::
value_t
::
number_integer
;
json
j
(
t
);
json
j
(
t
);
CHECK
(
j
.
type
()
==
t
);
CHECK
(
j
.
type
()
==
t
);
CHECK
(
j
==
0
);
}
}
SECTION
(
"number_unsigned"
)
SECTION
(
"number_unsigned"
)
...
@@ -98,6 +101,7 @@ TEST_CASE("constructors")
...
@@ -98,6 +101,7 @@ TEST_CASE("constructors")
auto
t
=
json
::
value_t
::
number_unsigned
;
auto
t
=
json
::
value_t
::
number_unsigned
;
json
j
(
t
);
json
j
(
t
);
CHECK
(
j
.
type
()
==
t
);
CHECK
(
j
.
type
()
==
t
);
CHECK
(
j
==
0
);
}
}
SECTION
(
"number_float"
)
SECTION
(
"number_float"
)
...
@@ -105,6 +109,7 @@ TEST_CASE("constructors")
...
@@ -105,6 +109,7 @@ TEST_CASE("constructors")
auto
t
=
json
::
value_t
::
number_float
;
auto
t
=
json
::
value_t
::
number_float
;
json
j
(
t
);
json
j
(
t
);
CHECK
(
j
.
type
()
==
t
);
CHECK
(
j
.
type
()
==
t
);
CHECK
(
j
==
0.0
);
}
}
}
}
...
...
test/src/unit-meta.cpp
View file @
24b6e028
...
@@ -47,5 +47,10 @@ TEST_CASE("version information")
...
@@ -47,5 +47,10 @@ TEST_CASE("version information")
{
"minor"
,
1
},
{
"minor"
,
1
},
{
"patch"
,
1
}
{
"patch"
,
1
}
}));
}));
CHECK
(
j
.
find
(
"platform"
)
!=
j
.
end
());
CHECK
(
j
.
at
(
"compiler"
).
find
(
"family"
)
!=
j
.
at
(
"compiler"
).
end
());
CHECK
(
j
.
at
(
"compiler"
).
find
(
"version"
)
!=
j
.
at
(
"compiler"
).
end
());
CHECK
(
j
.
at
(
"compiler"
).
find
(
"c++"
)
!=
j
.
at
(
"compiler"
).
end
());
}
}
}
}
test/src/unit-modifiers.cpp
View file @
24b6e028
...
@@ -271,9 +271,13 @@ TEST_CASE("modifiers")
...
@@ -271,9 +271,13 @@ TEST_CASE("modifiers")
j
.
push_back
({
"key2"
,
"bar"
});
j
.
push_back
({
"key2"
,
"bar"
});
CHECK
(
j
==
json
({{
"key1"
,
1
},
{
"key2"
,
"bar"
}}));
CHECK
(
j
==
json
({{
"key1"
,
1
},
{
"key2"
,
"bar"
}}));
json
k
=
{{
"key1"
,
1
}};
// invalid values (no string/val pair)
CHECK_THROWS_AS
(
k
.
push_back
({
1
,
2
,
3
,
4
}),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j
.
push_back
({
1
}),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
k
.
push_back
({
1
,
2
,
3
,
4
}),
"[json.exception.type_error.308] cannot use push_back() with object"
);
CHECK_THROWS_WITH
(
j
.
push_back
({
1
}),
"[json.exception.type_error.308] cannot use push_back() with object"
);
CHECK_THROWS_AS
(
j
.
push_back
({
1
,
2
}),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j
.
push_back
({
1
,
2
}),
"[json.exception.type_error.308] cannot use push_back() with object"
);
CHECK_THROWS_AS
(
j
.
push_back
({
1
,
2
,
3
,
4
}),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j
.
push_back
({
1
,
2
,
3
,
4
}),
"[json.exception.type_error.308] cannot use push_back() with object"
);
}
}
}
}
}
}
...
...
test/src/unit-reference_access.cpp
View file @
24b6e028
...
@@ -64,11 +64,24 @@ TEST_CASE("reference access")
...
@@ -64,11 +64,24 @@ TEST_CASE("reference access")
// check if mismatching references throw correctly
// check if mismatching references throw correctly
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
object_t
&>
());
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
object_t
&>
());
CHECK_THROWS
(
value
.
get_ref
<
json
::
array_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
array_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
string_t
&>
());
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
array_t
&>
(),
CHECK_THROWS
(
value
.
get_ref
<
json
::
boolean_t
&>
());
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
number_integer_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
string_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
number_float_t
&>
());
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
string_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_integer_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_integer_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"
);
}
}
SECTION
(
"const reference access to const object_t"
)
SECTION
(
"const reference access to const object_t"
)
...
@@ -100,12 +113,25 @@ TEST_CASE("reference access")
...
@@ -100,12 +113,25 @@ TEST_CASE("reference access")
CHECK
(
p2
==
value
.
get
<
test_type
>
());
CHECK
(
p2
==
value
.
get
<
test_type
>
());
// check if mismatching references throw correctly
// check if mismatching references throw correctly
CHECK_THROWS
(
value
.
get_ref
<
json
::
object_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
object_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
object_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"
);
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
array_t
&>
());
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
array_t
&>
());
CHECK_THROWS
(
value
.
get_ref
<
json
::
string_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
string_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
boolean_t
&>
());
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
string_t
&>
(),
CHECK_THROWS
(
value
.
get_ref
<
json
::
number_integer_t
&>
());
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
number_float_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_integer_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_integer_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"
);
}
}
SECTION
(
"reference access to string_t"
)
SECTION
(
"reference access to string_t"
)
...
@@ -123,12 +149,25 @@ TEST_CASE("reference access")
...
@@ -123,12 +149,25 @@ TEST_CASE("reference access")
CHECK
(
p2
==
value
.
get
<
test_type
>
());
CHECK
(
p2
==
value
.
get
<
test_type
>
());
// check if mismatching references throw correctly
// check if mismatching references throw correctly
CHECK_THROWS
(
value
.
get_ref
<
json
::
object_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
object_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
array_t
&>
());
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
object_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
array_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
array_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"
);
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
string_t
&>
());
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
string_t
&>
());
CHECK_THROWS
(
value
.
get_ref
<
json
::
boolean_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
number_integer_t
&>
());
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
CHECK_THROWS
(
value
.
get_ref
<
json
::
number_float_t
&>
());
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_integer_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_integer_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"
);
}
}
SECTION
(
"reference access to boolean_t"
)
SECTION
(
"reference access to boolean_t"
)
...
@@ -146,18 +185,31 @@ TEST_CASE("reference access")
...
@@ -146,18 +185,31 @@ TEST_CASE("reference access")
CHECK
(
p2
==
value
.
get
<
test_type
>
());
CHECK
(
p2
==
value
.
get
<
test_type
>
());
// check if mismatching references throw correctly
// check if mismatching references throw correctly
CHECK_THROWS
(
value
.
get_ref
<
json
::
object_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
object_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
array_t
&>
());
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
object_t
&>
(),
CHECK_THROWS
(
value
.
get_ref
<
json
::
string_t
&>
());
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
array_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
array_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
string_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
string_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"
);
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
boolean_t
&>
());
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
boolean_t
&>
());
CHECK_THROWS
(
value
.
get_ref
<
json
::
number_integer_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_integer_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
number_float_t
&>
());
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_integer_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"
);
}
}
SECTION
(
"reference access to number_integer_t"
)
SECTION
(
"reference access to number_integer_t"
)
{
{
using
test_type
=
json
::
number_integer_t
;
using
test_type
=
json
::
number_integer_t
;
json
value
=
23
;
json
value
=
-
23
;
// check if references are returned correctly
// check if references are returned correctly
test_type
&
p1
=
value
.
get_ref
<
test_type
&>
();
test_type
&
p1
=
value
.
get_ref
<
test_type
&>
();
...
@@ -169,12 +221,61 @@ TEST_CASE("reference access")
...
@@ -169,12 +221,61 @@ TEST_CASE("reference access")
CHECK
(
p2
==
value
.
get
<
test_type
>
());
CHECK
(
p2
==
value
.
get
<
test_type
>
());
// check if mismatching references throw correctly
// check if mismatching references throw correctly
CHECK_THROWS
(
value
.
get_ref
<
json
::
object_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
object_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
array_t
&>
());
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
object_t
&>
(),
CHECK_THROWS
(
value
.
get_ref
<
json
::
string_t
&>
());
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
boolean_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
array_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
array_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
string_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
string_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
number_integer_t
&>
());
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
number_integer_t
&>
());
CHECK_THROWS
(
value
.
get_ref
<
json
::
number_float_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
}
SECTION
(
"reference access to number_unsigned_t"
)
{
using
test_type
=
json
::
number_unsigned_t
;
json
value
=
23u
;
// check if references are returned correctly
test_type
&
p1
=
value
.
get_ref
<
test_type
&>
();
CHECK
(
&
p1
==
value
.
get_ptr
<
test_type
*>
());
CHECK
(
p1
==
value
.
get
<
test_type
>
());
const
test_type
&
p2
=
value
.
get_ref
<
const
test_type
&>
();
CHECK
(
&
p2
==
value
.
get_ptr
<
const
test_type
*>
());
CHECK
(
p2
==
value
.
get
<
test_type
>
());
// check if mismatching references throw correctly
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
object_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
object_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
array_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
array_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
string_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
string_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
//CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
//CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
// "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_float_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
}
}
SECTION
(
"reference access to number_float_t"
)
SECTION
(
"reference access to number_float_t"
)
...
@@ -192,11 +293,24 @@ TEST_CASE("reference access")
...
@@ -192,11 +293,24 @@ TEST_CASE("reference access")
CHECK
(
p2
==
value
.
get
<
test_type
>
());
CHECK
(
p2
==
value
.
get
<
test_type
>
());
// check if mismatching references throw correctly
// check if mismatching references throw correctly
CHECK_THROWS
(
value
.
get_ref
<
json
::
object_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
object_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
array_t
&>
());
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
object_t
&>
(),
CHECK_THROWS
(
value
.
get_ref
<
json
::
string_t
&>
());
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
boolean_t
&>
());
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
array_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS
(
value
.
get_ref
<
json
::
number_integer_t
&>
());
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
array_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
string_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
string_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
boolean_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_integer_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_integer_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_THROWS_AS
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
value
.
get_ref
<
json
::
number_unsigned_t
&>
(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"
);
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
number_float_t
&>
());
CHECK_NOTHROW
(
value
.
get_ref
<
json
::
number_float_t
&>
());
}
}
}
}
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