sqruff_lib/templaters/
raw.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::sync::Arc;

use sqruff_lib_core::errors::SQLFluffUserError;
use sqruff_lib_core::templaters::base::TemplatedFile;

use crate::cli::formatters::Formatter;
use crate::core::config::FluffConfig;
use crate::templaters::Templater;

#[derive(Default)]
pub struct RawTemplater;

impl Templater for RawTemplater {
    fn name(&self) -> &'static str {
        "raw"
    }

    fn description(&self) -> &'static str {
        r"The raw templater simply returns the input string as the output string. It passes through the input string unchanged and is useful if you need no templating. It is the defualt templater."
    }

    fn process(
        &self,
        in_str: &str,
        f_name: &str,
        _config: Option<&FluffConfig>,
        _formatter: &Option<Arc<dyn Formatter>>,
    ) -> Result<TemplatedFile, SQLFluffUserError> {
        if let Ok(tf) = TemplatedFile::new(in_str.to_string(), f_name.to_string(), None, None, None)
        {
            return Ok(tf);
        }
        panic!("Not implemented")
    }
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    /// Test the raw templater
    fn test_templater_raw() {
        let templater = RawTemplater;
        let in_str = "SELECT * FROM {{blah}}";

        let outstr = templater.process(in_str, "test.sql", None, &None).unwrap();

        assert_eq!(outstr.templated_str, Some(in_str.to_string()));
    }
}