Skip to main content

openpql_pql_parser/ast/
str.rs

1use super::{Loc, LocInfo, Spanned, str};
2
3#[derive(Clone, PartialEq, Eq, derive_more::From, derive_more::Debug)]
4#[debug("{:?}", self.inner)]
5pub struct Str<'i> {
6    pub inner: &'i str,
7    pub loc: (Loc, Loc),
8}
9
10impl Spanned for Str<'_> {
11    fn loc(&self) -> LocInfo {
12        self.loc
13    }
14}
15
16#[cfg(test)]
17mod tests {
18    use super::*;
19    use crate::*;
20
21    fn assert_str(src: &str, expected: &str) {
22        let loc_start = 0;
23        let loc_end = src.len();
24        assert_eq!(parse_str(src), Ok((expected, (loc_start, loc_end)).into()));
25    }
26
27    #[test]
28    fn test_str() {
29        assert_str(r#""str""#, "str");
30        assert_str(r#""""#, "");
31
32        assert_str("'str'", "str");
33        assert_str("''", "");
34
35        assert_str("'one two three'", "one two three");
36    }
37
38    #[test]
39    fn test_dbg() {
40        assert_eq!(
41            format!("{:?}", Str::from(("content", (0, 1)))),
42            "\"content\""
43        );
44    }
45}