Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f0085060
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,发现更多精彩内容 >>
提交
f0085060
编写于
2月 23, 2015
作者:
M
Manish Goregaokar
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #22658 - glacjay:issue-22535, r=Gankro
fix issue #22535
上级
7d46e049
c2a2b105
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
62 deletion
+66
-62
src/libstd/num/mod.rs
src/libstd/num/mod.rs
+66
-0
src/libstd/num/uint_macros.rs
src/libstd/num/uint_macros.rs
+0
-62
未找到文件。
src/libstd/num/mod.rs
浏览文件 @
f0085060
...
...
@@ -1751,6 +1751,72 @@ fn naive_pow<T: Int>(base: T, exp: usize) -> T {
assert_pow!
((
8
,
3
)
=>
512
);
assert_pow!
((
2u64
,
50
)
=>
1125899906842624
);
}
#[test]
fn
test_uint_to_str_overflow
()
{
let
mut
u8_val
:
u8
=
255_u8
;
assert_eq!
(
u8_val
.to_string
(),
"255"
);
u8_val
+=
1
as
u8
;
assert_eq!
(
u8_val
.to_string
(),
"0"
);
let
mut
u16_val
:
u16
=
65_535_u16
;
assert_eq!
(
u16_val
.to_string
(),
"65535"
);
u16_val
+=
1
as
u16
;
assert_eq!
(
u16_val
.to_string
(),
"0"
);
let
mut
u32_val
:
u32
=
4_294_967_295_u32
;
assert_eq!
(
u32_val
.to_string
(),
"4294967295"
);
u32_val
+=
1
as
u32
;
assert_eq!
(
u32_val
.to_string
(),
"0"
);
let
mut
u64_val
:
u64
=
18_446_744_073_709_551_615_u64
;
assert_eq!
(
u64_val
.to_string
(),
"18446744073709551615"
);
u64_val
+=
1
as
u64
;
assert_eq!
(
u64_val
.to_string
(),
"0"
);
}
fn
from_str
<
T
:
::
str
::
FromStr
>
(
t
:
&
str
)
->
Option
<
T
>
{
::
str
::
FromStr
::
from_str
(
t
)
.ok
()
}
#[test]
fn
test_uint_from_str_overflow
()
{
let
mut
u8_val
:
u8
=
255_u8
;
assert_eq!
(
from_str
::
<
u8
>
(
"255"
),
Some
(
u8_val
));
assert_eq!
(
from_str
::
<
u8
>
(
"256"
),
None
);
u8_val
+=
1
as
u8
;
assert_eq!
(
from_str
::
<
u8
>
(
"0"
),
Some
(
u8_val
));
assert_eq!
(
from_str
::
<
u8
>
(
"-1"
),
None
);
let
mut
u16_val
:
u16
=
65_535_u16
;
assert_eq!
(
from_str
::
<
u16
>
(
"65535"
),
Some
(
u16_val
));
assert_eq!
(
from_str
::
<
u16
>
(
"65536"
),
None
);
u16_val
+=
1
as
u16
;
assert_eq!
(
from_str
::
<
u16
>
(
"0"
),
Some
(
u16_val
));
assert_eq!
(
from_str
::
<
u16
>
(
"-1"
),
None
);
let
mut
u32_val
:
u32
=
4_294_967_295_u32
;
assert_eq!
(
from_str
::
<
u32
>
(
"4294967295"
),
Some
(
u32_val
));
assert_eq!
(
from_str
::
<
u32
>
(
"4294967296"
),
None
);
u32_val
+=
1
as
u32
;
assert_eq!
(
from_str
::
<
u32
>
(
"0"
),
Some
(
u32_val
));
assert_eq!
(
from_str
::
<
u32
>
(
"-1"
),
None
);
let
mut
u64_val
:
u64
=
18_446_744_073_709_551_615_u64
;
assert_eq!
(
from_str
::
<
u64
>
(
"18446744073709551615"
),
Some
(
u64_val
));
assert_eq!
(
from_str
::
<
u64
>
(
"18446744073709551616"
),
None
);
u64_val
+=
1
as
u64
;
assert_eq!
(
from_str
::
<
u64
>
(
"0"
),
Some
(
u64_val
));
assert_eq!
(
from_str
::
<
u64
>
(
"-1"
),
None
);
}
}
...
...
src/libstd/num/uint_macros.rs
浏览文件 @
f0085060
...
...
@@ -48,68 +48,6 @@ pub fn test_parse_bytes() {
assert_eq!
(
FromStrRadix
::
from_str_radix
(
"Z"
,
10
)
.ok
(),
None
::
<
$T
>
);
assert_eq!
(
FromStrRadix
::
from_str_radix
(
"_"
,
2
)
.ok
(),
None
::
<
$T
>
);
}
#[test]
fn
test_uint_to_str_overflow
()
{
let
mut
u8_val
:
u8
=
255_u8
;
assert_eq!
(
u8_val
.to_string
(),
"255"
);
u8_val
+=
1
as
u8
;
assert_eq!
(
u8_val
.to_string
(),
"0"
);
let
mut
u16_val
:
u16
=
65_535_u16
;
assert_eq!
(
u16_val
.to_string
(),
"65535"
);
u16_val
+=
1
as
u16
;
assert_eq!
(
u16_val
.to_string
(),
"0"
);
let
mut
u32_val
:
u32
=
4_294_967_295_u32
;
assert_eq!
(
u32_val
.to_string
(),
"4294967295"
);
u32_val
+=
1
as
u32
;
assert_eq!
(
u32_val
.to_string
(),
"0"
);
let
mut
u64_val
:
u64
=
18_446_744_073_709_551_615_u64
;
assert_eq!
(
u64_val
.to_string
(),
"18446744073709551615"
);
u64_val
+=
1
as
u64
;
assert_eq!
(
u64_val
.to_string
(),
"0"
);
}
#[test]
fn
test_uint_from_str_overflow
()
{
let
mut
u8_val
:
u8
=
255_u8
;
assert_eq!
(
from_str
::
<
u8
>
(
"255"
),
Some
(
u8_val
));
assert_eq!
(
from_str
::
<
u8
>
(
"256"
),
None
);
u8_val
+=
1
as
u8
;
assert_eq!
(
from_str
::
<
u8
>
(
"0"
),
Some
(
u8_val
));
assert_eq!
(
from_str
::
<
u8
>
(
"-1"
),
None
);
let
mut
u16_val
:
u16
=
65_535_u16
;
assert_eq!
(
from_str
::
<
u16
>
(
"65535"
),
Some
(
u16_val
));
assert_eq!
(
from_str
::
<
u16
>
(
"65536"
),
None
);
u16_val
+=
1
as
u16
;
assert_eq!
(
from_str
::
<
u16
>
(
"0"
),
Some
(
u16_val
));
assert_eq!
(
from_str
::
<
u16
>
(
"-1"
),
None
);
let
mut
u32_val
:
u32
=
4_294_967_295_u32
;
assert_eq!
(
from_str
::
<
u32
>
(
"4294967295"
),
Some
(
u32_val
));
assert_eq!
(
from_str
::
<
u32
>
(
"4294967296"
),
None
);
u32_val
+=
1
as
u32
;
assert_eq!
(
from_str
::
<
u32
>
(
"0"
),
Some
(
u32_val
));
assert_eq!
(
from_str
::
<
u32
>
(
"-1"
),
None
);
let
mut
u64_val
:
u64
=
18_446_744_073_709_551_615_u64
;
assert_eq!
(
from_str
::
<
u64
>
(
"18446744073709551615"
),
Some
(
u64_val
));
assert_eq!
(
from_str
::
<
u64
>
(
"18446744073709551616"
),
None
);
u64_val
+=
1
as
u64
;
assert_eq!
(
from_str
::
<
u64
>
(
"0"
),
Some
(
u64_val
));
assert_eq!
(
from_str
::
<
u64
>
(
"-1"
),
None
);
}
}
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录