Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
畅游知识海洋
json
提交
ea94518a
J
json
项目概览
畅游知识海洋
/
json
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
json
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ea94518a
编写于
12月 28, 2014
作者:
N
Niels
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
+ more test cases
上级
5b1f69ce
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
71 addition
and
4 deletion
+71
-4
src/JSON.cc
src/JSON.cc
+2
-2
src/JSON.h
src/JSON.h
+2
-2
test/JSON_unit.cc
test/JSON_unit.cc
+67
-0
未找到文件。
src/JSON.cc
浏览文件 @
ea94518a
...
...
@@ -285,7 +285,7 @@ JSON::~JSON() noexcept
@param s a string representation of a JSON object
@return a JSON object
*/
JSON
JSON
::
parse
(
std
::
string
&
s
)
JSON
JSON
::
parse
(
const
std
::
string
&
s
)
{
JSON
j
;
Parser
(
s
).
parse
(
j
);
...
...
@@ -1892,7 +1892,7 @@ JSON::Parser::Parser(const char* s)
/*!
@copydoc JSON::Parser::Parser(const char* s)
*/
JSON
::
Parser
::
Parser
(
std
::
string
&
s
)
JSON
::
Parser
::
Parser
(
const
std
::
string
&
s
)
:
_length
(
s
.
length
()),
_buffer
(
new
char
[
_length
+
1
])
{
std
::
strcpy
(
_buffer
,
s
.
c_str
());
...
...
src/JSON.h
浏览文件 @
ea94518a
...
...
@@ -139,7 +139,7 @@ class JSON
~
JSON
()
noexcept
;
/// create from string representation
static
JSON
parse
(
std
::
string
&
);
static
JSON
parse
(
const
std
::
string
&
);
/// create from string representation
static
JSON
parse
(
const
char
*
);
...
...
@@ -387,7 +387,7 @@ class JSON
/// a parser reading from a C string
Parser
(
const
char
*
);
/// a parser reading from a C++ string
Parser
(
std
::
string
&
);
Parser
(
const
std
::
string
&
);
/// a parser reading from an input stream
Parser
(
std
::
istream
&
);
/// destructor of the parser
...
...
test/JSON_unit.cc
浏览文件 @
ea94518a
...
...
@@ -17,6 +17,10 @@ TEST_CASE("array")
// string representation of default value
CHECK
(
j
.
toString
()
==
"[]"
);
// iterators
CHECK
(
j
.
begin
()
!=
j
.
end
());
CHECK
(
j
.
cbegin
()
!=
j
.
cend
());
// check payload
//CHECK(*(j.data().array) == JSON::array_t());
//CHECK(*(j_const.data().array) == JSON::array_t());
...
...
@@ -298,6 +302,10 @@ TEST_CASE("object")
// string representation of default value
CHECK
(
j
.
toString
()
==
"{}"
);
// iterators
CHECK
(
j
.
begin
()
!=
j
.
end
());
CHECK
(
j
.
cbegin
()
!=
j
.
cend
());
// check payload
//CHECK(*(j.data().object) == JSON::object_t());
//CHECK(*(j_const.data().object) == JSON::object_t());
...
...
@@ -678,6 +686,10 @@ TEST_CASE("null")
// string representation of default value
CHECK
(
j
.
toString
()
==
"null"
);
// iterators
CHECK
(
j
.
begin
()
!=
j
.
end
());
CHECK
(
j
.
cbegin
()
!=
j
.
cend
());
// container members
CHECK
(
j
.
size
()
==
0
);
CHECK
(
j
.
empty
()
==
true
);
...
...
@@ -737,6 +749,10 @@ TEST_CASE("string")
// const object
const
JSON
j_const
=
j
;
// iterators
CHECK
(
j
.
begin
()
!=
j
.
end
());
CHECK
(
j
.
cbegin
()
!=
j
.
cend
());
// string representation of default value
CHECK
(
j
.
toString
()
==
"
\"\"
"
);
...
...
@@ -819,6 +835,10 @@ TEST_CASE("boolean")
// const object
const
JSON
j_const
=
j
;
// iterators
CHECK
(
j
.
begin
()
!=
j
.
end
());
CHECK
(
j
.
cbegin
()
!=
j
.
cend
());
// string representation of default value
CHECK
(
j
.
toString
()
==
"false"
);
...
...
@@ -898,6 +918,10 @@ TEST_CASE("number (int)")
// const object
const
JSON
j_const
=
j
;
// iterators
CHECK
(
j
.
begin
()
!=
j
.
end
());
CHECK
(
j
.
cbegin
()
!=
j
.
cend
());
// string representation of default value
CHECK
(
j
.
toString
()
==
"0"
);
...
...
@@ -984,6 +1008,10 @@ TEST_CASE("number (float)")
// const object
const
JSON
j_const
=
j
;
// iterators
CHECK
(
j
.
begin
()
!=
j
.
end
());
CHECK
(
j
.
cbegin
()
!=
j
.
cend
());
// string representation of default value
CHECK
(
j
.
toString
()
==
"0.000000"
);
...
...
@@ -1060,6 +1088,7 @@ TEST_CASE("Comparisons")
JSON
j4
=
nullptr
;
JSON
j5
=
42
;
JSON
j6
=
23.42
;
JSON
j7
=
"hello"
;
CHECK
((
j1
==
j1
)
==
true
);
CHECK
((
j1
==
j2
)
==
false
);
...
...
@@ -1067,6 +1096,7 @@ TEST_CASE("Comparisons")
CHECK
((
j1
==
j4
)
==
false
);
CHECK
((
j1
==
j5
)
==
false
);
CHECK
((
j1
==
j6
)
==
false
);
CHECK
((
j1
==
j7
)
==
false
);
CHECK
((
j2
==
j1
)
==
false
);
CHECK
((
j2
==
j2
)
==
true
);
...
...
@@ -1074,6 +1104,7 @@ TEST_CASE("Comparisons")
CHECK
((
j2
==
j4
)
==
false
);
CHECK
((
j2
==
j5
)
==
false
);
CHECK
((
j2
==
j6
)
==
false
);
CHECK
((
j2
==
j7
)
==
false
);
CHECK
((
j3
==
j1
)
==
false
);
CHECK
((
j3
==
j2
)
==
false
);
...
...
@@ -1081,6 +1112,7 @@ TEST_CASE("Comparisons")
CHECK
((
j3
==
j4
)
==
false
);
CHECK
((
j3
==
j5
)
==
false
);
CHECK
((
j3
==
j6
)
==
false
);
CHECK
((
j3
==
j7
)
==
false
);
CHECK
((
j4
==
j1
)
==
false
);
CHECK
((
j4
==
j2
)
==
false
);
...
...
@@ -1088,6 +1120,7 @@ TEST_CASE("Comparisons")
CHECK
((
j4
==
j4
)
==
true
);
CHECK
((
j4
==
j5
)
==
false
);
CHECK
((
j4
==
j6
)
==
false
);
CHECK
((
j4
==
j7
)
==
false
);
CHECK
((
j5
==
j1
)
==
false
);
CHECK
((
j5
==
j2
)
==
false
);
...
...
@@ -1095,6 +1128,7 @@ TEST_CASE("Comparisons")
CHECK
((
j5
==
j4
)
==
false
);
CHECK
((
j5
==
j5
)
==
true
);
CHECK
((
j5
==
j6
)
==
false
);
CHECK
((
j5
==
j7
)
==
false
);
CHECK
((
j6
==
j1
)
==
false
);
CHECK
((
j6
==
j2
)
==
false
);
...
...
@@ -1102,6 +1136,15 @@ TEST_CASE("Comparisons")
CHECK
((
j6
==
j4
)
==
false
);
CHECK
((
j6
==
j5
)
==
false
);
CHECK
((
j6
==
j6
)
==
true
);
CHECK
((
j6
==
j7
)
==
false
);
CHECK
((
j7
==
j1
)
==
false
);
CHECK
((
j7
==
j2
)
==
false
);
CHECK
((
j7
==
j3
)
==
false
);
CHECK
((
j7
==
j4
)
==
false
);
CHECK
((
j7
==
j5
)
==
false
);
CHECK
((
j7
==
j6
)
==
false
);
CHECK
((
j7
==
j7
)
==
true
);
CHECK
((
j1
!=
j1
)
==
false
);
CHECK
((
j1
!=
j2
)
==
true
);
...
...
@@ -1109,6 +1152,7 @@ TEST_CASE("Comparisons")
CHECK
((
j1
!=
j4
)
==
true
);
CHECK
((
j1
!=
j5
)
==
true
);
CHECK
((
j1
!=
j6
)
==
true
);
CHECK
((
j1
!=
j7
)
==
true
);
CHECK
((
j2
!=
j1
)
==
true
);
CHECK
((
j2
!=
j2
)
==
false
);
...
...
@@ -1116,6 +1160,7 @@ TEST_CASE("Comparisons")
CHECK
((
j2
!=
j4
)
==
true
);
CHECK
((
j2
!=
j5
)
==
true
);
CHECK
((
j2
!=
j6
)
==
true
);
CHECK
((
j2
!=
j7
)
==
true
);
CHECK
((
j3
!=
j1
)
==
true
);
CHECK
((
j3
!=
j2
)
==
true
);
...
...
@@ -1123,6 +1168,7 @@ TEST_CASE("Comparisons")
CHECK
((
j3
!=
j4
)
==
true
);
CHECK
((
j3
!=
j5
)
==
true
);
CHECK
((
j3
!=
j6
)
==
true
);
CHECK
((
j3
!=
j7
)
==
true
);
CHECK
((
j4
!=
j1
)
==
true
);
CHECK
((
j4
!=
j2
)
==
true
);
...
...
@@ -1130,6 +1176,7 @@ TEST_CASE("Comparisons")
CHECK
((
j4
!=
j4
)
==
false
);
CHECK
((
j4
!=
j5
)
==
true
);
CHECK
((
j4
!=
j6
)
==
true
);
CHECK
((
j4
!=
j7
)
==
true
);
CHECK
((
j5
!=
j1
)
==
true
);
CHECK
((
j5
!=
j2
)
==
true
);
...
...
@@ -1137,6 +1184,7 @@ TEST_CASE("Comparisons")
CHECK
((
j5
!=
j4
)
==
true
);
CHECK
((
j5
!=
j5
)
==
false
);
CHECK
((
j5
!=
j6
)
==
true
);
CHECK
((
j5
!=
j7
)
==
true
);
CHECK
((
j6
!=
j1
)
==
true
);
CHECK
((
j6
!=
j2
)
==
true
);
...
...
@@ -1144,6 +1192,15 @@ TEST_CASE("Comparisons")
CHECK
((
j6
!=
j4
)
==
true
);
CHECK
((
j6
!=
j5
)
==
true
);
CHECK
((
j6
!=
j6
)
==
false
);
CHECK
((
j6
!=
j7
)
==
true
);
CHECK
((
j7
!=
j1
)
==
true
);
CHECK
((
j7
!=
j2
)
==
true
);
CHECK
((
j7
!=
j3
)
==
true
);
CHECK
((
j7
!=
j4
)
==
true
);
CHECK
((
j7
!=
j5
)
==
true
);
CHECK
((
j7
!=
j6
)
==
true
);
CHECK
((
j7
!=
j7
)
==
false
);
}
TEST_CASE
(
"Parser"
)
...
...
@@ -1173,6 +1230,10 @@ TEST_CASE("Parser")
CHECK
(
JSON
::
parse
(
"
\"\"
"
)
==
JSON
(
""
));
CHECK
(
JSON
::
parse
(
"
\"
foo
\"
"
)
==
JSON
(
"foo"
));
// escape characters
CHECK_THROWS_AS
(
JSON
::
parse
(
"
\"\\\"
"
),
std
::
invalid_argument
);
CHECK_NOTHROW
(
JSON
::
parse
(
"
\"\\\"\"
"
));
// quotes must be closed
CHECK_THROWS_AS
(
JSON
::
parse
(
"
\"
"
),
std
::
invalid_argument
);
}
...
...
@@ -1299,4 +1360,10 @@ TEST_CASE("Parser")
auto
j3
=
"{
\"
key
\"
:
\"
value
\"
}"
_json
;
CHECK
(
j3
[
"key"
]
==
"value"
);
}
SECTION
(
"Errors"
)
{
CHECK_THROWS_AS
(
JSON
::
parse
(
""
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
JSON
::
parse
(
std
::
string
(
""
)),
std
::
invalid_argument
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录