Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
6cf99fa5
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6cf99fa5
编写于
3月 26, 2013
作者:
E
Erick Tryzelaar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
std: change fail_unless to assert_eq in json.rs
上级
89fc9588
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
128 addition
and
133 deletion
+128
-133
src/libstd/json.rs
src/libstd/json.rs
+128
-133
未找到文件。
src/libstd/json.rs
浏览文件 @
6cf99fa5
...
...
@@ -1214,45 +1214,47 @@ fn mk_object(items: &[(~str, Json)]) -> Json {
#[test]
fn
test_write_null
()
{
fail_unless!
(
to_str
(
&
Null
)
==
~
"null"
);
assert_eq!
(
to_str
(
&
Null
),
~
"null"
);
}
#[test]
fn
test_write_number
()
{
fail_unless!
(
to_str
(
&
Number
(
3
f
))
==
~
"3"
);
fail_unless!
(
to_str
(
&
Number
(
3.1
f
))
==
~
"3.1"
);
fail_unless!
(
to_str
(
&
Number
(
-
1.5
f
))
==
~
"-1.5"
);
fail_unless!
(
to_str
(
&
Number
(
0.5
f
))
==
~
"0.5"
);
assert_eq!
(
to_str
(
&
Number
(
3
f
)),
~
"3"
);
assert_eq!
(
to_str
(
&
Number
(
3.1
f
)),
~
"3.1"
);
assert_eq!
(
to_str
(
&
Number
(
-
1.5
f
)),
~
"-1.5"
);
assert_eq!
(
to_str
(
&
Number
(
0.5
f
)),
~
"0.5"
);
}
#[test]
fn
test_write_str
()
{
fail_unless!
(
to_str
(
&
String
(
~
""
))
==
~
"
\"\"
"
);
fail_unless!
(
to_str
(
&
String
(
~
"foo"
))
==
~
"
\"
foo
\"
"
);
assert_eq!
(
to_str
(
&
String
(
~
""
)),
~
"
\"\"
"
);
assert_eq!
(
to_str
(
&
String
(
~
"foo"
)),
~
"
\"
foo
\"
"
);
}
#[test]
fn
test_write_bool
()
{
fail_unless!
(
to_str
(
&
Boolean
(
true
))
==
~
"true"
);
fail_unless!
(
to_str
(
&
Boolean
(
false
))
==
~
"false"
);
assert_eq!
(
to_str
(
&
Boolean
(
true
)),
~
"true"
);
assert_eq!
(
to_str
(
&
Boolean
(
false
)),
~
"false"
);
}
#[test]
fn
test_write_list
()
{
fail_unless!
(
to_str
(
&
List
(
~
[]))
==
~
"[]"
);
fail_unless!
(
to_str
(
&
List
(
~
[
Boolean
(
true
)]))
==
~
"[true]"
);
fail_unless
!
(
to_str
(
&
List
(
~
[
assert_eq!
(
to_str
(
&
List
(
~
[])),
~
"[]"
);
assert_eq!
(
to_str
(
&
List
(
~
[
Boolean
(
true
)])),
~
"[true]"
);
assert_eq
!
(
to_str
(
&
List
(
~
[
Boolean
(
false
),
Null
,
List
(
~
[
String
(
~
"foo
\n
bar"
),
Number
(
3.5
f
)])
]))
==
~
"[false,null,[
\"
foo
\\
nbar
\"
,3.5]]"
);
]))
,
~
"[false,null,[
\"
foo
\\
nbar
\"
,3.5]]"
);
}
#[test]
fn
test_write_object
()
{
fail_unless!
(
to_str
(
&
mk_object
(
~
[]))
==
~
"{}"
);
fail_unless!
(
to_str
(
&
mk_object
(
~
[(
~
"a"
,
Boolean
(
true
))]))
==
~
"{
\"
a
\"
:true}"
);
assert_eq!
(
to_str
(
&
mk_object
(
~
[])),
~
"{}"
);
assert_eq!
(
to_str
(
&
mk_object
(
~
[(
~
"a"
,
Boolean
(
true
))])),
~
"{
\"
a
\"
:true}"
);
let
a
=
mk_object
(
~
[
(
~
"a"
,
Boolean
(
true
)),
(
~
"b"
,
List
(
~
[
...
...
@@ -1262,248 +1264,241 @@ fn test_write_object() {
]);
// We can't compare the strings directly because the object fields be
// printed in a different order.
let
b
=
result
::
unwrap
(
from_str
(
to_str
(
&
a
))
);
fail_unless!
(
a
==
b
);
let
b
=
from_str
(
to_str
(
&
a
))
.unwrap
(
);
assert_eq!
(
a
,
b
);
}
#[test]
fn
test_write_enum
()
{
let
bw
=
@
io
::
BytesWriter
();
let
bww
:
@
io
::
Writer
=
(
bw
as
@
io
::
Writer
)
;
let
encoder
=
(
@
Encoder
(
bww
)
as
@
serialize
::
Encoder
);
do
encoder
.emit_enum
(
~
"animal"
)
{
do
encoder
.emit_enum_variant
(
~
"frog"
,
37
,
1242
)
{
// name of frog:
do
encoder
.emit_enum_variant_arg
(
0
)
{
encoder
.emit_owned_str
(
~
"Henry"
)
}
// mass of frog in grams:
do
encoder
.emit_enum_variant_arg
(
1
)
{
encoder
.emit_int
(
349
);
let
s
=
do
io
::
with_str_writer
|
wr
|
{
let
encoder
=
&
Encoder
(
wr
)
as
&
serialize
::
Encoder
;
do
encoder
.emit_enum
(
~
"animal"
)
{
do
encoder
.emit_enum_variant
(
~
"frog"
,
37
,
1242
)
{
// name of frog:
do
encoder
.emit_enum_variant_arg
(
0
)
{
encoder
.emit_owned_str
(
~
"Henry"
)
}
// mass of frog in grams:
do
encoder
.emit_enum_variant_arg
(
1
)
{
encoder
.emit_int
(
349
);
}
}
}
}
assert_eq!
(
s
tr
::
from_bytes
(
bw
.bytes
)
,
~
"[
\"
frog
\"
,[
\"
Henry
\"
,349]]"
);
}
;
assert_eq!
(
s
,
~
"[
\"
frog
\"
,[
\"
Henry
\"
,349]]"
);
}
#[test]
fn
test_write_some
()
{
let
bw
=
@
io
::
BytesWriter
();
let
bww
:
@
io
::
Writer
=
(
bw
as
@
io
::
Writer
);
let
encoder
=
(
@
Encoder
(
bww
)
as
@
serialize
::
Encoder
);
do
encoder
.emit_enum
(
~
"Option"
)
{
do
encoder
.emit_enum_variant
(
~
"Some"
,
37
,
1242
)
{
do
encoder
.emit_enum_variant_arg
(
0
)
{
encoder
.emit_owned_str
(
~
"jodhpurs"
)
}
}
}
assert_eq!
(
str
::
from_bytes
(
bw
.bytes
),
~
"
\"
jodhpurs
\"
"
);
fn
test_write_some
()
{
let
value
=
Some
(
~
"jodhpurs"
);
let
s
=
do
io
::
with_str_writer
|
wr
|
{
let
encoder
=
Encoder
(
wr
);
value
.encode
(
&
encoder
);
};
assert_eq!
(
s
,
~
"
\"
jodhpurs
\"
"
);
}
#[test]
fn
test_write_none
()
{
let
bw
=
@
io
::
BytesWriter
();
let
bww
:
@
io
::
Writer
=
(
bw
as
@
io
::
Writer
);
let
encoder
=
(
@
Encoder
(
bww
)
as
@
serialize
::
Encoder
);
do
encoder
.emit_enum
(
~
"Option"
)
{
do
encoder
.emit_enum_variant
(
~
"None"
,
37
,
1242
)
{
}
}
assert_eq!
(
str
::
from_bytes
(
bw
.bytes
),
~
"null"
);
fn
test_write_none
()
{
let
value
:
Option
<~
str
>
=
None
;
let
s
=
do
io
::
with_str_writer
|
wr
|
{
let
encoder
=
Encoder
(
wr
);
value
.encode
(
&
encoder
);
};
assert_eq!
(
s
,
~
"null"
);
}
#[test]
fn
test_trailing_characters
()
{
fail_unless!
(
from_str
(
~
"nulla"
)
==
assert_eq!
(
from_str
(
~
"nulla"
),
Err
(
Error
{
line
:
1u
,
col
:
5u
,
msg
:
@~
"trailing characters"
}));
fail_unless!
(
from_str
(
~
"truea"
)
==
assert_eq!
(
from_str
(
~
"truea"
),
Err
(
Error
{
line
:
1u
,
col
:
5u
,
msg
:
@~
"trailing characters"
}));
fail_unless!
(
from_str
(
~
"falsea"
)
==
assert_eq!
(
from_str
(
~
"falsea"
),
Err
(
Error
{
line
:
1u
,
col
:
6u
,
msg
:
@~
"trailing characters"
}));
fail_unless!
(
from_str
(
~
"1a"
)
==
assert_eq!
(
from_str
(
~
"1a"
),
Err
(
Error
{
line
:
1u
,
col
:
2u
,
msg
:
@~
"trailing characters"
}));
fail_unless!
(
from_str
(
~
"[]a"
)
==
assert_eq!
(
from_str
(
~
"[]a"
),
Err
(
Error
{
line
:
1u
,
col
:
3u
,
msg
:
@~
"trailing characters"
}));
fail_unless!
(
from_str
(
~
"{}a"
)
==
assert_eq!
(
from_str
(
~
"{}a"
),
Err
(
Error
{
line
:
1u
,
col
:
3u
,
msg
:
@~
"trailing characters"
}));
}
#[test]
fn
test_read_identifiers
()
{
fail_unless!
(
from_str
(
~
"n"
)
==
assert_eq!
(
from_str
(
~
"n"
),
Err
(
Error
{
line
:
1u
,
col
:
2u
,
msg
:
@~
"invalid syntax"
}));
fail_unless!
(
from_str
(
~
"nul"
)
==
assert_eq!
(
from_str
(
~
"nul"
),
Err
(
Error
{
line
:
1u
,
col
:
4u
,
msg
:
@~
"invalid syntax"
}));
fail_unless!
(
from_str
(
~
"t"
)
==
assert_eq!
(
from_str
(
~
"t"
),
Err
(
Error
{
line
:
1u
,
col
:
2u
,
msg
:
@~
"invalid syntax"
}));
fail_unless!
(
from_str
(
~
"truz"
)
==
assert_eq!
(
from_str
(
~
"truz"
),
Err
(
Error
{
line
:
1u
,
col
:
4u
,
msg
:
@~
"invalid syntax"
}));
fail_unless!
(
from_str
(
~
"f"
)
==
assert_eq!
(
from_str
(
~
"f"
),
Err
(
Error
{
line
:
1u
,
col
:
2u
,
msg
:
@~
"invalid syntax"
}));
fail_unless!
(
from_str
(
~
"faz"
)
==
assert_eq!
(
from_str
(
~
"faz"
),
Err
(
Error
{
line
:
1u
,
col
:
3u
,
msg
:
@~
"invalid syntax"
}));
fail_unless!
(
from_str
(
~
"null"
)
==
Ok
(
Null
));
fail_unless!
(
from_str
(
~
"true"
)
==
Ok
(
Boolean
(
true
)));
fail_unless!
(
from_str
(
~
"false"
)
==
Ok
(
Boolean
(
false
)));
fail_unless!
(
from_str
(
~
" null "
)
==
Ok
(
Null
));
fail_unless!
(
from_str
(
~
" true "
)
==
Ok
(
Boolean
(
true
)));
fail_unless!
(
from_str
(
~
" false "
)
==
Ok
(
Boolean
(
false
)));
assert_eq!
(
from_str
(
~
"null"
),
Ok
(
Null
));
assert_eq!
(
from_str
(
~
"true"
),
Ok
(
Boolean
(
true
)));
assert_eq!
(
from_str
(
~
"false"
),
Ok
(
Boolean
(
false
)));
assert_eq!
(
from_str
(
~
" null "
),
Ok
(
Null
));
assert_eq!
(
from_str
(
~
" true "
),
Ok
(
Boolean
(
true
)));
assert_eq!
(
from_str
(
~
" false "
),
Ok
(
Boolean
(
false
)));
}
#[test]
fn
test_read_number
()
{
fail_unless!
(
from_str
(
~
"+"
)
==
assert_eq!
(
from_str
(
~
"+"
),
Err
(
Error
{
line
:
1u
,
col
:
1u
,
msg
:
@~
"invalid syntax"
}));
fail_unless!
(
from_str
(
~
"."
)
==
assert_eq!
(
from_str
(
~
"."
),
Err
(
Error
{
line
:
1u
,
col
:
1u
,
msg
:
@~
"invalid syntax"
}));
fail_unless!
(
from_str
(
~
"-"
)
==
assert_eq!
(
from_str
(
~
"-"
),
Err
(
Error
{
line
:
1u
,
col
:
2u
,
msg
:
@~
"invalid number"
}));
fail_unless!
(
from_str
(
~
"00"
)
==
assert_eq!
(
from_str
(
~
"00"
),
Err
(
Error
{
line
:
1u
,
col
:
2u
,
msg
:
@~
"invalid number"
}));
fail_unless!
(
from_str
(
~
"1."
)
==
assert_eq!
(
from_str
(
~
"1."
),
Err
(
Error
{
line
:
1u
,
col
:
3u
,
msg
:
@~
"invalid number"
}));
fail_unless!
(
from_str
(
~
"1e"
)
==
assert_eq!
(
from_str
(
~
"1e"
),
Err
(
Error
{
line
:
1u
,
col
:
3u
,
msg
:
@~
"invalid number"
}));
fail_unless!
(
from_str
(
~
"1e+"
)
==
assert_eq!
(
from_str
(
~
"1e+"
),
Err
(
Error
{
line
:
1u
,
col
:
4u
,
msg
:
@~
"invalid number"
}));
fail_unless!
(
from_str
(
~
"3"
)
==
Ok
(
Number
(
3
f
)));
fail_unless!
(
from_str
(
~
"3.1"
)
==
Ok
(
Number
(
3.1
f
)));
fail_unless!
(
from_str
(
~
"-1.2"
)
==
Ok
(
Number
(
-
1.2
f
)));
fail_unless!
(
from_str
(
~
"0.4"
)
==
Ok
(
Number
(
0.4
f
)));
fail_unless!
(
from_str
(
~
"0.4e5"
)
==
Ok
(
Number
(
0.4e5
f
)));
fail_unless!
(
from_str
(
~
"0.4e+15"
)
==
Ok
(
Number
(
0.4e15
f
)));
fail_unless!
(
from_str
(
~
"0.4e-01"
)
==
Ok
(
Number
(
0.4e-01
f
)));
fail_unless!
(
from_str
(
~
" 3 "
)
==
Ok
(
Number
(
3
f
)));
assert_eq!
(
from_str
(
~
"3"
),
Ok
(
Number
(
3
f
)));
assert_eq!
(
from_str
(
~
"3.1"
),
Ok
(
Number
(
3.1
f
)));
assert_eq!
(
from_str
(
~
"-1.2"
),
Ok
(
Number
(
-
1.2
f
)));
assert_eq!
(
from_str
(
~
"0.4"
),
Ok
(
Number
(
0.4
f
)));
assert_eq!
(
from_str
(
~
"0.4e5"
),
Ok
(
Number
(
0.4e5
f
)));
assert_eq!
(
from_str
(
~
"0.4e+15"
),
Ok
(
Number
(
0.4e15
f
)));
assert_eq!
(
from_str
(
~
"0.4e-01"
),
Ok
(
Number
(
0.4e-01
f
)));
assert_eq!
(
from_str
(
~
" 3 "
),
Ok
(
Number
(
3
f
)));
}
#[test]
fn
test_read_str
()
{
fail_unless!
(
from_str
(
~
"
\"
"
)
==
assert_eq!
(
from_str
(
~
"
\"
"
),
Err
(
Error
{
line
:
1u
,
col
:
2u
,
msg
:
@~
"EOF while parsing string"
}));
fail_unless!
(
from_str
(
~
"
\"
lol"
)
==
assert_eq!
(
from_str
(
~
"
\"
lol"
),
Err
(
Error
{
line
:
1u
,
col
:
5u
,
msg
:
@~
"EOF while parsing string"
}));
fail_unless!
(
from_str
(
~
"
\"\"
"
)
==
Ok
(
String
(
~
""
)));
fail_unless!
(
from_str
(
~
"
\"
foo
\"
"
)
==
Ok
(
String
(
~
"foo"
)));
fail_unless!
(
from_str
(
~
"
\"\\\"\"
"
)
==
Ok
(
String
(
~
"
\"
"
)));
fail_unless!
(
from_str
(
~
"
\"\\
b
\"
"
)
==
Ok
(
String
(
~
"
\x08
"
)));
fail_unless!
(
from_str
(
~
"
\"\\
n
\"
"
)
==
Ok
(
String
(
~
"
\n
"
)));
fail_unless!
(
from_str
(
~
"
\"\\
r
\"
"
)
==
Ok
(
String
(
~
"
\r
"
)));
fail_unless!
(
from_str
(
~
"
\"\\
t
\"
"
)
==
Ok
(
String
(
~
"
\t
"
)));
fail_unless!
(
from_str
(
~
"
\"
foo
\"
"
)
==
Ok
(
String
(
~
"foo"
)));
assert_eq!
(
from_str
(
~
"
\"\"
"
),
Ok
(
String
(
~
""
)));
assert_eq!
(
from_str
(
~
"
\"
foo
\"
"
),
Ok
(
String
(
~
"foo"
)));
assert_eq!
(
from_str
(
~
"
\"\\\"\"
"
),
Ok
(
String
(
~
"
\"
"
)));
assert_eq!
(
from_str
(
~
"
\"\\
b
\"
"
),
Ok
(
String
(
~
"
\x08
"
)));
assert_eq!
(
from_str
(
~
"
\"\\
n
\"
"
),
Ok
(
String
(
~
"
\n
"
)));
assert_eq!
(
from_str
(
~
"
\"\\
r
\"
"
),
Ok
(
String
(
~
"
\r
"
)));
assert_eq!
(
from_str
(
~
"
\"\\
t
\"
"
),
Ok
(
String
(
~
"
\t
"
)));
assert_eq!
(
from_str
(
~
"
\"
foo
\"
"
),
Ok
(
String
(
~
"foo"
)));
}
#[test]
fn
test_unicode_hex_escapes_in_str
()
{
fail_unless!
(
from_str
(
~
"
\"\\
u12ab
\"
"
)
==
Ok
(
String
(
~
"
\u12ab
"
)));
fail_unless!
(
from_str
(
~
"
\"\\
uAB12
\"
"
)
==
Ok
(
String
(
~
"
\uAB12
"
)));
assert_eq!
(
from_str
(
~
"
\"\\
u12ab
\"
"
),
Ok
(
String
(
~
"
\u12ab
"
)));
assert_eq!
(
from_str
(
~
"
\"\\
uAB12
\"
"
),
Ok
(
String
(
~
"
\uAB12
"
)));
}
#[test]
fn
test_read_list
()
{
fail_unless!
(
from_str
(
~
"["
)
==
assert_eq!
(
from_str
(
~
"["
),
Err
(
Error
{
line
:
1u
,
col
:
2u
,
msg
:
@~
"EOF while parsing value"
}));
fail_unless!
(
from_str
(
~
"[1"
)
==
assert_eq!
(
from_str
(
~
"[1"
),
Err
(
Error
{
line
:
1u
,
col
:
3u
,
msg
:
@~
"EOF while parsing list"
}));
fail_unless!
(
from_str
(
~
"[1,"
)
==
assert_eq!
(
from_str
(
~
"[1,"
),
Err
(
Error
{
line
:
1u
,
col
:
4u
,
msg
:
@~
"EOF while parsing value"
}));
fail_unless!
(
from_str
(
~
"[1,]"
)
==
assert_eq!
(
from_str
(
~
"[1,]"
),
Err
(
Error
{
line
:
1u
,
col
:
4u
,
msg
:
@~
"invalid syntax"
}));
fail_unless!
(
from_str
(
~
"[6 7]"
)
==
assert_eq!
(
from_str
(
~
"[6 7]"
),
Err
(
Error
{
line
:
1u
,
col
:
4u
,
msg
:
@~
"expected `,` or `]`"
}));
fail_unless!
(
from_str
(
~
"[]"
)
==
Ok
(
List
(
~
[])));
fail_unless!
(
from_str
(
~
"[ ]"
)
==
Ok
(
List
(
~
[])));
fail_unless!
(
from_str
(
~
"[true]"
)
==
Ok
(
List
(
~
[
Boolean
(
true
)])));
fail_unless!
(
from_str
(
~
"[ false ]"
)
==
Ok
(
List
(
~
[
Boolean
(
false
)])));
fail_unless!
(
from_str
(
~
"[null]"
)
==
Ok
(
List
(
~
[
Null
])));
fail_unless!
(
from_str
(
~
"[3, 1]"
)
==
assert_eq!
(
from_str
(
~
"[]"
),
Ok
(
List
(
~
[])));
assert_eq!
(
from_str
(
~
"[ ]"
),
Ok
(
List
(
~
[])));
assert_eq!
(
from_str
(
~
"[true]"
),
Ok
(
List
(
~
[
Boolean
(
true
)])));
assert_eq!
(
from_str
(
~
"[ false ]"
),
Ok
(
List
(
~
[
Boolean
(
false
)])));
assert_eq!
(
from_str
(
~
"[null]"
),
Ok
(
List
(
~
[
Null
])));
assert_eq!
(
from_str
(
~
"[3, 1]"
),
Ok
(
List
(
~
[
Number
(
3
f
),
Number
(
1
f
)])));
fail_unless!
(
from_str
(
~
"
\n
[3, 2]
\n
"
)
==
assert_eq!
(
from_str
(
~
"
\n
[3, 2]
\n
"
),
Ok
(
List
(
~
[
Number
(
3
f
),
Number
(
2
f
)])));
fail_unless!
(
from_str
(
~
"[2, [4, 1]]"
)
==
assert_eq!
(
from_str
(
~
"[2, [4, 1]]"
),
Ok
(
List
(
~
[
Number
(
2
f
),
List
(
~
[
Number
(
4
f
),
Number
(
1
f
)])])));
}
#[test]
fn
test_read_object
()
{
fail_unless!
(
from_str
(
~
"{"
)
==
assert_eq!
(
from_str
(
~
"{"
),
Err
(
Error
{
line
:
1u
,
col
:
2u
,
msg
:
@~
"EOF while parsing object"
}));
fail_unless!
(
from_str
(
~
"{ "
)
==
assert_eq!
(
from_str
(
~
"{ "
),
Err
(
Error
{
line
:
1u
,
col
:
3u
,
msg
:
@~
"EOF while parsing object"
}));
fail_unless!
(
from_str
(
~
"{1"
)
==
assert_eq!
(
from_str
(
~
"{1"
),
Err
(
Error
{
line
:
1u
,
col
:
2u
,
msg
:
@~
"key must be a string"
}));
fail_unless!
(
from_str
(
~
"{
\"
a
\"
"
)
==
assert_eq!
(
from_str
(
~
"{
\"
a
\"
"
),
Err
(
Error
{
line
:
1u
,
col
:
6u
,
msg
:
@~
"EOF while parsing object"
}));
fail_unless!
(
from_str
(
~
"{
\"
a
\"
"
)
==
assert_eq!
(
from_str
(
~
"{
\"
a
\"
"
),
Err
(
Error
{
line
:
1u
,
col
:
5u
,
msg
:
@~
"EOF while parsing object"
}));
fail_unless!
(
from_str
(
~
"{
\"
a
\"
"
)
==
assert_eq!
(
from_str
(
~
"{
\"
a
\"
"
),
Err
(
Error
{
line
:
1u
,
col
:
6u
,
msg
:
@~
"EOF while parsing object"
}));
fail_unless!
(
from_str
(
~
"{
\"
a
\"
1"
)
==
assert_eq!
(
from_str
(
~
"{
\"
a
\"
1"
),
Err
(
Error
{
line
:
1u
,
col
:
6u
,
msg
:
@~
"expected `:`"
}));
fail_unless!
(
from_str
(
~
"{
\"
a
\"
:"
)
==
assert_eq!
(
from_str
(
~
"{
\"
a
\"
:"
),
Err
(
Error
{
line
:
1u
,
col
:
6u
,
msg
:
@~
"EOF while parsing value"
}));
fail_unless!
(
from_str
(
~
"{
\"
a
\"
:1"
)
==
assert_eq!
(
from_str
(
~
"{
\"
a
\"
:1"
),
Err
(
Error
{
line
:
1u
,
col
:
7u
,
msg
:
@~
"EOF while parsing object"
}));
fail_unless!
(
from_str
(
~
"{
\"
a
\"
:1 1"
)
==
assert_eq!
(
from_str
(
~
"{
\"
a
\"
:1 1"
),
Err
(
Error
{
line
:
1u
,
col
:
8u
,
msg
:
@~
"expected `,` or `}`"
}));
fail_unless!
(
from_str
(
~
"{
\"
a
\"
:1,"
)
==
assert_eq!
(
from_str
(
~
"{
\"
a
\"
:1,"
),
Err
(
Error
{
line
:
1u
,
col
:
8u
,
msg
:
@~
"EOF while parsing object"
}));
fail_unless!
(
result
::
unwrap
(
from_str
(
~
"{}"
))
==
mk_object
(
~
[]));
fail_unless!
(
result
::
unwrap
(
from_str
(
~
"{
\"
a
\"
: 3}"
))
==
assert_eq!
(
result
::
unwrap
(
from_str
(
~
"{}"
)),
mk_object
(
~
[]));
assert_eq!
(
result
::
unwrap
(
from_str
(
~
"{
\"
a
\"
: 3}"
)),
mk_object
(
~
[(
~
"a"
,
Number
(
3.0
f
))]));
fail_unless
!
(
result
::
unwrap
(
from_str
(
~
"{
\"
a
\"
: null,
\"
b
\"
: true }"
))
==
assert_eq
!
(
result
::
unwrap
(
from_str
(
~
"{
\"
a
\"
: null,
\"
b
\"
: true }"
))
,
mk_object
(
~
[
(
~
"a"
,
Null
),
(
~
"b"
,
Boolean
(
true
))]));
fail_unless
!
(
result
::
unwrap
(
from_str
(
~
"
\n
{
\"
a
\"
: null,
\"
b
\"
: true }
\n
"
))
==
assert_eq
!
(
result
::
unwrap
(
from_str
(
~
"
\n
{
\"
a
\"
: null,
\"
b
\"
: true }
\n
"
))
,
mk_object
(
~
[
(
~
"a"
,
Null
),
(
~
"b"
,
Boolean
(
true
))]));
fail_unless
!
(
result
::
unwrap
(
from_str
(
~
"{
\"
a
\"
: 1.0 ,
\"
b
\"
: [ true ]}"
))
==
assert_eq
!
(
result
::
unwrap
(
from_str
(
~
"{
\"
a
\"
: 1.0 ,
\"
b
\"
: [ true ]}"
))
,
mk_object
(
~
[
(
~
"a"
,
Number
(
1.0
)),
(
~
"b"
,
List
(
~
[
Boolean
(
true
)]))
]));
fail_unless
!
(
result
::
unwrap
(
from_str
(
assert_eq
!
(
result
::
unwrap
(
from_str
(
~
"{"
+
~
"
\"
a
\"
: 1.0, "
+
~
"
\"
b
\"
: ["
+
...
...
@@ -1511,7 +1506,7 @@ fn test_read_object() {
~
"
\"
foo
\\
nbar
\"
, "
+
~
"{
\"
c
\"
: {
\"
d
\"
: null} } "
+
~
"]"
+
~
"}"
))
==
~
"}"
))
,
mk_object
(
~
[
(
~
"a"
,
Number
(
1.0
f
)),
(
~
"b"
,
List
(
~
[
...
...
@@ -1526,7 +1521,7 @@ fn test_read_object() {
#[test]
fn
test_multiline_errors
()
{
fail_unless!
(
from_str
(
~
"{
\n
\"
foo
\"
:
\n
\"
bar
\"
"
)
==
assert_eq!
(
from_str
(
~
"{
\n
\"
foo
\"
:
\n
\"
bar
\"
"
),
Err
(
Error
{
line
:
3u
,
col
:
8u
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录