Skip to content

Commit da62384

Browse files
committed
Auto merge of #24718 - tamird:fix-quote-tests, r=alexcrichton
Sniped from @rprichard's work in #24537. r? @alexcrichton
2 parents 00c48d3 + beb373b commit da62384

File tree

6 files changed

+158
-206
lines changed

6 files changed

+158
-206
lines changed

src/librustc/middle/astencode.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -1835,29 +1835,31 @@ fn decode_item_ast(par_doc: rbml::Doc) -> ast::Item {
18351835
}
18361836

18371837
#[cfg(test)]
1838-
trait fake_ext_ctxt {
1838+
trait FakeExtCtxt {
1839+
fn call_site(&self) -> codemap::Span;
18391840
fn cfg(&self) -> ast::CrateConfig;
1840-
fn parse_sess<'a>(&'a self) -> &'a parse::ParseSess;
1841-
fn call_site(&self) -> Span;
18421841
fn ident_of(&self, st: &str) -> ast::Ident;
1842+
fn name_of(&self, st: &str) -> ast::Name;
1843+
fn parse_sess(&self) -> &parse::ParseSess;
18431844
}
18441845

18451846
#[cfg(test)]
1846-
impl fake_ext_ctxt for parse::ParseSess {
1847-
fn cfg(&self) -> ast::CrateConfig {
1848-
Vec::new()
1849-
}
1850-
fn parse_sess<'a>(&'a self) -> &'a parse::ParseSess { self }
1851-
fn call_site(&self) -> Span {
1847+
impl FakeExtCtxt for parse::ParseSess {
1848+
fn call_site(&self) -> codemap::Span {
18521849
codemap::Span {
18531850
lo: codemap::BytePos(0),
18541851
hi: codemap::BytePos(0),
1855-
expn_id: codemap::NO_EXPANSION
1852+
expn_id: codemap::NO_EXPANSION,
18561853
}
18571854
}
1855+
fn cfg(&self) -> ast::CrateConfig { Vec::new() }
18581856
fn ident_of(&self, st: &str) -> ast::Ident {
1859-
token::str_to_ident(st)
1857+
parse::token::str_to_ident(st)
1858+
}
1859+
fn name_of(&self, st: &str) -> ast::Name {
1860+
parse::token::intern(st)
18601861
}
1862+
fn parse_sess(&self) -> &parse::ParseSess { self }
18611863
}
18621864

18631865
#[cfg(test)]
@@ -1883,15 +1885,14 @@ fn test_basic() {
18831885
fn foo() {}
18841886
));
18851887
}
1886-
/* NOTE: When there's a snapshot, update this (yay quasiquoter!)
1888+
18871889
#[test]
18881890
fn test_smalltalk() {
18891891
let cx = mk_ctxt();
18901892
roundtrip(quote_item!(&cx,
18911893
fn foo() -> isize { 3 + 4 } // first smalltalk program ever executed.
18921894
));
18931895
}
1894-
*/
18951896

18961897
#[test]
18971898
fn test_more() {
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-cross-compile
12+
13+
#![feature(quote, rustc_private)]
14+
15+
extern crate syntax;
16+
17+
use syntax::ast;
18+
use syntax::codemap;
19+
use syntax::parse;
20+
use syntax::print::pprust;
21+
22+
trait FakeExtCtxt {
23+
fn call_site(&self) -> codemap::Span;
24+
fn cfg(&self) -> ast::CrateConfig;
25+
fn ident_of(&self, st: &str) -> ast::Ident;
26+
fn name_of(&self, st: &str) -> ast::Name;
27+
fn parse_sess(&self) -> &parse::ParseSess;
28+
}
29+
30+
impl FakeExtCtxt for parse::ParseSess {
31+
fn call_site(&self) -> codemap::Span {
32+
codemap::Span {
33+
lo: codemap::BytePos(0),
34+
hi: codemap::BytePos(0),
35+
expn_id: codemap::NO_EXPANSION,
36+
}
37+
}
38+
fn cfg(&self) -> ast::CrateConfig { Vec::new() }
39+
fn ident_of(&self, st: &str) -> ast::Ident {
40+
parse::token::str_to_ident(st)
41+
}
42+
fn name_of(&self, st: &str) -> ast::Name {
43+
parse::token::intern(st)
44+
}
45+
fn parse_sess(&self) -> &parse::ParseSess { self }
46+
}
47+
48+
fn main() {
49+
let cx = parse::new_parse_sess();
50+
51+
assert_eq!(pprust::expr_to_string(&*quote_expr!(&cx, 23)), "23");
52+
53+
let expr = quote_expr!(&cx, 2 - $abcd + 7); //~ ERROR unresolved name `abcd`
54+
assert_eq!(pprust::expr_to_string(&*expr), "2 - $abcd + 7");
55+
}

src/test/parse-fail/qquote-1.rs

-70
This file was deleted.

src/test/parse-fail/qquote-2.rs

-63
This file was deleted.

src/test/run-fail/qquote.rs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-cross-compile
12+
13+
// error-pattern:expected identifier, found keyword `let`
14+
15+
#![feature(quote, rustc_private)]
16+
17+
extern crate syntax;
18+
19+
use syntax::ast;
20+
use syntax::codemap;
21+
use syntax::parse;
22+
use syntax::print::pprust;
23+
24+
trait FakeExtCtxt {
25+
fn call_site(&self) -> codemap::Span;
26+
fn cfg(&self) -> ast::CrateConfig;
27+
fn ident_of(&self, st: &str) -> ast::Ident;
28+
fn name_of(&self, st: &str) -> ast::Name;
29+
fn parse_sess(&self) -> &parse::ParseSess;
30+
}
31+
32+
impl FakeExtCtxt for parse::ParseSess {
33+
fn call_site(&self) -> codemap::Span {
34+
codemap::Span {
35+
lo: codemap::BytePos(0),
36+
hi: codemap::BytePos(0),
37+
expn_id: codemap::NO_EXPANSION,
38+
}
39+
}
40+
fn cfg(&self) -> ast::CrateConfig { Vec::new() }
41+
fn ident_of(&self, st: &str) -> ast::Ident {
42+
parse::token::str_to_ident(st)
43+
}
44+
fn name_of(&self, st: &str) -> ast::Name {
45+
parse::token::intern(st)
46+
}
47+
fn parse_sess(&self) -> &parse::ParseSess { self }
48+
}
49+
50+
fn main() {
51+
let cx = parse::new_parse_sess();
52+
53+
assert_eq!(pprust::expr_to_string(&*quote_expr!(&cx, 23)), "23");
54+
55+
let expr = quote_expr!(&cx, let x isize = 20;);
56+
assert_eq!(pprust::expr_to_string(&*expr), "let x isize = 20;");
57+
}

0 commit comments

Comments
 (0)