syntax-extension-source-utils.rs 1.7 KB
Newer Older
1
// Copyright 2012-2013-2014 The Rust Project Developers. See the COPYRIGHT
2 3 4 5 6 7 8 9 10
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

11
// This test is brittle!
12
// ignore-pretty - the pretty tests lose path information, breaking include!
13

14 15
pub mod m1 {
    pub mod m2 {
16
        pub fn where_am_i() -> String {
17
            (module_path!()).to_string()
18
        }
19 20 21
    }
}

22
macro_rules! indirect_line { () => ( line!() ) }
23

24
pub fn main() {
K
Keegan McAllister 已提交
25
    assert_eq!(line!(), 25);
H
Huon Wilson 已提交
26
    //assert!((column!() == 11));
K
Keegan McAllister 已提交
27
    assert_eq!(indirect_line!(), 27);
28
    assert!((file!().ends_with("syntax-extension-source-utils.rs")));
29
    assert_eq!(stringify!((2*3) + 5).to_string(), "( 2 * 3 ) + 5".to_string());
30
    assert!(include!("syntax-extension-source-utils-files/includeme.\
31 32
                      fragment").to_string()
           == "victory robot 6".to_string());
33

P
Patrick Walton 已提交
34
    assert!(
35
        include_str!("syntax-extension-source-utils-files/includeme.\
36
                      fragment").to_string()
37
        .as_slice()
E
Erick Tryzelaar 已提交
38
        .starts_with("/* this is for "));
P
Patrick Walton 已提交
39
    assert!(
C
Chris Wong 已提交
40
        include_bytes!("syntax-extension-source-utils-files/includeme.fragment")
P
Paul Stansifer 已提交
41
        [1] == (42 as u8)); // '*'
42
    // The Windows tests are wrapped in an extra module for some reason
43
    assert!((m1::m2::where_am_i().as_slice().ends_with("m1::m2")));
44

K
Keegan McAllister 已提交
45
    assert!(match (45, "( 2 * 3 ) + 5") {
46 47 48
        (line!(), stringify!((2*3) + 5)) => true,
        _ => false
    })
49
}