Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
畅游知识海洋
json
提交
8d4f6751
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,发现更多精彩内容 >>
提交
8d4f6751
编写于
12月 28, 2014
作者:
N
Niels
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
+ test cases for clear()
上级
b60fe6e7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
83 addition
and
13 deletion
+83
-13
src/JSON.h
src/JSON.h
+3
-3
test/JSON_unit.cc
test/JSON_unit.cc
+80
-10
未找到文件。
src/JSON.h
浏览文件 @
8d4f6751
...
...
@@ -246,13 +246,13 @@ class JSON
const
JSON
&
at
(
const
int
)
const
;
/// operator to set an element in an object
inline
JSON
&
operator
[](
const
std
::
string
&
);
JSON
&
operator
[](
const
std
::
string
&
);
/// operator to set an element in an object
JSON
&
operator
[](
const
char
*
);
/// operator to get an element in an object
const
JSON
&
operator
[](
const
std
::
string
&
)
const
;
/// operator to set an element in an object
inline
JSON
&
at
(
const
std
::
string
&
);
JSON
&
at
(
const
std
::
string
&
);
/// operator to set an element in an object
JSON
&
at
(
const
char
*
);
/// operator to get an element in an object
...
...
@@ -285,7 +285,7 @@ class JSON
/// lexicographically compares the values
bool
operator
==
(
const
JSON
&
)
const
noexcept
;
/// lexicographically compares the values
inline
bool
operator
!=
(
const
JSON
&
)
const
noexcept
;
bool
operator
!=
(
const
JSON
&
)
const
noexcept
;
/// returns an iterator to the beginning (array/object)
iterator
begin
()
noexcept
;
...
...
test/JSON_unit.cc
浏览文件 @
8d4f6751
...
...
@@ -158,6 +158,12 @@ TEST_CASE("array")
// add initializer list
j
.
push_back
({
"a"
,
"b"
,
"c"
});
CHECK
(
j
.
size
()
==
24
);
// clear()
JSON
j7
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
};;
CHECK
(
j7
.
size
()
==
7
);
j7
.
clear
();
CHECK
(
j7
.
size
()
==
0
);
}
SECTION
(
"Iterators"
)
...
...
@@ -338,16 +344,30 @@ TEST_CASE("object")
const
JSON
k
=
j
;
// read
const
std
::
string
v0
=
j
[
"k0"
];
CHECK
(
v0
==
"v0"
);
auto
v1
=
j
[
"k1"
];
CHECK
(
v1
==
nullptr
);
int
v2
=
j
[
"k2"
];
CHECK
(
v2
==
42
);
double
v3
=
j
[
"k3"
];
CHECK
(
v3
==
3.141
);
bool
v4
=
j
[
"k4"
];
CHECK
(
v4
==
true
);
{
const
std
::
string
v0
=
j
[
"k0"
];
CHECK
(
v0
==
"v0"
);
auto
v1
=
j
[
"k1"
];
CHECK
(
v1
==
nullptr
);
int
v2
=
j
[
"k2"
];
CHECK
(
v2
==
42
);
double
v3
=
j
[
"k3"
];
CHECK
(
v3
==
3.141
);
bool
v4
=
j
[
"k4"
];
CHECK
(
v4
==
true
);
}
{
const
std
::
string
v0
=
j
[
std
::
string
(
"k0"
)];
CHECK
(
v0
==
"v0"
);
auto
v1
=
j
[
std
::
string
(
"k1"
)];
CHECK
(
v1
==
nullptr
);
int
v2
=
j
[
std
::
string
(
"k2"
)];
CHECK
(
v2
==
42
);
double
v3
=
j
[
std
::
string
(
"k3"
)];
CHECK
(
v3
==
3.141
);
bool
v4
=
j
[
std
::
string
(
"k4"
)];
CHECK
(
v4
==
true
);
}
// write (replace)
j
[
"k0"
]
=
"new v0"
;
...
...
@@ -435,6 +455,12 @@ TEST_CASE("object")
JSON
nonarray
=
1
;
CHECK_THROWS_AS
(
const
int
i
=
nonarray
[
"v1"
],
std
::
domain_error
);
CHECK_THROWS_AS
(
nonarray
[
"v1"
]
=
10
,
std
::
domain_error
);
// clear()
JSON
j7
=
{{
"k0"
,
0
},
{
"k1"
,
1
},
{
"k2"
,
2
},
{
"k3"
,
3
}};
CHECK
(
j7
.
size
()
==
4
);
j7
.
clear
();
CHECK
(
j7
.
size
()
==
0
);
}
SECTION
(
"Iterators"
)
...
...
@@ -630,6 +656,14 @@ TEST_CASE("null")
JSON
j1
=
nullptr
;
CHECK
(
j1
.
type
()
==
JSON
::
value_type
::
null
);
}
SECTION
(
"Operators"
)
{
// clear()
JSON
j1
=
nullptr
;
j1
.
clear
();
CHECK
(
j1
==
JSON
(
nullptr
));
}
}
TEST_CASE
(
"string"
)
...
...
@@ -699,6 +733,15 @@ TEST_CASE("string")
JSON
j3
=
std
::
move
(
v3
);
CHECK
(
j3
.
get
<
std
::
string
>
()
==
"Hello, world"
);
}
SECTION
(
"Operators"
)
{
// clear()
JSON
j1
=
std
::
string
(
"Hello, world"
);
CHECK
(
j1
.
get
<
std
::
string
>
()
==
"Hello, world"
);
j1
.
clear
();
CHECK
(
j1
.
get
<
std
::
string
>
()
==
""
);
}
}
TEST_CASE
(
"boolean"
)
...
...
@@ -765,6 +808,15 @@ TEST_CASE("boolean")
bool
v2
=
j2
;
CHECK
(
j2
.
get
<
bool
>
()
==
v2
);
}
SECTION
(
"Operators"
)
{
// clear()
JSON
j1
=
true
;
CHECK
(
j1
.
get
<
bool
>
()
==
true
);
j1
.
clear
();
CHECK
(
j1
.
get
<
bool
>
()
==
false
);
}
}
TEST_CASE
(
"number (int)"
)
...
...
@@ -831,6 +883,15 @@ TEST_CASE("number (int)")
int
v2
=
j2
;
CHECK
(
j2
.
get
<
int
>
()
==
v2
);
}
SECTION
(
"Operators"
)
{
// clear()
JSON
j1
=
42
;
CHECK
(
j1
.
get
<
int
>
()
==
42
);
j1
.
clear
();
CHECK
(
j1
.
get
<
int
>
()
==
0
);
}
}
TEST_CASE
(
"number (float)"
)
...
...
@@ -897,6 +958,15 @@ TEST_CASE("number (float)")
double
v2
=
j2
;
CHECK
(
j2
.
get
<
double
>
()
==
v2
);
}
SECTION
(
"Operators"
)
{
// clear()
JSON
j1
=
3.1415926
;
CHECK
(
j1
.
get
<
double
>
()
==
3.1415926
);
j1
.
clear
();
CHECK
(
j1
.
get
<
double
>
()
==
0.0
);
}
}
TEST_CASE
(
"Parser"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录