Skip to content

Commit e3acb34

Browse files
committed
Remove some tests using AST comparisons, fix other tests
1 parent 5987fe8 commit e3acb34

File tree

5 files changed

+34
-277
lines changed

5 files changed

+34
-277
lines changed

src/libsyntax/parse/lexer/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,8 @@ mod tests {
18421842
tok: token::Ident(id, false),
18431843
sp: Span::new(BytePos(21), BytePos(23), NO_EXPANSION),
18441844
};
1845-
assert_eq!(tok1, tok2);
1845+
assert_eq!(tok1.tok, tok2.tok);
1846+
assert_eq!(tok1.sp, tok2.sp);
18461847
assert_eq!(string_reader.next_token().tok, token::Whitespace);
18471848
// the 'main' id is already read:
18481849
assert_eq!(string_reader.pos.clone(), BytePos(28));
@@ -1852,7 +1853,8 @@ mod tests {
18521853
tok: mk_ident("main"),
18531854
sp: Span::new(BytePos(24), BytePos(28), NO_EXPANSION),
18541855
};
1855-
assert_eq!(tok3, tok4);
1856+
assert_eq!(tok3.tok, tok4.tok);
1857+
assert_eq!(tok3.sp, tok4.sp);
18561858
// the lparen is already read:
18571859
assert_eq!(string_reader.pos.clone(), BytePos(29))
18581860
})

src/libsyntax/parse/mod.rs

+26-204
Original file line numberDiff line numberDiff line change
@@ -673,65 +673,47 @@ fn integer_lit(s: &str, suffix: Option<Symbol>, diag: Option<(Span, &Handler)>)
673673
})
674674
}
675675

676+
/// `SeqSep` : a sequence separator (token)
677+
/// and whether a trailing separator is allowed.
678+
pub struct SeqSep {
679+
pub sep: Option<token::Token>,
680+
pub trailing_sep_allowed: bool,
681+
}
682+
683+
impl SeqSep {
684+
pub fn trailing_allowed(t: token::Token) -> SeqSep {
685+
SeqSep {
686+
sep: Some(t),
687+
trailing_sep_allowed: true,
688+
}
689+
}
690+
691+
pub fn none() -> SeqSep {
692+
SeqSep {
693+
sep: None,
694+
trailing_sep_allowed: false,
695+
}
696+
}
697+
}
698+
676699
#[cfg(test)]
677700
mod tests {
678701
use super::*;
679-
use syntax_pos::{self, Span, BytePos, Pos, NO_EXPANSION};
680-
use codemap::{respan, Spanned};
702+
use syntax_pos::{Span, BytePos, Pos, NO_EXPANSION};
681703
use ast::{self, Ident, PatKind};
682-
use rustc_target::spec::abi::Abi;
683704
use attr::first_attr_value_str_by_name;
684705
use parse;
685-
use parse::parser::Parser;
686706
use print::pprust::item_to_string;
687-
use ptr::P;
688707
use tokenstream::{self, TokenTree};
689-
use util::parser_testing::{string_to_stream, string_to_parser};
690-
use util::parser_testing::{string_to_expr, string_to_item, string_to_stmt};
691-
use util::ThinVec;
708+
use util::parser_testing::string_to_stream;
709+
use util::parser_testing::{string_to_expr, string_to_item};
692710
use with_globals;
693711

694712
// produce a syntax_pos::span
695713
fn sp(a: u32, b: u32) -> Span {
696714
Span::new(BytePos(a), BytePos(b), NO_EXPANSION)
697715
}
698716

699-
fn str2seg(s: &str, lo: u32, hi: u32) -> ast::PathSegment {
700-
ast::PathSegment::from_ident(Ident::new(Symbol::intern(s), sp(lo, hi)))
701-
}
702-
703-
#[test] fn path_exprs_1() {
704-
with_globals(|| {
705-
assert!(string_to_expr("a".to_string()) ==
706-
P(ast::Expr{
707-
id: ast::DUMMY_NODE_ID,
708-
node: ast::ExprKind::Path(None, ast::Path {
709-
span: sp(0, 1),
710-
segments: vec![str2seg("a", 0, 1)],
711-
}),
712-
span: sp(0, 1),
713-
attrs: ThinVec::new(),
714-
}))
715-
})
716-
}
717-
718-
#[test] fn path_exprs_2 () {
719-
with_globals(|| {
720-
assert!(string_to_expr("::a::b".to_string()) ==
721-
P(ast::Expr {
722-
id: ast::DUMMY_NODE_ID,
723-
node: ast::ExprKind::Path(None, ast::Path {
724-
span: sp(0, 6),
725-
segments: vec![ast::PathSegment::crate_root(sp(0, 0)),
726-
str2seg("a", 2, 3),
727-
str2seg("b", 5, 6)]
728-
}),
729-
span: sp(0, 6),
730-
attrs: ThinVec::new(),
731-
}))
732-
})
733-
}
734-
735717
#[should_panic]
736718
#[test] fn bad_path_expr_1() {
737719
with_globals(|| {
@@ -832,143 +814,6 @@ mod tests {
832814
})
833815
}
834816

