sqruff_lib/templaters/
raw.rs

1use std::sync::Arc;
2
3use sqruff_lib_core::errors::SQLFluffUserError;
4use sqruff_lib_core::templaters::base::TemplatedFile;
5
6use crate::cli::formatters::Formatter;
7use crate::core::config::FluffConfig;
8use crate::templaters::Templater;
9
10#[derive(Default)]
11pub struct RawTemplater;
12
13impl Templater for RawTemplater {
14    fn name(&self) -> &'static str {
15        "raw"
16    }
17
18    fn description(&self) -> &'static str {
19        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."
20    }
21
22    fn process(
23        &self,
24        in_str: &str,
25        f_name: &str,
26        _config: &FluffConfig,
27        _formatter: &Option<Arc<dyn Formatter>>,
28    ) -> Result<TemplatedFile, SQLFluffUserError> {
29        if let Ok(tf) = TemplatedFile::new(in_str.to_string(), f_name.to_string(), None, None, None)
30        {
31            return Ok(tf);
32        }
33        panic!("Not implemented")
34    }
35}
36
37#[cfg(test)]
38mod test {
39    use super::*;
40
41    #[test]
42    /// Test the raw templater
43    fn test_templater_raw() {
44        let templater = RawTemplater;
45        let in_str = "SELECT * FROM {{blah}}";
46
47        let outstr = templater
48            .process(
49                in_str,
50                "test.sql",
51                &FluffConfig::from_source("", None),
52                &None,
53            )
54            .unwrap();
55
56        assert_eq!(outstr.templated_str, Some(in_str.to_string()));
57    }
58}