Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ba694775
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,发现更多精彩内容 >>
提交
ba694775
编写于
1月 09, 2012
作者:
G
Grahame Bowland
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add tests for io::readchars and io::readchar
Additionally reformat so that 'make check' passes.
上级
bcc25634
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
7 deletion
+58
-7
src/libstd/io.rs
src/libstd/io.rs
+10
-7
src/test/stdtest/io.rs
src/test/stdtest/io.rs
+48
-0
未找到文件。
src/libstd/io.rs
浏览文件 @
ba694775
...
...
@@ -130,26 +130,29 @@ fn chars_from_buf(buf: [u8], &chars: [char]) -> (uint, uint) {
val
+=
next
&
63
as
uint
;
}
// See str::char_at
val
+=
(
b0
<<
(
w
+
1u
as
u8
)
as
uint
)
<<
(
w
-
1u
)
*
6u
-
w
-
1u
;
val
+=
(
b0
<<
(
w
+
1u
as
u8
)
as
uint
)
<<
(
w
-
1u
)
*
6u
-
w
-
1u
;
chars
+=
[
val
as
char
];
}
ret
(
i
,
0u
);
}
let
buf
:
[
u8
]
=
[];
let
chars
:
[
char
]
=
[];
let
nbread
=
n
;
// might need more bytes, but reading n will never over-read
// might need more bytes, but reading n will never over-read
let
nbread
=
n
;
while
nbread
>
0u
{
let
data
=
self
.read_bytes
(
nbread
);
let
data
=
self
.read_bytes
(
nbread
);
if
vec
::
len
(
data
)
==
0u
{
// eof - FIXME should we do something if we're split in a unicode char?
// eof - FIXME should we do something if
// we're split in a unicode char?
break
;
}
buf
+=
data
;
let
(
offset
,
nbreq
)
=
chars_from_buf
(
buf
,
chars
);
let
ncreq
=
n
-
vec
::
len
(
chars
);
// again we either know we need a certain number of bytes
to complete a
//
character, or we make sure we don't over-read by reading 1-byte per char
// needed
// again we either know we need a certain number of bytes
//
to complete a character, or we make sure we don't
//
over-read by reading 1-byte per char
needed
nbread
=
if
ncreq
>
nbreq
{
ncreq
}
else
{
nbreq
};
if
nbread
>
0u
{
buf
=
vec
::
slice
(
buf
,
offset
,
vec
::
len
(
buf
));
...
...
src/test/stdtest/io.rs
浏览文件 @
ba694775
...
...
@@ -23,6 +23,54 @@ fn test_simple() {
assert
(
str
::
eq
(
frood
,
frood2
));
}
#[test]
fn
test_readchars_empty
()
{
let
inp
:
io
::
reader
=
io
::
string_reader
(
""
);
let
res
:
[
char
]
=
inp
.read_chars
(
128u
);
assert
(
vec
::
len
(
res
)
==
0u
);
}
#[test]
fn
test_readchars_wide
()
{
let
wide_test
=
"生锈的汤匙切肉汤hello生锈的汤匙切肉汤"
;
let
ivals
:
[
int
]
=
[
29983
,
38152
,
30340
,
27748
,
21273
,
20999
,
32905
,
27748
,
104
,
101
,
108
,
108
,
111
,
29983
,
38152
,
30340
,
27748
,
21273
,
20999
,
32905
,
27748
];
fn
check_read_ln
(
len
:
uint
,
s
:
str
,
ivals
:
[
int
])
{
let
inp
:
io
::
reader
=
io
::
string_reader
(
s
);
let
res
:
[
char
]
=
inp
.read_chars
(
len
);
if
(
len
<=
vec
::
len
(
ivals
))
{
assert
(
vec
::
len
(
res
)
==
len
);
}
assert
(
vec
::
slice
(
ivals
,
0u
,
vec
::
len
(
res
))
==
vec
::
map
(
res
,
{|
x
|
x
as
int
}));
}
let
i
=
0u
;
while
i
<
8u
{
check_read_ln
(
i
,
wide_test
,
ivals
);
i
+=
1u
;
}
// check a long read for good measure
check_read_ln
(
128u
,
wide_test
,
ivals
);
}
#[test]
fn
test_readchar
()
{
let
inp
:
io
::
reader
=
io
::
string_reader
(
"生"
);
let
res
:
char
=
inp
.read_char
();
assert
(
res
as
int
==
29983
);
}
#[test]
fn
test_readchar_empty
()
{
let
inp
:
io
::
reader
=
io
::
string_reader
(
""
);
let
res
:
char
=
inp
.read_char
();
assert
(
res
as
int
==
-
1
);
}
#[test]
fn
file_reader_not_exist
()
{
alt
io
::
file_reader
(
"not a file"
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录