3 // This test is mainly here for interactive development. Use this test while
4 // you're working on the proc-macro defined in this file.
7 // We textually include the symbol.rs file, which contains the list of all
8 // symbols, keywords, and common words. Then we search for the
9 // `symbols! { ... }` call.
11 static SYMBOL_RS_FILE: &str = include_str!("../../../rustc_span/src/symbol.rs");
13 let file = syn::parse_file(SYMBOL_RS_FILE).unwrap();
14 let symbols_path: syn::Path = syn::parse_quote!(symbols);
16 let m: &syn::ItemMacro = file
20 if let syn::Item::Macro(m) = i {
21 if m.mac.path == symbols_path { Some(m) } else { None }
27 .expect("did not find `symbols!` macro invocation.");
29 let body_tokens = m.mac.tokens.clone();
31 test_symbols_macro(body_tokens, &[]);
34 fn test_symbols_macro(input: TokenStream, expected_errors: &[&str]) {
35 let (output, found_errors) = symbols_with_errors(input);
37 // It should always parse.
38 let _parsed_file = syn::parse2::<syn::File>(output).unwrap();
42 expected_errors.len(),
43 "Macro generated a different number of errors than expected"
46 for (found_error, &expected_error) in found_errors.iter().zip(expected_errors) {
47 let found_error_str = format!("{}", found_error);
48 assert_eq!(found_error_str, expected_error);
53 fn check_dup_keywords() {
61 test_symbols_macro(input, &["Symbol `crate` is duplicated", "location of previous definition"]);
65 fn check_dup_symbol() {
73 test_symbols_macro(input, &["Symbol `splat` is duplicated", "location of previous definition"]);
77 fn check_dup_symbol_and_keyword() {
86 test_symbols_macro(input, &["Symbol `splat` is duplicated", "location of previous definition"]);
90 fn check_symbol_order() {
100 &["Symbol `aardvark` must precede `zebra`", "location of previous symbol `zebra`"],