Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5b7d608b
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,发现更多精彩内容 >>
提交
5b7d608b
编写于
3月 30, 2013
作者:
E
Erick Tryzelaar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
std: add more json decoder tests.
上级
f364cf54
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
124 addition
and
12 deletion
+124
-12
src/libstd/json.rs
src/libstd/json.rs
+124
-12
未找到文件。
src/libstd/json.rs
浏览文件 @
5b7d608b
...
...
@@ -1173,6 +1173,22 @@ enum Animal {
Frog
(
~
str
,
int
)
}
#[auto_encode]
#[auto_decode]
#[deriving(Eq)]
struct
Inner
{
a
:
(),
b
:
uint
,
c
:
~
[
~
str
],
}
#[auto_encode]
#[auto_decode]
#[deriving(Eq)]
struct
Outer
{
inner
:
~
[
Inner
],
}
fn
mk_object
(
items
:
&
[(
~
str
,
Json
)])
->
Json
{
let
mut
d
=
~
LinearMap
::
new
();
...
...
@@ -1441,6 +1457,18 @@ fn test_read_identifiers() {
assert_eq!
(
from_str
(
~
" false "
),
Ok
(
Boolean
(
false
)));
}
#[test]
fn
test_decode_identifiers
()
{
let
v
:
()
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"null"
)
.unwrap
()));
assert_eq!
(
v
,
());
let
v
:
bool
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"true"
)
.unwrap
()));
assert_eq!
(
v
,
true
);
let
v
:
bool
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"false"
)
.unwrap
()));
assert_eq!
(
v
,
false
);
}
#[test]
fn
test_read_number
()
{
assert_eq!
(
from_str
(
~
"+"
),
...
...
@@ -1469,6 +1497,30 @@ fn test_read_number() {
assert_eq!
(
from_str
(
~
" 3 "
),
Ok
(
Number
(
3
f
)));
}
#[test]
fn
test_decode_numbers
()
{
let
v
:
float
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"3"
)
.unwrap
()));
assert_eq!
(
v
,
3
f
);
let
v
:
float
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"3.1"
)
.unwrap
()));
assert_eq!
(
v
,
3.1
f
);
let
v
:
float
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"-1.2"
)
.unwrap
()));
assert_eq!
(
v
,
-
1.2
f
);
let
v
:
float
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"0.4"
)
.unwrap
()));
assert_eq!
(
v
,
0.4
f
);
let
v
:
float
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"0.4e5"
)
.unwrap
()));
assert_eq!
(
v
,
0.4e5
f
);
let
v
:
float
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"0.4e15"
)
.unwrap
()));
assert_eq!
(
v
,
0.4e15
f
);
let
v
:
float
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"0.4e-01"
)
.unwrap
()));
assert_eq!
(
v
,
0.4e-01
f
);
}
#[test]
fn
test_read_str
()
{
assert_eq!
(
from_str
(
~
"
\"
"
),
...
...
@@ -1486,12 +1538,38 @@ fn test_read_str() {
assert_eq!
(
from_str
(
~
"
\"\\
r
\"
"
),
Ok
(
String
(
~
"
\r
"
)));
assert_eq!
(
from_str
(
~
"
\"\\
t
\"
"
),
Ok
(
String
(
~
"
\t
"
)));
assert_eq!
(
from_str
(
~
"
\"
foo
\"
"
),
Ok
(
String
(
~
"foo"
)));
assert_eq!
(
from_str
(
~
"
\"\\
u12ab
\"
"
),
Ok
(
String
(
~
"
\u12ab
"
)));
assert_eq!
(
from_str
(
~
"
\"\\
uAB12
\"
"
),
Ok
(
String
(
~
"
\uAB12
"
)));
}
#[test]
fn
test_unicode_hex_escapes_in_str
()
{
assert_eq!
(
from_str
(
~
"
\"\\
u12ab
\"
"
),
Ok
(
String
(
~
"
\u12ab
"
)));
assert_eq!
(
from_str
(
~
"
\"\\
uAB12
\"
"
),
Ok
(
String
(
~
"
\uAB12
"
)));
fn
test_decode_str
()
{
let
v
:
~
str
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"
\"\"
"
)
.unwrap
()));
assert_eq!
(
v
,
~
""
);
let
v
:
~
str
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"
\"
foo
\"
"
)
.unwrap
()));
assert_eq!
(
v
,
~
"foo"
);
let
v
:
~
str
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"
\"\\\"\"
"
)
.unwrap
()));
assert_eq!
(
v
,
~
"
\"
"
);
let
v
:
~
str
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"
\"\\
b
\"
"
)
.unwrap
()));
assert_eq!
(
v
,
~
"
\x08
"
);
let
v
:
~
str
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"
\"\\
n
\"
"
)
.unwrap
()));
assert_eq!
(
v
,
~
"
\n
"
);
let
v
:
~
str
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"
\"\\
r
\"
"
)
.unwrap
()));
assert_eq!
(
v
,
~
"
\r
"
);
let
v
:
~
str
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"
\"\\
t
\"
"
)
.unwrap
()));
assert_eq!
(
v
,
~
"
\t
"
);
let
v
:
~
str
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"
\"\\
u12ab
\"
"
)
.unwrap
()));
assert_eq!
(
v
,
~
"
\u12ab
"
);
let
v
:
~
str
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"
\"\\
uAB12
\"
"
)
.unwrap
()));
assert_eq!
(
v
,
~
"
\uAB12
"
);
}
#[test]
...
...
@@ -1520,6 +1598,28 @@ fn test_read_list() {
Ok
(
List
(
~
[
Number
(
2
f
),
List
(
~
[
Number
(
4
f
),
Number
(
1
f
)])])));
}
#[test]
fn
test_decode_list
()
{
let
v
:
~
[()]
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"[]"
)
.unwrap
()));
assert_eq!
(
v
,
~
[]);
let
v
:
~
[()]
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"[null]"
)
.unwrap
()));
assert_eq!
(
v
,
~
[()]);
let
v
:
~
[
bool
]
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"[true]"
)
.unwrap
()));
assert_eq!
(
v
,
~
[
true
]);
let
v
:
~
[
bool
]
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"[true]"
)
.unwrap
()));
assert_eq!
(
v
,
~
[
true
]);
let
v
:
~
[
int
]
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"[3, 1]"
)
.unwrap
()));
assert_eq!
(
v
,
~
[
3
,
1
]);
let
v
:
~
[
~
[
uint
]]
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
~
"[[3], [1, 2]]"
)
.unwrap
()));
assert_eq!
(
v
,
~
[
~
[
3
],
~
[
1
,
2
]]);
}
#[test]
fn
test_read_object
()
{
assert_eq!
(
from_str
(
~
"{"
),
...
...
@@ -1612,35 +1712,47 @@ fn test_read_object() {
}
#[test]
fn
test_read_none
()
{
fn
test_decode_struct
()
{
let
s
=
~
"{
\"
inner
\"
: [
{
\"
a
\"
: null,
\"
b
\"
: 2,
\"
c
\"
: [
\"
abc
\"
,
\"
xyz
\"
] }
]
}"
;
let
v
:
Outer
=
Decodable
::
decode
(
&
Decoder
(
from_str
(
s
)
.unwrap
()));
assert_eq!
(
v
,
Outer
{
inner
:
~
[
Inner
{
a
:
(),
b
:
2
,
c
:
~
[
~
"abc"
,
~
"xyz"
]
}
]
}
);
}
#[test]
fn
test_decode_option
()
{
let
decoder
=
Decoder
(
from_str
(
~
"null"
)
.unwrap
());
let
value
:
Option
<~
str
>
=
Decodable
::
decode
(
&
decoder
);
assert_eq!
(
value
,
None
);
}
#[test]
fn
test_read_some
()
{
let
decoder
=
Decoder
(
from_str
(
~
"
\"
jodhpurs
\"
"
)
.unwrap
());
let
value
:
Option
<~
str
>
=
Decodable
::
decode
(
&
decoder
);
assert_eq!
(
value
,
Some
(
~
"jodhpurs"
));
}
#[test]
fn
test_
read_enum_no_args
()
{
fn
test_
decode_enum
()
{
let
decoder
=
Decoder
(
from_str
(
~
"
\"
Dog
\"
"
)
.unwrap
());
let
value
:
Animal
=
Decodable
::
decode
(
&
decoder
);
assert_eq!
(
value
,
Dog
);
}
#[test]
fn
test_read_enum_multiple_args
()
{
let
decoder
=
Decoder
(
from_str
(
~
"[
\"
Frog
\"
,
\"
Henry
\"
,349]"
)
.unwrap
());
let
value
:
Animal
=
Decodable
::
decode
(
&
decoder
);
assert_eq!
(
value
,
Frog
(
~
"Henry"
,
349
));
}
#[test]
fn
test_
read
_map
()
{
fn
test_
decode
_map
()
{
let
s
=
~
"{
\"
a
\"
:
\"
Dog
\"
,
\"
b
\"
: [
\"
Frog
\"
,
\"
Henry
\"
, 349]}"
;
let
decoder
=
Decoder
(
from_str
(
s
)
.unwrap
());
let
mut
map
:
LinearMap
<~
str
,
Animal
>
=
Decodable
::
decode
(
&
decoder
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录