open_pql/pql_parser/ast/
ident.rs1use super::*;
2
3#[derive(PartialEq, Eq, Debug, From)]
4pub struct Ident<'i> {
5 pub inner: &'i str,
6 pub loc: (Loc, Loc),
7}
8
9#[cfg(test)]
10mod tests {
11 use super::{super::super::parser::*, *};
12
13 fn i(s: &str) -> Ident<'_> {
14 IdentParser::new().parse(s).unwrap()
15 }
16
17 #[test]
18 fn test_ident() {
19 assert_eq!(i("_"), ("_", (0, 1)).into());
20
21 for c in "0123456789".chars() {
22 assert_eq!(
23 i(&format!("_{c}")),
24 (format!("_{c}").as_str(), (0, 2)).into()
25 );
26 }
27
28 let mut c = 'a';
29
30 while c <= 'z' {
31 assert_eq!(
32 i(&format!("{c}")),
33 (format!("{c}").as_str(), (0, 1)).into()
34 );
35
36 assert_eq!(
37 i(&format!("{}", c.to_uppercase())),
38 (format!("{}", c.to_uppercase()).as_str(), (0, 1)).into()
39 );
40
41 c = (c as u8 + 1) as char;
42 }
43
44 assert_eq!(i("__abc123"), ("__abc123", (0, 8)).into());
45 }
46}