Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5257a5b2
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,发现更多精彩内容 >>
提交
5257a5b2
编写于
11月 27, 2014
作者:
J
Jorge Aparicio
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
libcoretest: remove unnecessary `as_slice()` calls
上级
0ac3b166
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
139 addition
and
139 deletion
+139
-139
src/libcoretest/cell.rs
src/libcoretest/cell.rs
+4
-4
src/libcoretest/char.rs
src/libcoretest/char.rs
+19
-19
src/libcoretest/fmt/num.rs
src/libcoretest/fmt/num.rs
+107
-107
src/libcoretest/option.rs
src/libcoretest/option.rs
+4
-4
src/libcoretest/result.rs
src/libcoretest/result.rs
+2
-2
src/libcoretest/tuple.rs
src/libcoretest/tuple.rs
+3
-3
未找到文件。
src/libcoretest/cell.rs
浏览文件 @
5257a5b2
...
...
@@ -29,10 +29,10 @@ fn smoketest_cell() {
#[test]
fn
cell_has_sensible_show
()
{
let
x
=
Cell
::
new
(
"foo bar"
);
assert
!
(
format!
(
"{}"
,
x
)
.
as_slice
()
.
contains
(
x
.get
()));
assert
!
(
format!
(
"{}"
,
x
)
.contains
(
x
.get
()));
x
.set
(
"baz qux"
);
assert
!
(
format!
(
"{}"
,
x
)
.
as_slice
()
.
contains
(
x
.get
()));
assert
!
(
format!
(
"{}"
,
x
)
.contains
(
x
.get
()));
}
#[test]
...
...
@@ -40,11 +40,11 @@ fn ref_and_refmut_have_sensible_show() {
let
refcell
=
RefCell
::
new
(
"foo"
);
let
refcell_refmut
=
refcell
.borrow_mut
();
assert
!
(
format!
(
"{}"
,
refcell_refmut
)
.
as_slice
()
.
contains
(
"foo"
));
assert
!
(
format!
(
"{}"
,
refcell_refmut
)
.contains
(
"foo"
));
drop
(
refcell_refmut
);
let
refcell_ref
=
refcell
.borrow
();
assert
!
(
format!
(
"{}"
,
refcell_ref
)
.
as_slice
()
.
contains
(
"foo"
));
assert
!
(
format!
(
"{}"
,
refcell_ref
)
.contains
(
"foo"
));
drop
(
refcell_ref
);
}
...
...
src/libcoretest/char.rs
浏览文件 @
5257a5b2
...
...
@@ -121,31 +121,31 @@ fn string(c: char) -> String {
return
result
;
}
let
s
=
string
(
'\n'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
n"
);
assert_eq!
(
s
,
"
\\
n"
);
let
s
=
string
(
'\r'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
r"
);
assert_eq!
(
s
,
"
\\
r"
);
let
s
=
string
(
'\''
);
assert_eq!
(
s
.as_slice
()
,
"
\\
'"
);
assert_eq!
(
s
,
"
\\
'"
);
let
s
=
string
(
'"'
);
assert_eq!
(
s
.as_slice
()
,
"
\\\"
"
);
assert_eq!
(
s
,
"
\\\"
"
);
let
s
=
string
(
' '
);
assert_eq!
(
s
.as_slice
()
,
" "
);
assert_eq!
(
s
,
" "
);
let
s
=
string
(
'a'
);
assert_eq!
(
s
.as_slice
()
,
"a"
);
assert_eq!
(
s
,
"a"
);
let
s
=
string
(
'~'
);
assert_eq!
(
s
.as_slice
()
,
"~"
);
assert_eq!
(
s
,
"~"
);
let
s
=
string
(
'\x00'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
x00"
);
assert_eq!
(
s
,
"
\\
x00"
);
let
s
=
string
(
'\x1f'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
x1f"
);
assert_eq!
(
s
,
"
\\
x1f"
);
let
s
=
string
(
'\x7f'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
x7f"
);
assert_eq!
(
s
,
"
\\
x7f"
);
let
s
=
string
(
'\u00ff'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
u00ff"
);
assert_eq!
(
s
,
"
\\
u00ff"
);
let
s
=
string
(
'\u011b'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
u011b"
);
assert_eq!
(
s
,
"
\\
u011b"
);
let
s
=
string
(
'\U0001d4b6'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
U0001d4b6"
);
assert_eq!
(
s
,
"
\\
U0001d4b6"
);
}
#[test]
...
...
@@ -156,17 +156,17 @@ fn string(c: char) -> String {
return
result
;
}
let
s
=
string
(
'\x00'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
x00"
);
assert_eq!
(
s
,
"
\\
x00"
);
let
s
=
string
(
'\n'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
x0a"
);
assert_eq!
(
s
,
"
\\
x0a"
);
let
s
=
string
(
' '
);
assert_eq!
(
s
.as_slice
()
,
"
\\
x20"
);
assert_eq!
(
s
,
"
\\
x20"
);
let
s
=
string
(
'a'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
x61"
);
assert_eq!
(
s
,
"
\\
x61"
);
let
s
=
string
(
'\u011b'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
u011b"
);
assert_eq!
(
s
,
"
\\
u011b"
);
let
s
=
string
(
'\U0001d4b6'
);
assert_eq!
(
s
.as_slice
()
,
"
\\
U0001d4b6"
);
assert_eq!
(
s
,
"
\\
U0001d4b6"
);
}
#[test]
...
...
src/libcoretest/fmt/num.rs
浏览文件 @
5257a5b2
...
...
@@ -16,136 +16,136 @@ fn test_format_int() {
// Formatting integers should select the right implementation based off
// the type of the argument. Also, hex/octal/binary should be defined
// for integers, but they shouldn't emit the negative sign.
assert
!
(
format!
(
"{}"
,
1
i
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{}"
,
1i8
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{}"
,
1i16
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{}"
,
1i32
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{}"
,
1i64
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{}"
,
-
1
i
)
.as_slice
()
==
"-1"
);
assert
!
(
format!
(
"{}"
,
-
1i8
)
.as_slice
()
==
"-1"
);
assert
!
(
format!
(
"{}"
,
-
1i16
)
.as_slice
()
==
"-1"
);
assert
!
(
format!
(
"{}"
,
-
1i32
)
.as_slice
()
==
"-1"
);
assert
!
(
format!
(
"{}"
,
-
1i64
)
.as_slice
()
==
"-1"
);
assert
!
(
format!
(
"{:b}"
,
1
i
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1i8
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1i16
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1i32
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1i64
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1
i
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1i8
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1i16
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1i32
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1i64
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1
i
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1i8
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1i16
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1i32
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1i64
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1
i
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1i8
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1i16
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1i32
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1i64
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{}"
,
1u
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{}"
,
1u8
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{}"
,
1u16
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{}"
,
1u32
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{}"
,
1u64
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1u
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1u8
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1u16
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1u32
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1u64
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1u
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1u8
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1u16
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1u32
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1u64
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1u
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1u8
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1u16
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1u32
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1u64
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1u
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1u8
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1u16
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1u32
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1u64
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{}"
,
1
i
)
==
"1"
);
assert
!
(
format!
(
"{}"
,
1i8
)
==
"1"
);
assert
!
(
format!
(
"{}"
,
1i16
)
==
"1"
);
assert
!
(
format!
(
"{}"
,
1i32
)
==
"1"
);
assert
!
(
format!
(
"{}"
,
1i64
)
==
"1"
);
assert
!
(
format!
(
"{}"
,
-
1
i
)
==
"-1"
);
assert
!
(
format!
(
"{}"
,
-
1i8
)
==
"-1"
);
assert
!
(
format!
(
"{}"
,
-
1i16
)
==
"-1"
);
assert
!
(
format!
(
"{}"
,
-
1i32
)
==
"-1"
);
assert
!
(
format!
(
"{}"
,
-
1i64
)
==
"-1"
);
assert
!
(
format!
(
"{:b}"
,
1
i
)
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1i8
)
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1i16
)
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1i32
)
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1i64
)
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1
i
)
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1i8
)
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1i16
)
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1i32
)
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1i64
)
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1
i
)
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1i8
)
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1i16
)
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1i32
)
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1i64
)
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1
i
)
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1i8
)
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1i16
)
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1i32
)
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1i64
)
==
"1"
);
assert
!
(
format!
(
"{}"
,
1u
)
==
"1"
);
assert
!
(
format!
(
"{}"
,
1u8
)
==
"1"
);
assert
!
(
format!
(
"{}"
,
1u16
)
==
"1"
);
assert
!
(
format!
(
"{}"
,
1u32
)
==
"1"
);
assert
!
(
format!
(
"{}"
,
1u64
)
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1u
)
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1u8
)
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1u16
)
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1u32
)
==
"1"
);
assert
!
(
format!
(
"{:b}"
,
1u64
)
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1u
)
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1u8
)
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1u16
)
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1u32
)
==
"1"
);
assert
!
(
format!
(
"{:x}"
,
1u64
)
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1u
)
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1u8
)
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1u16
)
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1u32
)
==
"1"
);
assert
!
(
format!
(
"{:X}"
,
1u64
)
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1u
)
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1u8
)
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1u16
)
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1u32
)
==
"1"
);
assert
!
(
format!
(
"{:o}"
,
1u64
)
==
"1"
);
// Test a larger number
assert
!
(
format!
(
"{:b}"
,
55
i
)
.as_slice
()
==
"110111"
);
assert
!
(
format!
(
"{:o}"
,
55
i
)
.as_slice
()
==
"67"
);
assert
!
(
format!
(
"{}"
,
55
i
)
.as_slice
()
==
"55"
);
assert
!
(
format!
(
"{:x}"
,
55
i
)
.as_slice
()
==
"37"
);
assert
!
(
format!
(
"{:X}"
,
55
i
)
.as_slice
()
==
"37"
);
assert
!
(
format!
(
"{:b}"
,
55
i
)
==
"110111"
);
assert
!
(
format!
(
"{:o}"
,
55
i
)
==
"67"
);
assert
!
(
format!
(
"{}"
,
55
i
)
==
"55"
);
assert
!
(
format!
(
"{:x}"
,
55
i
)
==
"37"
);
assert
!
(
format!
(
"{:X}"
,
55
i
)
==
"37"
);
}
#[test]
fn
test_format_int_zero
()
{
assert
!
(
format!
(
"{}"
,
0
i
)
.as_slice
()
==
"0"
);
assert
!
(
format!
(
"{:b}"
,
0
i
)
.as_slice
()
==
"0"
);
assert
!
(
format!
(
"{:o}"
,
0
i
)
.as_slice
()
==
"0"
);
assert
!
(
format!
(
"{:x}"
,
0
i
)
.as_slice
()
==
"0"
);
assert
!
(
format!
(
"{:X}"
,
0
i
)
.as_slice
()
==
"0"
);
assert
!
(
format!
(
"{}"
,
0u
)
.as_slice
()
==
"0"
);
assert
!
(
format!
(
"{:b}"
,
0u
)
.as_slice
()
==
"0"
);
assert
!
(
format!
(
"{:o}"
,
0u
)
.as_slice
()
==
"0"
);
assert
!
(
format!
(
"{:x}"
,
0u
)
.as_slice
()
==
"0"
);
assert
!
(
format!
(
"{:X}"
,
0u
)
.as_slice
()
==
"0"
);
assert
!
(
format!
(
"{}"
,
0
i
)
==
"0"
);
assert
!
(
format!
(
"{:b}"
,
0
i
)
==
"0"
);
assert
!
(
format!
(
"{:o}"
,
0
i
)
==
"0"
);
assert
!
(
format!
(
"{:x}"
,
0
i
)
==
"0"
);
assert
!
(
format!
(
"{:X}"
,
0
i
)
==
"0"
);
assert
!
(
format!
(
"{}"
,
0u
)
==
"0"
);
assert
!
(
format!
(
"{:b}"
,
0u
)
==
"0"
);
assert
!
(
format!
(
"{:o}"
,
0u
)
==
"0"
);
assert
!
(
format!
(
"{:x}"
,
0u
)
==
"0"
);
assert
!
(
format!
(
"{:X}"
,
0u
)
==
"0"
);
}
#[test]
fn
test_format_int_flags
()
{
assert
!
(
format!
(
"{:3}"
,
1
i
)
.as_slice
()
==
" 1"
);
assert
!
(
format!
(
"{:>3}"
,
1
i
)
.as_slice
()
==
" 1"
);
assert
!
(
format!
(
"{:>+3}"
,
1
i
)
.as_slice
()
==
" +1"
);
assert
!
(
format!
(
"{:<3}"
,
1
i
)
.as_slice
()
==
"1 "
);
assert
!
(
format!
(
"{:#}"
,
1
i
)
.as_slice
()
==
"1"
);
assert
!
(
format!
(
"{:#x}"
,
10
i
)
.as_slice
()
==
"0xa"
);
assert
!
(
format!
(
"{:#X}"
,
10
i
)
.as_slice
()
==
"0xA"
);
assert
!
(
format!
(
"{:#5x}"
,
10
i
)
.as_slice
()
==
" 0xa"
);
assert
!
(
format!
(
"{:#o}"
,
10
i
)
.as_slice
()
==
"0o12"
);
assert
!
(
format!
(
"{:08x}"
,
10
i
)
.as_slice
()
==
"0000000a"
);
assert
!
(
format!
(
"{:8x}"
,
10
i
)
.as_slice
()
==
" a"
);
assert
!
(
format!
(
"{:<8x}"
,
10
i
)
.as_slice
()
==
"a "
);
assert
!
(
format!
(
"{:>8x}"
,
10
i
)
.as_slice
()
==
" a"
);
assert
!
(
format!
(
"{:#08x}"
,
10
i
)
.as_slice
()
==
"0x00000a"
);
assert
!
(
format!
(
"{:08}"
,
-
10
i
)
.as_slice
()
==
"-0000010"
);
assert
!
(
format!
(
"{:x}"
,
-
1u8
)
.as_slice
()
==
"ff"
);
assert
!
(
format!
(
"{:X}"
,
-
1u8
)
.as_slice
()
==
"FF"
);
assert
!
(
format!
(
"{:b}"
,
-
1u8
)
.as_slice
()
==
"11111111"
);
assert
!
(
format!
(
"{:o}"
,
-
1u8
)
.as_slice
()
==
"377"
);
assert
!
(
format!
(
"{:#x}"
,
-
1u8
)
.as_slice
()
==
"0xff"
);
assert
!
(
format!
(
"{:#X}"
,
-
1u8
)
.as_slice
()
==
"0xFF"
);
assert
!
(
format!
(
"{:#b}"
,
-
1u8
)
.as_slice
()
==
"0b11111111"
);
assert
!
(
format!
(
"{:#o}"
,
-
1u8
)
.as_slice
()
==
"0o377"
);
assert
!
(
format!
(
"{:3}"
,
1
i
)
==
" 1"
);
assert
!
(
format!
(
"{:>3}"
,
1
i
)
==
" 1"
);
assert
!
(
format!
(
"{:>+3}"
,
1
i
)
==
" +1"
);
assert
!
(
format!
(
"{:<3}"
,
1
i
)
==
"1 "
);
assert
!
(
format!
(
"{:#}"
,
1
i
)
==
"1"
);
assert
!
(
format!
(
"{:#x}"
,
10
i
)
==
"0xa"
);
assert
!
(
format!
(
"{:#X}"
,
10
i
)
==
"0xA"
);
assert
!
(
format!
(
"{:#5x}"
,
10
i
)
==
" 0xa"
);
assert
!
(
format!
(
"{:#o}"
,
10
i
)
==
"0o12"
);
assert
!
(
format!
(
"{:08x}"
,
10
i
)
==
"0000000a"
);
assert
!
(
format!
(
"{:8x}"
,
10
i
)
==
" a"
);
assert
!
(
format!
(
"{:<8x}"
,
10
i
)
==
"a "
);
assert
!
(
format!
(
"{:>8x}"
,
10
i
)
==
" a"
);
assert
!
(
format!
(
"{:#08x}"
,
10
i
)
==
"0x00000a"
);
assert
!
(
format!
(
"{:08}"
,
-
10
i
)
==
"-0000010"
);
assert
!
(
format!
(
"{:x}"
,
-
1u8
)
==
"ff"
);
assert
!
(
format!
(
"{:X}"
,
-
1u8
)
==
"FF"
);
assert
!
(
format!
(
"{:b}"
,
-
1u8
)
==
"11111111"
);
assert
!
(
format!
(
"{:o}"
,
-
1u8
)
==
"377"
);
assert
!
(
format!
(
"{:#x}"
,
-
1u8
)
==
"0xff"
);
assert
!
(
format!
(
"{:#X}"
,
-
1u8
)
==
"0xFF"
);
assert
!
(
format!
(
"{:#b}"
,
-
1u8
)
==
"0b11111111"
);
assert
!
(
format!
(
"{:#o}"
,
-
1u8
)
==
"0o377"
);
}
#[test]
fn
test_format_int_sign_padding
()
{
assert
!
(
format!
(
"{:+5}"
,
1
i
)
.as_slice
()
==
" +1"
);
assert
!
(
format!
(
"{:+5}"
,
-
1
i
)
.as_slice
()
==
" -1"
);
assert
!
(
format!
(
"{:05}"
,
1
i
)
.as_slice
()
==
"00001"
);
assert
!
(
format!
(
"{:05}"
,
-
1
i
)
.as_slice
()
==
"-0001"
);
assert
!
(
format!
(
"{:+05}"
,
1
i
)
.as_slice
()
==
"+0001"
);
assert
!
(
format!
(
"{:+05}"
,
-
1
i
)
.as_slice
()
==
"-0001"
);
assert
!
(
format!
(
"{:+5}"
,
1
i
)
==
" +1"
);
assert
!
(
format!
(
"{:+5}"
,
-
1
i
)
==
" -1"
);
assert
!
(
format!
(
"{:05}"
,
1
i
)
==
"00001"
);
assert
!
(
format!
(
"{:05}"
,
-
1
i
)
==
"-0001"
);
assert
!
(
format!
(
"{:+05}"
,
1
i
)
==
"+0001"
);
assert
!
(
format!
(
"{:+05}"
,
-
1
i
)
==
"-0001"
);
}
#[test]
fn
test_format_int_twos_complement
()
{
use
core
::{
i8
,
i16
,
i32
,
i64
};
assert
!
(
format!
(
"{}"
,
i8
::
MIN
)
.as_slice
()
==
"-128"
);
assert
!
(
format!
(
"{}"
,
i16
::
MIN
)
.as_slice
()
==
"-32768"
);
assert
!
(
format!
(
"{}"
,
i32
::
MIN
)
.as_slice
()
==
"-2147483648"
);
assert
!
(
format!
(
"{}"
,
i64
::
MIN
)
.as_slice
()
==
"-9223372036854775808"
);
assert
!
(
format!
(
"{}"
,
i8
::
MIN
)
==
"-128"
);
assert
!
(
format!
(
"{}"
,
i16
::
MIN
)
==
"-32768"
);
assert
!
(
format!
(
"{}"
,
i32
::
MIN
)
==
"-2147483648"
);
assert
!
(
format!
(
"{}"
,
i64
::
MIN
)
==
"-9223372036854775808"
);
}
#[test]
fn
test_format_radix
()
{
assert
!
(
format!
(
"{:04}"
,
radix
(
3
i
,
2
))
.as_slice
()
==
"0011"
);
assert
!
(
format!
(
"{}"
,
radix
(
55
i
,
36
))
.as_slice
()
==
"1j"
);
assert
!
(
format!
(
"{:04}"
,
radix
(
3
i
,
2
))
==
"0011"
);
assert
!
(
format!
(
"{}"
,
radix
(
55
i
,
36
))
==
"1j"
);
}
#[test]
...
...
src/libcoretest/option.rs
浏览文件 @
5257a5b2
...
...
@@ -28,10 +28,10 @@ fn test_get_ptr() {
#[test]
fn
test_get_str
()
{
let
x
=
"test"
.to_string
();
let
addr_x
=
x
.as_
slice
()
.as_
ptr
();
let
addr_x
=
x
.as_ptr
();
let
opt
=
Some
(
x
);
let
y
=
opt
.unwrap
();
let
addr_y
=
y
.as_
slice
()
.as_
ptr
();
let
addr_y
=
y
.as_ptr
();
assert_eq!
(
addr_x
,
addr_y
);
}
...
...
@@ -135,7 +135,7 @@ fn test_or_else() {
fn
test_unwrap
()
{
assert_eq!
(
Some
(
1
i
)
.unwrap
(),
1
);
let
s
=
Some
(
"hello"
.to_string
())
.unwrap
();
assert_eq!
(
s
.as_slice
()
,
"hello"
);
assert_eq!
(
s
,
"hello"
);
}
#[test]
...
...
@@ -266,4 +266,4 @@ fn test_cloned() {
assert_eq!
(
opt_ref_ref
.clone
(),
Some
(
&
val1_ref
));
assert_eq!
(
opt_ref_ref
.clone
()
.cloned
(),
Some
(
&
val1
));
assert_eq!
(
opt_ref_ref
.cloned
()
.cloned
(),
Some
(
1u32
));
}
\ No newline at end of file
}
src/libcoretest/result.rs
浏览文件 @
5257a5b2
...
...
@@ -93,9 +93,9 @@ pub fn test_fmt_default() {
let
err
:
Result
<
int
,
&
'static
str
>
=
Err
(
"Err"
);
let
s
=
format!
(
"{}"
,
ok
);
assert_eq!
(
s
.as_slice
()
,
"Ok(100)"
);
assert_eq!
(
s
,
"Ok(100)"
);
let
s
=
format!
(
"{}"
,
err
);
assert_eq!
(
s
.as_slice
()
,
"Err(Err)"
);
assert_eq!
(
s
,
"Err(Err)"
);
}
#[test]
...
...
src/libcoretest/tuple.rs
浏览文件 @
5257a5b2
...
...
@@ -84,9 +84,9 @@ fn test_tuple_cmp() {
#[test]
fn
test_show
()
{
let
s
=
format!
(
"{}"
,
(
1
i
,));
assert_eq!
(
s
.as_slice
()
,
"(1,)"
);
assert_eq!
(
s
,
"(1,)"
);
let
s
=
format!
(
"{}"
,
(
1
i
,
true
));
assert_eq!
(
s
.as_slice
()
,
"(1, true)"
);
assert_eq!
(
s
,
"(1, true)"
);
let
s
=
format!
(
"{}"
,
(
1
i
,
"hi"
,
true
));
assert_eq!
(
s
.as_slice
()
,
"(1, hi, true)"
);
assert_eq!
(
s
,
"(1, hi, true)"
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录