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 }
26 .expect("did not find `symbols!` macro invocation.");
28 let body_tokens = m.mac.tokens.clone();
30 test_symbols_macro(body_tokens, &[]);
33 fn test_symbols_macro(input: TokenStream, expected_errors: &[&str]) {
34 let (output, found_errors) = symbols_with_errors(input);
36 // It should always parse.
37 let _parsed_file = syn::parse2::<syn::File>(output).unwrap();
41 expected_errors.len(),
42 "Macro generated a different number of errors than expected"
45 for (found_error, &expected_error) in found_errors.iter().zip(expected_errors) {
46 let found_error_str = format!("{}", found_error);
47 assert_eq!(found_error_str, expected_error);
52 fn check_dup_keywords() {
60 test_symbols_macro(input, &["Symbol `crate` is duplicated", "location of previous definition"]);
64 fn check_dup_symbol() {
72 test_symbols_macro(input, &["Symbol `splat` is duplicated", "location of previous definition"]);
76 fn check_dup_symbol_and_keyword() {
85 test_symbols_macro(input, &["Symbol `splat` is duplicated", "location of previous definition"]);
89 fn check_symbol_order() {
99 &["Symbol `aardvark` must precede `zebra`", "location of previous symbol `zebra`"],