Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ad15dc2a
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,发现更多精彩内容 >>
未验证
提交
ad15dc2a
编写于
8月 22, 2020
作者:
D
Dylan DPC
提交者:
GitHub
8月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #75769 - matklad:flatten, r=petrochenkov
Minor, remove double nesting of a test module
上级
cc1e5c05
35994db6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
121 addition
and
136 deletion
+121
-136
src/librustc_lexer/src/tests.rs
src/librustc_lexer/src/tests.rs
+121
-136
未找到文件。
src/librustc_lexer/src/tests.rs
浏览文件 @
ad15dc2a
#[cfg(test)]
mod
tests
{
use
crate
::
*
;
fn
check_raw_str
(
s
:
&
str
,
expected_hashes
:
u16
,
expected_err
:
Option
<
RawStrError
>
)
{
let
s
=
&
format!
(
"r{}"
,
s
);
let
mut
cursor
=
Cursor
::
new
(
s
);
cursor
.bump
();
let
(
n_hashes
,
err
)
=
cursor
.raw_double_quoted_string
(
0
);
assert_eq!
(
n_hashes
,
expected_hashes
);
assert_eq!
(
err
,
expected_err
);
}
#[test]
fn
test_naked_raw_str
()
{
check_raw_str
(
r#""abc""#
,
0
,
None
);
}
#[test]
fn
test_raw_no_start
()
{
check_raw_str
(
r##""abc"#"##
,
0
,
None
);
}
#[test]
fn
test_too_many_terminators
()
{
// this error is handled in the parser later
check_raw_str
(
r###"#"abc"##"###
,
1
,
None
);
}
#[test]
fn
test_unterminated
()
{
check_raw_str
(
r#"#"abc"#
,
1
,
Some
(
RawStrError
::
NoTerminator
{
expected
:
1
,
found
:
0
,
possible_terminator_offset
:
None
,
}),
);
check_raw_str
(
r###"##"abc"#"###
,
2
,
Some
(
RawStrError
::
NoTerminator
{
expected
:
2
,
found
:
1
,
possible_terminator_offset
:
Some
(
7
),
}),
);
// We're looking for "# not just any #
check_raw_str
(
r###"##"abc#"###
,
2
,
Some
(
RawStrError
::
NoTerminator
{
expected
:
2
,
found
:
0
,
possible_terminator_offset
:
None
,
}),
)
}
#[test]
fn
test_invalid_start
()
{
check_raw_str
(
r##"#~"abc"#"##
,
1
,
Some
(
RawStrError
::
InvalidStarter
{
bad_char
:
'~'
}));
}
#[test]
fn
test_unterminated_no_pound
()
{
// https://github.com/rust-lang/rust/issues/70677
check_raw_str
(
r#"""#
,
0
,
Some
(
RawStrError
::
NoTerminator
{
expected
:
0
,
found
:
0
,
possible_terminator_offset
:
None
,
}),
);
}
#[test]
fn
test_valid_shebang
()
{
// https://github.com/rust-lang/rust/issues/70528
let
input
=
"#!/usr/bin/rustrun
\n
let x = 5;"
;
assert_eq!
(
strip_shebang
(
input
),
Some
(
18
));
}
#[test]
fn
test_invalid_shebang_valid_rust_syntax
()
{
// https://github.com/rust-lang/rust/issues/70528
let
input
=
"#! [bad_attribute]"
;
assert_eq!
(
strip_shebang
(
input
),
None
);
}
#[test]
fn
test_shebang_second_line
()
{
// Because shebangs are interpreted by the kernel, they must be on the first line
let
input
=
"
\n
#!/bin/bash"
;
assert_eq!
(
strip_shebang
(
input
),
None
);
}
#[test]
fn
test_shebang_space
()
{
let
input
=
"#! /bin/bash"
;
assert_eq!
(
strip_shebang
(
input
),
Some
(
input
.len
()));
}
#[test]
fn
test_shebang_empty_shebang
()
{
let
input
=
"#!
\n
[attribute(foo)]"
;
assert_eq!
(
strip_shebang
(
input
),
None
);
}
#[test]
fn
test_invalid_shebang_comment
()
{
let
input
=
"#!//bin/ami/a/comment
\n
["
;
assert_eq!
(
strip_shebang
(
input
),
None
)
}
#[test]
fn
test_invalid_shebang_another_comment
()
{
let
input
=
"#!/*bin/ami/a/comment*/
\n
[attribute"
;
assert_eq!
(
strip_shebang
(
input
),
None
)
}
#[test]
fn
test_shebang_valid_rust_after
()
{
let
input
=
"#!/*bin/ami/a/comment*/
\n
pub fn main() {}"
;
assert_eq!
(
strip_shebang
(
input
),
Some
(
23
))
}
#[test]
fn
test_shebang_followed_by_attrib
()
{
let
input
=
"#!/bin/rust-scripts
\n
#![allow_unused(true)]"
;
assert_eq!
(
strip_shebang
(
input
),
Some
(
19
));
}
use
super
::
*
;
fn
check_raw_str
(
s
:
&
str
,
expected_hashes
:
u16
,
expected_err
:
Option
<
RawStrError
>
)
{
let
s
=
&
format!
(
"r{}"
,
s
);
let
mut
cursor
=
Cursor
::
new
(
s
);
cursor
.bump
();
let
(
n_hashes
,
err
)
=
cursor
.raw_double_quoted_string
(
0
);
assert_eq!
(
n_hashes
,
expected_hashes
);
assert_eq!
(
err
,
expected_err
);
}
#[test]
fn
test_naked_raw_str
()
{
check_raw_str
(
r#""abc""#
,
0
,
None
);
}
#[test]
fn
test_raw_no_start
()
{
check_raw_str
(
r##""abc"#"##
,
0
,
None
);
}
#[test]
fn
test_too_many_terminators
()
{
// this error is handled in the parser later
check_raw_str
(
r###"#"abc"##"###
,
1
,
None
);
}
#[test]
fn
test_unterminated
()
{
check_raw_str
(
r#"#"abc"#
,
1
,
Some
(
RawStrError
::
NoTerminator
{
expected
:
1
,
found
:
0
,
possible_terminator_offset
:
None
}),
);
check_raw_str
(
r###"##"abc"#"###
,
2
,
Some
(
RawStrError
::
NoTerminator
{
expected
:
2
,
found
:
1
,
possible_terminator_offset
:
Some
(
7
),
}),
);
// We're looking for "# not just any #
check_raw_str
(
r###"##"abc#"###
,
2
,
Some
(
RawStrError
::
NoTerminator
{
expected
:
2
,
found
:
0
,
possible_terminator_offset
:
None
}),
)
}
#[test]
fn
test_invalid_start
()
{
check_raw_str
(
r##"#~"abc"#"##
,
1
,
Some
(
RawStrError
::
InvalidStarter
{
bad_char
:
'~'
}));
}
#[test]
fn
test_unterminated_no_pound
()
{
// https://github.com/rust-lang/rust/issues/70677
check_raw_str
(
r#"""#
,
0
,
Some
(
RawStrError
::
NoTerminator
{
expected
:
0
,
found
:
0
,
possible_terminator_offset
:
None
}),
);
}
#[test]
fn
test_valid_shebang
()
{
// https://github.com/rust-lang/rust/issues/70528
let
input
=
"#!/usr/bin/rustrun
\n
let x = 5;"
;
assert_eq!
(
strip_shebang
(
input
),
Some
(
18
));
}
#[test]
fn
test_invalid_shebang_valid_rust_syntax
()
{
// https://github.com/rust-lang/rust/issues/70528
let
input
=
"#! [bad_attribute]"
;
assert_eq!
(
strip_shebang
(
input
),
None
);
}
#[test]
fn
test_shebang_second_line
()
{
// Because shebangs are interpreted by the kernel, they must be on the first line
let
input
=
"
\n
#!/bin/bash"
;
assert_eq!
(
strip_shebang
(
input
),
None
);
}
#[test]
fn
test_shebang_space
()
{
let
input
=
"#! /bin/bash"
;
assert_eq!
(
strip_shebang
(
input
),
Some
(
input
.len
()));
}
#[test]
fn
test_shebang_empty_shebang
()
{
let
input
=
"#!
\n
[attribute(foo)]"
;
assert_eq!
(
strip_shebang
(
input
),
None
);
}
#[test]
fn
test_invalid_shebang_comment
()
{
let
input
=
"#!//bin/ami/a/comment
\n
["
;
assert_eq!
(
strip_shebang
(
input
),
None
)
}
#[test]
fn
test_invalid_shebang_another_comment
()
{
let
input
=
"#!/*bin/ami/a/comment*/
\n
[attribute"
;
assert_eq!
(
strip_shebang
(
input
),
None
)
}
#[test]
fn
test_shebang_valid_rust_after
()
{
let
input
=
"#!/*bin/ami/a/comment*/
\n
pub fn main() {}"
;
assert_eq!
(
strip_shebang
(
input
),
Some
(
23
))
}
#[test]
fn
test_shebang_followed_by_attrib
()
{
let
input
=
"#!/bin/rust-scripts
\n
#![allow_unused(true)]"
;
assert_eq!
(
strip_shebang
(
input
),
Some
(
19
));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录