835-
#[test] fn ret_expr() {
836-
with_globals(|| {
837-
assert!(string_to_expr("return d".to_string()) ==
838-
P(ast::Expr{
839-
id: ast::DUMMY_NODE_ID,
840-
node:ast::ExprKind::Ret(Some(P(ast::Expr{
841-
id: ast::DUMMY_NODE_ID,
842-
node:ast::ExprKind::Path(None, ast::Path{
843-
span: sp(7, 8),
844-
segments: vec![str2seg("d", 7, 8)],
845-
}),
846-
span:sp(7,8),
847-
attrs: ThinVec::new(),
848-
}))),
849-
span:sp(0,8),
850-
attrs: ThinVec::new(),
851-
}))
852-
})
853-
}
854-
855-
#[test] fn parse_stmt_1 () {
856-
with_globals(|| {
857-
assert!(string_to_stmt("b;".to_string()) ==
858-
Some(ast::Stmt {
859-
node: ast::StmtKind::Expr(P(ast::Expr {
860-
id: ast::DUMMY_NODE_ID,
861-
node: ast::ExprKind::Path(None, ast::Path {
862-
span:sp(0,1),
863-
segments: vec![str2seg("b", 0, 1)],
864-
}),
865-
span: sp(0,1),
866-
attrs: ThinVec::new()})),
867-
id: ast::DUMMY_NODE_ID,
868-
span: sp(0,1)}))
869-
})
870-
}
871-
872-
fn parser_done(p: Parser){
873-
assert_eq!(p.token.clone(), token::Eof);
874-
}
875-
876-
#[test] fn parse_ident_pat () {
877-
with_globals(|| {
878-
let sess = ParseSess::new(FilePathMapping::empty());
879-
let mut parser = string_to_parser(&sess, "b".to_string());
880-
assert!(panictry!(parser.parse_pat())
881-
== P(ast::Pat{
882-
id: ast::DUMMY_NODE_ID,
883-
node: PatKind::Ident(ast::BindingMode::ByValue(ast::Mutability::Immutable),
884-
Ident::new(Symbol::intern("b"), sp(0, 1)),
885-
None),
886-
span: sp(0,1)}));
887-
parser_done(parser);
888-
})
889-
}
890-
891-
// check the contents of the tt manually:
892-
#[test] fn parse_fundecl () {
893-
with_globals(|| {
894-
// this test depends on the intern order of "fn" and "i32"
895-
let item = string_to_item("fn a (b : i32) { b; }".to_string()).map(|m| {
896-
m.map(|mut m| {
897-
m.tokens = None;
898-
m
899-
})
900-
});
901-
assert_eq!(item,
902-
Some(
903-
P(ast::Item{ident:Ident::from_str("a"),
904-
attrs:Vec::new(),
905-
id: ast::DUMMY_NODE_ID,
906-
tokens: None,
907-
node: ast::ItemKind::Fn(P(ast::FnDecl {
908-
inputs: vec![ast::Arg{
909-
ty: P(ast::Ty{id: ast::DUMMY_NODE_ID,
910-
node: ast::TyKind::Path(None, ast::Path{
911-
span:sp(10,13),
912-
segments: vec![str2seg("i32", 10, 13)],
913-
}),
914-
span:sp(10,13)
915-
}),
916-
pat: P(ast::Pat {
917-
id: ast::DUMMY_NODE_ID,
918-
node: PatKind::Ident(
919-
ast::BindingMode::ByValue(
920-
ast::Mutability::Immutable),
921-
Ident::new(Symbol::intern("b"), sp(6, 7)),
922-
None
923-
),
924-
span: sp(6,7)
925-
}),
926-
id: ast::DUMMY_NODE_ID
927-
}],
928-
output: ast::FunctionRetTy::Default(sp(15, 15)),
929-
variadic: false
930-
}),
931-
ast::FnHeader {
932-
unsafety: ast::Unsafety::Normal,
933-
asyncness: ast::IsAsync::NotAsync,
934-
constness: Spanned {
935-
span: sp(0,2),
936-
node: ast::Constness::NotConst,
937-
},
938-
abi: Abi::Rust,
939-
},
940-
ast::Generics{
941-
params: Vec::new(),
942-
where_clause: ast::WhereClause {
943-
id: ast::DUMMY_NODE_ID,
944-
predicates: Vec::new(),
945-
span: syntax_pos::DUMMY_SP,
946-
},
947-
span: syntax_pos::DUMMY_SP,
948-
},
949-
P(ast::Block {
950-
stmts: vec![ast::Stmt {
951-
node: ast::StmtKind::Semi(P(ast::Expr{
952-
id: ast::DUMMY_NODE_ID,
953-
node: ast::ExprKind::Path(None,
954-
ast::Path{
955-
span:sp(17,18),
956-
segments: vec![str2seg("b", 17, 18)],
957-
}),
958-
span: sp(17,18),
959-
attrs: ThinVec::new()})),
960-
id: ast::DUMMY_NODE_ID,
961-
span: sp(17,19)}],
962-
id: ast::DUMMY_NODE_ID,
963-
rules: ast::BlockCheckMode::Default, // no idea
964-
span: sp(15,21),
965-
recovered: false,
966-
})),
967-
vis: respan(sp(0, 0), ast::VisibilityKind::Inherited),
968-
span: sp(0,21)})));
969-
})
970-
}
971-
972817
#[test] fn parse_use() {
973818
with_globals(|| {
974819
let use_s = "use foo::bar::baz;";
@@ -1133,26 +978,3 @@ mod tests {
1133978
});
1134979
}
1135980
}
1136-
1137-
/// `SeqSep` : a sequence separator (token)
1138-
/// and whether a trailing separator is allowed.
1139-
pub struct SeqSep {
1140-
pub sep: Option<token::Token>,
1141-
pub trailing_sep_allowed: bool,
1142-
}
1143-
1144-
impl SeqSep {
1145-
pub fn trailing_allowed(t: token::Token) -> SeqSep {
1146-
SeqSep {
1147-
sep: Some(t),
1148-
trailing_sep_allowed: true,
1149-
}
1150-
}
1151-
1152-
pub fn none() -> SeqSep {
1153-
SeqSep {
1154-
sep: None,
1155-
trailing_sep_allowed: false,
1156-
}
1157-
}
1158-
}

