|
| 1 | +// https://doc.rust-lang.org/stable/reference/keywords.html |
| 2 | +const KEYWORDS: [&str; 52] = [ |
| 3 | + "as", "break", "const", "continue", "crate", "else", "enum", "extern", "false", "fn", "for", |
| 4 | + "if", "impl", "in", "let", "loop", "match", "mod", "move", "mut", "pub", "ref", "return", |
| 5 | + "self", "Self", "static", "struct", "super", "trait", "true", "type", "unsafe", "use", "where", |
| 6 | + "while", "async", "await", "dyn", "abstract", "become", "box", "do", "final", "macro", |
| 7 | + "override", "priv", "typeof", "unsized", "virtual", "yield", "try", "union", |
| 8 | +]; |
| 9 | + |
| 10 | +pub fn is_keyword(x: &str) -> bool { |
| 11 | + KEYWORDS.contains(&x.to_lowercase().as_str()) |
| 12 | +} |
| 13 | + |
| 14 | +#[test] |
| 15 | +fn value_is_a_keyword() { |
| 16 | + assert!(is_keyword("type")); |
| 17 | + assert!(is_keyword("TYPE")); |
| 18 | +} |
| 19 | + |
| 20 | +#[test] |
| 21 | +fn value_is_not_a_keyword() { |
| 22 | + assert!(!is_keyword("rpms")); |
| 23 | +} |
0 commit comments