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
ee0f23fd
Commit
ee0f23fd
authored
Nov 28, 2016
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚧
bug fixes and more tests
parent
bc238124
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
31 deletions
+61
-31
src/json.hpp
src/json.hpp
+1
-1
src/json.hpp.re2c
src/json.hpp.re2c
+1
-1
test/Makefile
test/Makefile
+1
-1
test/src/unit-cbor.cpp
test/src/unit-cbor.cpp
+58
-28
No files found.
src/json.hpp
View file @
ee0f23fd
...
@@ -6490,8 +6490,8 @@ class basic_json
...
@@ -6490,8 +6490,8 @@ class basic_json
v
.
push_back
(
0x3b
);
v
.
push_back
(
0x3b
);
add_to_vector
(
v
,
8
,
positive_number
);
add_to_vector
(
v
,
8
,
positive_number
);
}
}
break
;
}
}
break
;
}
}
case
value_t
:
:
number_unsigned
:
case
value_t
:
:
number_unsigned
:
...
...
src/json.hpp.re2c
View file @
ee0f23fd
...
@@ -6490,8 +6490,8 @@ class basic_json
...
@@ -6490,8 +6490,8 @@ class basic_json
v.push_back(0x3b);
v.push_back(0x3b);
add_to_vector(v, 8, positive_number);
add_to_vector(v, 8, positive_number);
}
}
break;
}
}
break;
}
}
case value_t::number_unsigned:
case value_t::number_unsigned:
...
...
test/Makefile
View file @
ee0f23fd
...
@@ -77,4 +77,4 @@ test-%: src/unit-%.cpp ../src/json.hpp src/catch.hpp
...
@@ -77,4 +77,4 @@ test-%: src/unit-%.cpp ../src/json.hpp src/catch.hpp
TEST_PATTERN
=
"*"
TEST_PATTERN
=
"*"
TEST_PREFIX
=
""
TEST_PREFIX
=
""
check
:
$(TESTCASES)
check
:
$(TESTCASES)
@
cd
..
;
for
testcase
in
$(TESTCASES)
;
do
echo
"Executing
$$
testcase..."
;
$(TEST_PREFIX)
test
/
$$
testcase
$(TEST_PATTERN)
;
done
@
cd
..
;
for
testcase
in
$(TESTCASES)
;
do
echo
"Executing
$$
testcase..."
;
$(TEST_PREFIX)
test
/
$$
testcase
$(TEST_PATTERN)
||
exit
1
;
done
test/src/unit-cbor.cpp
View file @
ee0f23fd
...
@@ -77,9 +77,24 @@ TEST_CASE("CBOR")
...
@@ -77,9 +77,24 @@ TEST_CASE("CBOR")
{
{
SECTION
(
"signed"
)
SECTION
(
"signed"
)
{
{
SECTION
(
"-
24..-1
"
)
SECTION
(
"-
9263 (int 16)
"
)
{
{
for
(
auto
i
=
-
24
;
i
<=
-
1
;
++
i
)
json
j
=
-
9263
;
std
::
vector
<
uint8_t
>
expected
=
{
0x39
,
0x24
,
0x2e
};
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
int16_t
restored
=
-
1
-
((
result
[
1
]
<<
8
)
+
result
[
2
]);
CHECK
(
restored
==
-
9263
);
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
}
SECTION
(
"-256..-24"
)
{
for
(
auto
i
=
-
256
;
i
<
-
24
;
++
i
)
{
{
CAPTURE
(
i
);
CAPTURE
(
i
);
...
@@ -91,98 +106,113 @@ TEST_CASE("CBOR")
...
@@ -91,98 +106,113 @@ TEST_CASE("CBOR")
// create expected byte vector
// create expected byte vector
std
::
vector
<
uint8_t
>
expected
;
std
::
vector
<
uint8_t
>
expected
;
expected
.
push_back
(
0x20
-
1
-
static_cast
<
uint8_t
>
(
i
));
expected
.
push_back
(
0x38
);
expected
.
push_back
(
static_cast
<
uint8_t
>
(
-
1
-
i
));
// compare result + size
// compare result + size
const
auto
result
=
json
::
to_cbor
(
j
);
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
CHECK
(
result
==
expected
);
CHECK
(
result
.
size
()
==
1
);
CHECK
(
result
.
size
()
==
2
);
// check individual bytes
// check individual bytes
CHECK
(
static_cast
<
int8_t
>
(
0x20
-
1
-
result
[
0
])
==
i
);
CHECK
(
result
[
0
]
==
0x38
);
CHECK
(
static_cast
<
int16_t
>
(
-
1
-
result
[
1
])
==
i
);
// roundtrip
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
}
}
}
}
/*
SECTION
(
"-24..-1"
)
SECTION("0..127 (positive fixnum)")
{
{
for (
size_t i = 0; i <= 255
; ++i)
for
(
auto
i
=
-
24
;
i
<=
-
1
;
++
i
)
{
{
CAPTURE
(
i
);
CAPTURE
(
i
);
// create JSON value with integer number
// create JSON value with integer number
json j = -1;
json
j
=
i
;
j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
// check type
// check type
CHECK
(
j
.
is_number_integer
());
CHECK
(
j
.
is_number_integer
());
// create expected byte vector
// create expected byte vector
std
::
vector
<
uint8_t
>
expected
;
std
::
vector
<
uint8_t
>
expected
;
expected.push_back(static_cast<uint8_t>(i));
expected
.
push_back
(
0x20
-
1
-
static_cast
<
uint8_t
>
(
i
));
// compare result + size
// compare result + size
const auto result = json::to_
msgpack
(j);
const
auto
result
=
json
::
to_
cbor
(
j
);
CHECK
(
result
==
expected
);
CHECK
(
result
==
expected
);
CHECK
(
result
.
size
()
==
1
);
CHECK
(
result
.
size
()
==
1
);
// check individual bytes
// check individual bytes
CHECK(
result[0]
== i);
CHECK
(
static_cast
<
int8_t
>
(
0x20
-
1
-
result
[
0
])
==
i
);
// roundtrip
// roundtrip
CHECK(json::from_
msgpack
(result) == j);
CHECK
(
json
::
from_
cbor
(
result
)
==
j
);
}
}
}
}
*/
SECTION
(
"
-256..-24
"
)
SECTION
(
"
0..22
"
)
{
{
for
(
auto
i
=
-
256
;
i
<
-
24
;
++
i
)
for
(
size_t
i
=
0
;
i
<=
22
;
++
i
)
{
{
CAPTURE
(
i
);
CAPTURE
(
i
);
// create JSON value with integer number
// create JSON value with integer number
json
j
=
i
;
json
j
=
-
1
;
j
.
get_ref
<
json
::
number_integer_t
&>
()
=
static_cast
<
json
::
number_integer_t
>
(
i
);
// check type
// check type
CHECK
(
j
.
is_number_integer
());
CHECK
(
j
.
is_number_integer
());
// create expected byte vector
// create expected byte vector
std
::
vector
<
uint8_t
>
expected
;
std
::
vector
<
uint8_t
>
expected
;
expected
.
push_back
(
0x38
);
expected
.
push_back
(
static_cast
<
uint8_t
>
(
i
));
expected
.
push_back
(
static_cast
<
uint8_t
>
(
-
1
-
i
));
// compare result + size
// compare result + size
const
auto
result
=
json
::
to_cbor
(
j
);
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
CHECK
(
result
==
expected
);
CHECK
(
result
.
size
()
==
2
);
CHECK
(
result
.
size
()
==
1
);
// check individual bytes
// check individual bytes
CHECK
(
result
[
0
]
==
0x38
);
CHECK
(
result
[
0
]
==
i
);
CHECK
(
static_cast
<
int16_t
>
(
-
1
-
result
[
1
])
==
i
);
// roundtrip
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
}
}
}
}
SECTION
(
"
-9263 (int 16)
"
)
SECTION
(
"
23..255
"
)
{
{
json
j
=
-
9263
;
for
(
size_t
i
=
23
;
i
<=
255
;
++
i
)
std
::
vector
<
uint8_t
>
expected
=
{
0x39
,
0x24
,
0x2e
};
{
CAPTURE
(
i
);
// create JSON value with integer number
json
j
=
-
1
;
j
.
get_ref
<
json
::
number_integer_t
&>
()
=
static_cast
<
json
::
number_integer_t
>
(
i
);
// check type
CHECK
(
j
.
is_number_integer
());
// create expected byte vector
std
::
vector
<
uint8_t
>
expected
;
expected
.
push_back
(
static_cast
<
uint8_t
>
(
0x18
));
expected
.
push_back
(
static_cast
<
uint8_t
>
(
i
));
// compare result + size
const
auto
result
=
json
::
to_cbor
(
j
);
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
CHECK
(
result
==
expected
);
CHECK
(
result
.
size
()
==
2
);
int16_t
restored
=
-
1
-
((
result
[
1
]
<<
8
)
+
result
[
2
]);
// check individual bytes
CHECK
(
restored
==
-
9263
);
CHECK
(
result
[
0
]
==
0x18
);
CHECK
(
result
[
1
]
==
i
);
// roundtrip
// roundtrip
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
CHECK
(
json
::
from_cbor
(
result
)
==
j
);
}
}
}
/*
/*
SECTION("-32768..-129 (int 16)")
SECTION("-32768..-129 (int 16)")
...
...
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