src/libsyntax/util/parser_testing.rs

-8
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ pub fn string_to_item (source_str : String) -> Option<P<ast::Item>> {
6363
})
6464
}
6565

66-
/// Parse a string, return a stmt
67-
pub fn string_to_stmt(source_str : String) -> Option<ast::Stmt> {
68-
let ps = ParseSess::new(FilePathMapping::empty());
69-
with_error_checking_parse(source_str, &ps, |p| {
70-
p.parse_stmt()
71-
})
72-
}
73-
7466
/// Parse a string, return a pat. Uses "irrefutable"... which doesn't
7567
/// (currently) affect parsing.
7668
pub fn string_to_pat(source_str: String) -> P<ast::Pat> {

src/libsyntax_ext/format_foreign.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub mod printf {
1212
use super::strcursor::StrCursor as Cur;
1313

1414
/// Represents a single `printf`-style substitution.
15-
#[derive(Clone, Debug)]
15+
#[derive(Clone, PartialEq, Debug)]
1616
pub enum Substitution<'a> {
1717
/// A formatted output substitution.
1818
Format(Format<'a>),
@@ -40,7 +40,7 @@ pub mod printf {
4040
}
4141
}
4242

43-
#[derive(Clone, Debug)]
43+
#[derive(Clone, PartialEq, Debug)]
4444
/// A single `printf`-style formatting directive.
4545
pub struct Format<'a> {
4646
/// The entire original formatting directive.
@@ -213,7 +213,7 @@ pub mod printf {
213213
}
214214

215215
/// A general number used in a `printf` formatting directive.
216-
#[derive(Copy, Clone, Debug)]
216+
#[derive(Copy, Clone, PartialEq, Debug)]
217217
pub enum Num {
218218
// The range of these values is technically bounded by `NL_ARGMAX`... but, at least for GNU
219219
// libc, it apparently has no real fixed limit. A `u16` is used here on the basis that it
@@ -739,7 +739,7 @@ pub mod printf {
739739
pub mod shell {
740740
use super::strcursor::StrCursor as Cur;
741741

742-
#[derive(Clone, Debug)]
742+
#[derive(Clone, PartialEq, Debug)]
743743
pub enum Substitution<'a> {
744744
Ordinal(u8),
745745
Name(&'a str),

src/test/run-pass-fulldeps/issue-35829.rs

-59
This file was deleted.

0 commit comments

Comments
 (0)