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
0cfd0f5d
Commit
0cfd0f5d
authored
Feb 09, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added test cases and fixed some warnings
parent
0df642de
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
8 deletions
+115
-8
src/json.hpp
src/json.hpp
+5
-3
src/json.hpp.re2c
src/json.hpp.re2c
+5
-3
test/unit.cpp
test/unit.cpp
+105
-2
No files found.
src/json.hpp
View file @
0cfd0f5d
...
@@ -443,8 +443,9 @@ class basic_json
...
@@ -443,8 +443,9 @@ class basic_json
}
}
/// copy assignment
/// copy assignment
inline
reference
operator
=
(
basic_json
other
)
noexcept
inline
reference
&
operator
=
(
basic_json
other
)
noexcept
{
{
assert
(
false
);
// not sure if function will ever be called
std
::
swap
(
m_type
,
other
.
m_type
);
std
::
swap
(
m_type
,
other
.
m_type
);
std
::
swap
(
m_value
,
other
.
m_value
);
std
::
swap
(
m_value
,
other
.
m_value
);
return
*
this
;
return
*
this
;
...
@@ -1704,6 +1705,7 @@ class basic_json
...
@@ -1704,6 +1705,7 @@ class basic_json
/// copy assignment
/// copy assignment
inline
iterator
&
operator
=
(
const
iterator
&
other
)
noexcept
inline
iterator
&
operator
=
(
const
iterator
&
other
)
noexcept
{
{
assert
(
false
);
// not sure if function will ever be called
m_object
=
other
.
m_object
;
m_object
=
other
.
m_object
;
m_it
=
other
.
m_it
;
m_it
=
other
.
m_it
;
return
*
this
;
return
*
this
;
...
@@ -2085,7 +2087,7 @@ class basic_json
...
@@ -2085,7 +2087,7 @@ class basic_json
}
}
/// copy assignment
/// copy assignment
inline
const_iterator
operator
=
(
const
const_iterator
&
other
)
noexcept
inline
const_iterator
&
operator
=
(
const
const_iterator
&
other
)
noexcept
{
{
m_object
=
other
.
m_object
;
m_object
=
other
.
m_object
;
m_it
=
other
.
m_it
;
m_it
=
other
.
m_it
;
...
@@ -3329,7 +3331,7 @@ json_parser_60:
...
@@ -3329,7 +3331,7 @@ json_parser_60:
}
}
}
}
inline
std
::
string
token_type_name
(
token_type
t
)
inline
st
atic
st
d
::
string
token_type_name
(
token_type
t
)
{
{
switch
(
t
)
switch
(
t
)
{
{
...
...
src/json.hpp.re2c
View file @
0cfd0f5d
...
@@ -443,8 +443,9 @@ class basic_json
...
@@ -443,8 +443,9 @@ class basic_json
}
}
/// copy assignment
/// copy assignment
inline reference operator=(basic_json other) noexcept
inline reference
&
operator=(basic_json other) noexcept
{
{
assert(false); // not sure if function will ever be called
std::swap(m_type, other.m_type);
std::swap(m_type, other.m_type);
std::swap(m_value, other.m_value);
std::swap(m_value, other.m_value);
return *this;
return *this;
...
@@ -1704,6 +1705,7 @@ class basic_json
...
@@ -1704,6 +1705,7 @@ class basic_json
/// copy assignment
/// copy assignment
inline iterator& operator=(const iterator& other) noexcept
inline iterator& operator=(const iterator& other) noexcept
{
{
assert(false); // not sure if function will ever be called
m_object = other.m_object;
m_object = other.m_object;
m_it = other.m_it;
m_it = other.m_it;
return *this;
return *this;
...
@@ -2085,7 +2087,7 @@ class basic_json
...
@@ -2085,7 +2087,7 @@ class basic_json
}
}
/// copy assignment
/// copy assignment
inline const_iterator operator=(const const_iterator& other) noexcept
inline const_iterator
&
operator=(const const_iterator& other) noexcept
{
{
m_object = other.m_object;
m_object = other.m_object;
m_it = other.m_it;
m_it = other.m_it;
...
@@ -2689,7 +2691,7 @@ class basic_json
...
@@ -2689,7 +2691,7 @@ class basic_json
}
}
}
}
inline std::string token_type_name(token_type t)
inline st
atic st
d::string token_type_name(token_type t)
{
{
switch (t)
switch (t)
{
{
...
...
test/unit.cpp
View file @
0cfd0f5d
...
@@ -2518,8 +2518,8 @@ TEST_CASE("iterators")
...
@@ -2518,8 +2518,8 @@ TEST_CASE("iterators")
SECTION
(
"const json + begin/end"
)
SECTION
(
"const json + begin/end"
)
{
{
json
::
iterator
it_begin
=
j_const
.
begin
();
json
::
const_
iterator
it_begin
=
j_const
.
begin
();
json
::
iterator
it_end
=
j_const
.
end
();
json
::
const_
iterator
it_end
=
j_const
.
end
();
auto
it
=
it_begin
;
auto
it
=
it_begin
;
CHECK
(
it
!=
it_end
);
CHECK
(
it
!=
it_end
);
...
@@ -3464,4 +3464,107 @@ TEST_CASE("modifiers")
...
@@ -3464,4 +3464,107 @@ TEST_CASE("modifiers")
CHECK
(
j
==
json
(
json
::
value_t
::
null
));
CHECK
(
j
==
json
(
json
::
value_t
::
null
));
}
}
}
}
SECTION
(
"swap()"
)
{
SECTION
(
"json"
)
{
SECTION
(
"member swap"
)
{
json
j
(
"hello world"
);
json
k
(
42.23
);
j
.
swap
(
k
);
CHECK
(
j
==
json
(
42.23
));
CHECK
(
k
==
json
(
"hello world"
));
}
SECTION
(
"nonmember swap"
)
{
json
j
(
"hello world"
);
json
k
(
42.23
);
std
::
swap
(
j
,
k
);
CHECK
(
j
==
json
(
42.23
));
CHECK
(
k
==
json
(
"hello world"
));
}
}
SECTION
(
"array_t"
)
{
SECTION
(
"array_t type"
)
{
json
j
=
{
1
,
2
,
3
,
4
};
json
::
array_t
a
=
{
"foo"
,
"bar"
,
"baz"
};
j
.
swap
(
a
);
CHECK
(
j
==
json
({
"foo"
,
"bar"
,
"baz"
}));
j
.
swap
(
a
);
CHECK
(
j
==
json
({
1
,
2
,
3
,
4
}));
}
SECTION
(
"non-array_t type"
)
{
json
j
=
17
;
json
::
array_t
a
=
{
"foo"
,
"bar"
,
"baz"
};
CHECK_THROWS_AS
(
j
.
swap
(
a
),
std
::
runtime_error
);
}
}
SECTION
(
"object_t"
)
{
SECTION
(
"object_t type"
)
{
json
j
=
{{
"one"
,
1
},
{
"two"
,
2
}};
json
::
object_t
o
=
{{
"cow"
,
"Kuh"
},
{
"chicken"
,
"Huhn"
}};
j
.
swap
(
o
);
CHECK
(
j
==
json
({{
"cow"
,
"Kuh"
},
{
"chicken"
,
"Huhn"
}}));
j
.
swap
(
o
);
CHECK
(
j
==
json
({{
"one"
,
1
},
{
"two"
,
2
}}));
}
SECTION
(
"non-object_t type"
)
{
json
j
=
17
;
json
::
object_t
o
=
{{
"cow"
,
"Kuh"
},
{
"chicken"
,
"Huhn"
}};
CHECK_THROWS_AS
(
j
.
swap
(
o
),
std
::
runtime_error
);
}
}
SECTION
(
"string_t"
)
{
SECTION
(
"string_t type"
)
{
json
j
=
"Hello world"
;
json
::
string_t
s
=
"Hallo Welt"
;
j
.
swap
(
s
);
CHECK
(
j
==
json
(
"Hallo Welt"
));
j
.
swap
(
s
);
CHECK
(
j
==
json
(
"Hello world"
));
}
SECTION
(
"non-string_t type"
)
{
json
j
=
17
;
json
::
string_t
s
=
"Hallo Welt"
;
CHECK_THROWS_AS
(
j
.
swap
(
s
),
std
::
runtime_error
);
}
}
}
}
}
\ No newline at end of file
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