Skip to main content

md_tmpl_core/
consts.rs

1//! Shared string constants for the template engine.
2//!
3//! Every string that appears as a magic literal in more than one module
4//! or defines core syntax/grammar is defined here once.
5
6// -- Built-in function names --------------------------------------------------
7
8/// Name of the loop-index function: `idx(binding)`.
9pub(crate) const FN_IDX: &str = "idx";
10
11/// Name of the length function: `len(expr)`.
12pub(crate) const FN_LEN: &str = "len";
13
14/// Name of the explicit kind/variant-name function: `kind(expr)`.
15pub(crate) const FN_KIND: &str = "kind";
16/// Name of the enum variants list function: `kinds(expr)`.
17pub(crate) const FN_KINDS: &str = "kinds";
18
19/// Name of the option-presence function: `has(expr)`.
20pub(crate) const FN_HAS: &str = "has";
21
22/// All built-in function names.
23///
24/// Used by static analysis to avoid treating function names as variable
25/// references (e.g. `idx` in `idx(item)` is not a variable).
26pub(crate) const BUILTIN_FUNCTIONS: &[&str] = &[FN_IDX, FN_LEN, FN_KIND, FN_KINDS, FN_HAS];
27
28// -- Filter names -------------------------------------------------------------
29
30/// Name of the `upper` filter.
31pub(crate) const FILTER_UPPER: &str = "upper";
32/// Name of the `lower` filter.
33pub(crate) const FILTER_LOWER: &str = "lower";
34/// Name of the `trim` filter.
35pub(crate) const FILTER_TRIM: &str = "trim";
36/// Name of the `fixed` filter.
37pub(crate) const FILTER_FIXED: &str = "fixed";
38/// Name of the `join` filter.
39pub(crate) const FILTER_JOIN: &str = "join";
40/// Name of the `limit` filter.
41pub(crate) const FILTER_LIMIT: &str = "limit";
42/// Name of the `add` filter.
43pub(crate) const FILTER_ADD: &str = "add";
44/// Name of the `sub` filter.
45pub(crate) const FILTER_SUB: &str = "sub";
46
47// -- Enum tag key -------------------------------------------------------------
48
49/// Struct key used for internally-tagged enum variants:
50/// `{"__kind__": "VariantName", ...}`.
51///
52/// Uses a dunder prefix to avoid collisions with user-defined field names.
53pub const ENUM_TAG_KEY: &str = "__kind__";
54/// Struct key used for enum variant lists: `__variants__`.
55pub const ENUM_VARIANTS_KEY: &str = "__variants__";
56
57// -- Expression syntax chars --------------------------------------------------
58
59/// Opening parenthesis for function calls: `idx(item)`, `len(items)`.
60pub const PAREN_OPEN: char = '(';
61/// Closing parenthesis for function calls.
62pub const PAREN_CLOSE: char = ')';
63/// Dot separator for dotted path expressions: `item.label`.
64pub const PATH_SEP: char = '.';
65/// Pipe separator for filter chains: `{{ name | upper }}`.
66pub const PIPE: char = '|';
67/// Opening angle bracket for embed literals: `<file.txt>`.
68pub const ANGLE_OPEN: char = '<';
69/// Closing angle bracket for delimiters: `>`.
70pub const ANGLE_CLOSE: char = '>';
71/// Opening square bracket for delimiters: `[`.
72pub const BRACKET_OPEN: char = '[';
73/// Closing square bracket for delimiters: `]`.
74pub const BRACKET_CLOSE: char = ']';
75/// Opening brace character: `{`.
76pub const BRACE_OPEN: char = '{';
77/// Closing brace character: `}`.
78pub const BRACE_CLOSE: char = '}';
79/// Comma separator: `,`.
80pub const COMMA: char = ',';
81/// Colon separator: `:`.
82pub const COLON: char = ':';
83/// Equals separator: `=`.
84pub const EQUALS: char = '=';
85/// Slash separator: `/`.
86pub const SLASH: char = '/';
87/// Absolute path prefix: `/`.
88pub const PATH_PREFIX_SLASH: &str = "/";
89/// Relative current directory prefix: `./`.
90pub const PATH_PREFIX_CUR: &str = "./";
91/// Relative parent directory prefix: `../`.
92pub const PATH_PREFIX_PARENT: &str = "../";
93/// Windows relative current directory prefix: `.\`.
94pub const PATH_PREFIX_CUR_WIN: &str = ".\\";
95/// Windows relative parent directory prefix: `..\`.
96pub const PATH_PREFIX_PARENT_WIN: &str = "..\\";
97/// Backslash separator: `\`.
98pub const BACKSLASH: char = '\\';
99/// Newline character: `\n`.
100pub const CHAR_NEWLINE: char = '\n';
101/// Carriage return character: `\r`.
102pub const CHAR_CR: char = '\r';
103/// Space character: `' '`.
104pub const CHAR_SPACE: char = ' ';
105/// Tab character: `\t`.
106pub const CHAR_TAB: char = '\t';
107
108/// Newline string literal: `"\n"`.
109pub const STR_NEWLINE: &str = "\n";
110/// Double newline string literal: `"\n\n"`.
111pub const STR_DOUBLE_NEWLINE: &str = "\n\n";
112/// Carriage return + newline string literal: `"\r\n"`.
113pub const STR_CRLF: &str = "\r\n";
114
115/// Check if a resolved path starts with `/`, `./`, `../`, `.\`, or `..\`.
116#[must_use]
117pub fn is_valid_resolved_path(path: &str) -> bool {
118    path.starts_with(PATH_PREFIX_SLASH)
119        || path.starts_with(PATH_PREFIX_CUR)
120        || path.starts_with(PATH_PREFIX_PARENT)
121        || path.starts_with(PATH_PREFIX_CUR_WIN)
122        || path.starts_with(PATH_PREFIX_PARENT_WIN)
123}
124
125/// Check if a path starts with a valid import or include prefix (`/`, `./`, `../`, `.\`, `..\`, or an expression `{{`).
126#[must_use]
127pub fn is_valid_include_path(path: &str) -> bool {
128    is_valid_resolved_path(path) || path.starts_with(EXPR_START)
129}
130
131/// Template extension: `.tmpl.md`.
132pub const EXT_TMPL_MD: &str = ".tmpl.md";
133/// Template extension: `.tmpl`.
134pub const EXT_TMPL: &str = ".tmpl";
135/// Markdown extension: `.md`.
136pub const EXT_MD: &str = ".md";
137/// Block list item separator: ` - `.
138pub const LIST_BLOCK_SEP: &str = " - ";
139/// Block list item prefix: `- `.
140pub const LIST_ITEM_PREFIX: &str = "- ";
141/// Double-quote character for string literal delimiters.
142pub const QUOTE_DOUBLE: char = '"';
143/// Single-quote character for string literal delimiters.
144pub const QUOTE_SINGLE: char = '\'';
145
146pub const PAREN_OPEN_BYTE: u8 = b'(';
147pub const PAREN_CLOSE_BYTE: u8 = b')';
148pub const ANGLE_OPEN_BYTE: u8 = b'<';
149pub const ANGLE_CLOSE_BYTE: u8 = b'>';
150pub const BRACKET_OPEN_BYTE: u8 = b'[';
151pub const BRACKET_CLOSE_BYTE: u8 = b']';
152pub const BRACE_OPEN_BYTE: u8 = b'{';
153pub const BRACE_CLOSE_BYTE: u8 = b'}';
154pub const COLON_BYTE: u8 = b':';
155pub const EQUALS_BYTE: u8 = b'=';
156
157// -- Template tag delimiters -------------------------------------------------
158
159/// Delimiter indicating the start of an expression: `{{`.
160pub(crate) const EXPR_START: &str = "{{";
161/// Delimiter indicating the end of an expression: `}}`.
162pub(crate) const EXPR_END: &str = "}}";
163
164/// Delimiter indicating the start of a statement: `{%`.
165pub(crate) const STMT_START: &str = "{%";
166/// Delimiter indicating the end of a statement: `%}`.
167pub(crate) const STMT_END: &str = "%}";
168
169/// Delimiter indicating the start of a comment: `{#`.
170pub(crate) const COMMENT_START: &str = "{#";
171/// Delimiter indicating the end of a comment: `#}`.
172pub(crate) const COMMENT_END: &str = "#}";
173
174/// Whitespace control trim marker: `-`.
175pub(crate) const TRIM_MARKER: char = '-';
176
177// -- Grammar keywords and tags ------------------------------------------------
178
179/// Spaced for loop tag prefix: `for `.
180pub(crate) const TAG_FOR_PREFIX: &str = "for ";
181/// Spaced in keyword for loops: ` in `.
182pub(crate) const KW_IN_SPACED: &str = " in ";
183
184pub(crate) const OP_EQ: &str = " == ";
185pub(crate) const OP_NE: &str = " != ";
186pub(crate) const OP_LE: &str = " <= ";
187pub(crate) const OP_GE: &str = " >= ";
188pub(crate) const OP_LT: &str = " < ";
189pub(crate) const OP_GT: &str = " > ";
190
191/// Logical AND operator: `&&`.
192pub(crate) const OP_AND: &str = "&&";
193/// Logical OR operator: `||`.
194pub(crate) const OP_OR: &str = "||";
195/// Logical NOT operator: `!`.
196pub(crate) const OP_NOT: char = '!';
197
198/// Spaced if statement tag prefix: `if `.
199pub(crate) const TAG_IF_PREFIX: &str = "if ";
200/// Spaced elif statement tag prefix: `elif `.
201pub(crate) const TAG_ELIF_PREFIX: &str = "elif ";
202/// Else keyword: `else`.
203pub(crate) const KW_ELSE: &str = "else";
204
205/// Raw literal block keyword: `raw`.
206pub(crate) const KW_RAW: &str = "raw";
207/// Raw custom delimiter assignment prefix: `raw=`.
208pub(crate) const KW_RAW_ASSIGN: &str = "raw=";
209
210/// Include keyword: `include`.
211pub(crate) const KW_INCLUDE: &str = "include";
212/// Include statement prefix: `include `.
213pub(crate) const TAG_INCLUDE_PREFIX: &str = "include ";
214/// Include `with` override statement prefix: `with `.
215pub(crate) const TAG_WITH_PREFIX: &str = "with ";
216/// Spaced include `with` override: ` with `.
217pub(crate) const TAG_WITH_SPACED: &str = " with ";
218
219/// Inline template tag name: `tmpl `.
220pub(crate) const TAG_TMPL_PREFIX: &str = "tmpl ";
221
222/// Match statement tag prefix: `match `.
223pub(crate) const TAG_MATCH_PREFIX: &str = "match ";
224/// Case arm tag prefix: `case `.
225pub(crate) const TAG_CASE_PREFIX: &str = "case ";
226/// Spaced case keyword: ` case`.
227pub(crate) const TAG_CASE_SPACED: &str = " case";
228/// Spaced case keyword for match-as-condition: ` case `.
229pub(crate) const KW_CASE_SPACED: &str = " case ";
230/// Variant separator in match case arms: `|`.
231pub(crate) const VARIANT_SEP: char = '|';
232pub(crate) const KW_PANIC: &str = "panic";
233pub(crate) const TAG_PANIC_PREFIX: &str = "panic ";
234pub(crate) const TAG_PANIC_PAREN: &str = "panic(";
235
236// -- Closing block tags -------------------------------------------------------
237
238/// Closing tag for `if` statement block: `/if`.
239pub(crate) const CLOSE_IF: &str = "/if";
240/// Closing tag for `for` statement block: `/for`.
241pub(crate) const CLOSE_FOR: &str = "/for";
242/// Closing tag for `raw` statement block: `/raw`.
243pub(crate) const CLOSE_RAW: &str = "/raw";
244/// Closing tag for inline template definition: `/tmpl`.
245pub(crate) const CLOSE_TMPL: &str = "/tmpl";
246/// Closing tag for match block: `/match`.
247pub(crate) const CLOSE_MATCH: &str = "/match";
248
249// -- Markdown Blockquote delimiters -------------------------------------------
250
251/// Blockquote character used to prefix template directives: `>`.
252pub(crate) const BLOCKQUOTE_PREFIX: char = '>';
253/// Spaced blockquote prefix: `> `.
254pub(crate) const BLOCKQUOTE_PREFIX_SPACED: &str = "> ";
255/// Compact statement blockquote start: `>{`.
256pub(crate) const BLOCKQUOTE_COMPACT_OPEN: &str = ">{";
257/// Spaced statement blockquote start: `> {%`.
258pub(crate) const BLOCKQUOTE_SPACED_OPEN: &str = "> {%";
259
260// -- Frontmatter YAML delimiters & keys ---------------------------------------
261
262/// YAML frontmatter block delimiter: `---`.
263pub(crate) const FM_DELIMITER: &str = "---";
264/// YAML frontmatter block delimiter ending line: `\n---`.
265pub(crate) const FM_DELIMITER_NEWLINE: &str = "\n---";
266
267/// Frontmatter key for template name: `name:`.
268pub(crate) const FM_NAME_PREFIX: &str = "name:";
269/// Frontmatter key for template description: `description:`.
270pub(crate) const FM_DESC_PREFIX: &str = "description:";
271/// Frontmatter key for template parameters: `params:`.
272pub(crate) const FM_PARAMS_PREFIX: &str = "params:";
273/// Frontmatter key to allow unused declared parameters: `allow_unused:`.
274pub(crate) const FM_ALLOW_UNUSED_PREFIX: &str = "allow_unused:";
275/// Frontmatter key for local type aliases: `types:`.
276pub(crate) const FM_TYPES_PREFIX: &str = "types:";
277/// Frontmatter key for cross-template imports: `imports:`.
278pub(crate) const FM_IMPORTS_PREFIX: &str = "imports:";
279/// Frontmatter key for global constants: `consts:`.
280pub(crate) const FM_CONSTS_PREFIX: &str = "consts:";
281/// Frontmatter key for compile-time environment variables: `env:`.
282pub(crate) const FM_ENV_PREFIX: &str = "env:";
283
284// -- Type annotations ---------------------------------------------------------
285
286/// Type name for strings: `str`.
287pub(crate) const TYPE_STR: &str = "str";
288/// Type name for booleans: `bool`.
289pub(crate) const TYPE_BOOL: &str = "bool";
290/// Type name for integers: `int`.
291pub(crate) const TYPE_INT: &str = "int";
292/// Type name for floating point numbers: `float`.
293pub(crate) const TYPE_FLOAT: &str = "float";
294/// Type name for lists: `list`.
295pub(crate) const TYPE_LIST: &str = "list";
296/// Type name for structs: `struct`.
297pub(crate) const TYPE_STRUCT: &str = "struct";
298/// Type name for enums: `enum`.
299pub(crate) const TYPE_ENUM: &str = "enum";
300/// Type name for templates: `tmpl`.
301pub(crate) const TYPE_TMPL: &str = "tmpl";
302/// Type name for none/null: `none`.
303pub(crate) const TYPE_NONE: &str = "none";
304
305/// Type prefix for lists with parentheses: `list(`.
306pub(crate) const TYPE_LIST_PREFIX: &str = "list(";
307/// Type prefix for structs with parentheses: `struct(`.
308pub(crate) const TYPE_STRUCT_PREFIX: &str = "struct(";
309/// Type prefix for structs with angle brackets: `struct<`.
310pub(crate) const TYPE_STRUCT_ANGLE_PREFIX: &str = "struct<";
311/// Type prefix for structs with square brackets: `struct[`.
312pub(crate) const TYPE_STRUCT_BRACKET_PREFIX: &str = "struct[";
313/// Type prefix for structs with trailing space: `struct `.
314pub(crate) const TYPE_STRUCT_SPACE_PREFIX: &str = "struct ";
315/// Type prefix for enums with parentheses: `enum(`.
316pub(crate) const TYPE_ENUM_PREFIX: &str = "enum(";
317/// Type prefix for templates with parentheses: `tmpl(`.
318pub(crate) const TYPE_TMPL_PREFIX: &str = "tmpl(";
319/// Type name for options: `option`.
320pub(crate) const TYPE_OPTION: &str = "option";
321/// Type prefix for options with parentheses: `option(`.
322pub(crate) const TYPE_OPTION_PREFIX: &str = "option(";
323
324/// Variant name for the `Some` variant of `option(T)`.
325pub const OPTION_SOME: &str = "Some";
326/// Variant name for the `None` variant of `option(T)`.
327pub const OPTION_NONE: &str = "None";
328/// Field name for the inner value of `option(T)`'s `Some` variant.
329pub const OPTION_VAL_FIELD: &str = "val";
330/// Wildcard/default pattern in match arms: `_`.
331pub const MATCH_DEFAULT: &str = "_";
332
333// -- Variable prefixes --------------------------------------------------------
334
335/// Prefix for constant references: `consts.`.
336pub(crate) const PREFIX_CONSTS_DOT: &str = "consts.";
337/// Prefix for runtime options: `opts.`.
338pub(crate) const PREFIX_OPTS_DOT: &str = "opts.";
339/// Prefix for runtime options (alias): `options.`.
340pub(crate) const PREFIX_OPTIONS_DOT: &str = "options.";
341/// Prefix for parameter references: `params.`.
342pub(crate) const PREFIX_PARAMS_DOT: &str = "params.";
343
344// -- Literals -----------------------------------------------------------------
345
346/// Boolean true literal: `true`.
347pub(crate) const LIT_TRUE: &str = "true";
348/// Boolean false literal: `false`.
349pub(crate) const LIT_FALSE: &str = "false";
350
351/// Try to strip balanced quotes from a string literal token.
352///
353/// Returns `Some(inner)` if `token` is a valid quoted string literal
354/// (`"..."` or `'...'`), otherwise `None`.
355#[must_use]
356pub fn strip_string_literal(token: &str) -> Option<&str> {
357    if token.len() >= 2
358        && ((token.starts_with(QUOTE_DOUBLE) && token.ends_with(QUOTE_DOUBLE))
359            || (token.starts_with(QUOTE_SINGLE) && token.ends_with(QUOTE_SINGLE)))
360    {
361        return Some(&token[1..token.len() - 1]);
362    }
363    None
364}
365
366// -- Error messages -----------------------------------------------------------
367
368/// Error when frontmatter block is missing.
369pub(crate) const ERR_MISSING_FM: &str =
370    "missing mandatory YAML frontmatter block (starts with ---)";
371/// Error when frontmatter block is unclosed.
372pub(crate) const ERR_UNCLOSED_FM: &str = "unclosed YAML frontmatter block";
373/// Prefix for undeclared variable references error.
374pub(crate) const ERR_UNDECLARED_PREFIX: &str = "undeclared variable(s) referenced in body: ";
375
376/// Error when a param is named after a reserved keyword.
377pub(crate) const ERR_RESERVED_KEYWORD: &str = "reserved keyword used as name";
378/// Error when two params have the same name.
379pub(crate) const ERR_DUPLICATE_PARAM: &str = "duplicate parameter name";
380/// Error when a `types:` entry has a duplicate name.
381pub(crate) const ERR_DUPLICATE_TYPE_ALIAS: &str = "duplicate type alias";
382/// Error when a `types:` entry shadows a built-in type name.
383pub(crate) const ERR_BUILTIN_SHADOW: &str = "type alias shadows built-in type name";
384/// Error when a type alias and param name collide in `PascalCase`.
385pub(crate) const ERR_TYPE_PARAM_CONFLICT: &str =
386    "type alias name conflicts with parameter name (PascalCase collision)";
387/// Error for circular import chains.
388#[cfg(feature = "std")]
389pub(crate) const ERR_CIRCULAR_IMPORT: &str = "circular import detected";
390/// Error when a type alias name shadows an import alias (stem).
391pub(crate) const ERR_TYPE_SHADOWS_IMPORT: &str = "type alias shadows import alias";
392/// Error when a param's `PascalCase` name shadows an import alias.
393pub(crate) const ERR_PARAM_SHADOWS_IMPORT: &str =
394    "parameter name (PascalCase) shadows import alias";
395pub(crate) const ERR_UNUSED_TYPE_ALIAS: &str = "unused type alias";
396/// Error when a constant name is duplicated.
397pub(crate) const ERR_DUPLICATE_CONST: &str = "duplicate constant name";
398/// Error when a param and a const share the same name.
399pub(crate) const ERR_PARAM_CONST_CONFLICT: &str = "parameter name conflicts with constant name";
400/// Error when a for-loop binding shadows a declared name.
401pub(crate) const ERR_FOR_BINDING_SHADOWS: &str = "for loop binding shadows";
402/// Error when a `{% %}` tag starts a line without a blockquote `>` prefix.
403pub(crate) const ERR_BARE_STMT_TAG: &str =
404    "statement tag at line start must be blockquote-prefixed with '> '";
405/// Error when compound type uses angle or square brackets instead of parentheses.
406pub(crate) const ERR_COMPOUND_BRACKETS_PROHIBITED: &str =
407    "must use parentheses (...); angle brackets <...> and square brackets [...] are prohibited";
408
409/// Built-in type names and keywords that cannot be used as user-defined names.
410pub(crate) const RESERVED_NAMES: &[&str] = &[
411    TYPE_LIST,
412    TYPE_STRUCT,
413    TYPE_ENUM,
414    TYPE_TMPL,
415    TYPE_OPTION,
416    "params",
417    TYPE_STR,
418    TYPE_INT,
419    TYPE_FLOAT,
420    TYPE_BOOL,
421];
422
423#[cfg(test)]
424mod tests {
425    use super::*;
426
427    // -- strip_string_literal -------------------------------------------------
428
429    #[test]
430    fn strip_double_quoted_string() {
431        assert_eq!(strip_string_literal("\"hello\""), Some("hello"));
432    }
433
434    #[test]
435    fn strip_single_quoted_string() {
436        assert_eq!(strip_string_literal("'world'"), Some("world"));
437    }
438
439    #[test]
440    fn strip_empty_double_quoted_string() {
441        assert_eq!(strip_string_literal("\"\""), Some(""));
442    }
443
444    #[test]
445    fn strip_empty_single_quoted_string() {
446        assert_eq!(strip_string_literal("''"), Some(""));
447    }
448
449    #[test]
450    fn strip_unquoted_string_returns_none() {
451        assert_eq!(strip_string_literal("hello"), None);
452    }
453
454    #[test]
455    fn strip_mismatched_quotes_returns_none() {
456        assert_eq!(strip_string_literal("\"hello'"), None);
457        assert_eq!(strip_string_literal("'hello\""), None);
458    }
459
460    #[test]
461    fn strip_single_quote_char_returns_none() {
462        assert_eq!(strip_string_literal("\""), None);
463        assert_eq!(strip_string_literal("'"), None);
464    }
465
466    #[test]
467    fn strip_empty_input_returns_none() {
468        assert_eq!(strip_string_literal(""), None);
469    }
470
471    #[test]
472    fn strip_quoted_string_with_spaces() {
473        assert_eq!(strip_string_literal("\"hello world\""), Some("hello world"));
474        assert_eq!(strip_string_literal("'hello world'"), Some("hello world"));
475    }
476
477    #[test]
478    fn strip_quoted_string_with_inner_quotes() {
479        // Inner quotes of the opposite kind are preserved.
480        assert_eq!(strip_string_literal("\"it's\""), Some("it's"));
481        assert_eq!(strip_string_literal("'say \"hi\"'"), Some("say \"hi\""));
482    }
483
484    // -- RESERVED_NAMES -------------------------------------------------------
485
486    #[test]
487    fn reserved_names_contains_type_names() {
488        for name in &[
489            "list", "struct", "enum", "tmpl", "option", "str", "int", "float", "bool",
490        ] {
491            assert!(
492                RESERVED_NAMES.contains(name),
493                "{name} should be in RESERVED_NAMES"
494            );
495        }
496    }
497
498    #[test]
499    fn reserved_names_contains_params() {
500        assert!(RESERVED_NAMES.contains(&"params"));
501    }
502
503    // -- BUILTIN_FUNCTIONS ----------------------------------------------------
504
505    #[test]
506    fn builtin_functions_contains_expected_entries() {
507        assert!(BUILTIN_FUNCTIONS.contains(&"idx"));
508        assert!(BUILTIN_FUNCTIONS.contains(&"len"));
509        assert!(BUILTIN_FUNCTIONS.contains(&"kind"));
510        assert!(BUILTIN_FUNCTIONS.contains(&"kinds"));
511        assert!(BUILTIN_FUNCTIONS.contains(&"has"));
512    }
513
514    #[test]
515    fn builtin_functions_length() {
516        assert_eq!(BUILTIN_FUNCTIONS.len(), 5);
517    }
518
519    // -- Delimiter constants --------------------------------------------------
520
521    #[test]
522    fn expr_delimiters() {
523        assert_eq!(EXPR_START, "{{");
524        assert_eq!(EXPR_END, "}}");
525    }
526
527    #[test]
528    fn stmt_delimiters() {
529        assert_eq!(STMT_START, "{%");
530        assert_eq!(STMT_END, "%}");
531    }
532
533    #[test]
534    fn comment_delimiters() {
535        assert_eq!(COMMENT_START, "{#");
536        assert_eq!(COMMENT_END, "#}");
537    }
538
539    #[test]
540    fn closing_block_tags() {
541        assert_eq!(CLOSE_IF, "/if");
542        assert_eq!(CLOSE_FOR, "/for");
543        assert_eq!(CLOSE_RAW, "/raw");
544        assert_eq!(CLOSE_TMPL, "/tmpl");
545        assert_eq!(CLOSE_MATCH, "/match");
546    }
547
548    #[test]
549    fn frontmatter_delimiter() {
550        assert_eq!(FM_DELIMITER, "---");
551    }
552
553    #[test]
554    fn enum_tag_key_value() {
555        assert_eq!(ENUM_TAG_KEY, "__kind__");
556    }
557
558    #[test]
559    fn syntax_chars() {
560        assert_eq!(PAREN_OPEN, '(');
561        assert_eq!(PAREN_CLOSE, ')');
562        assert_eq!(PATH_SEP, '.');
563        assert_eq!(PIPE, '|');
564        assert_eq!(QUOTE_DOUBLE, '"');
565        assert_eq!(QUOTE_SINGLE, '\'');
566    }
567
568    #[test]
569    fn test_is_valid_include_path() {
570        assert!(is_valid_include_path("./file.tmpl.md"));
571        assert!(is_valid_include_path("../file.tmpl.md"));
572        assert!(is_valid_include_path(".\\file.tmpl.md"));
573        assert!(is_valid_include_path("..\\file.tmpl.md"));
574        assert!(is_valid_include_path("/file.tmpl.md"));
575        assert!(is_valid_include_path("{{ consts.DIR }}/file.tmpl.md"));
576        assert!(!is_valid_include_path("file.tmpl.md"));
577        assert!(!is_valid_include_path("sub/file.tmpl.md"));
578
579        assert!(is_valid_resolved_path("./file.tmpl.md"));
580        assert!(!is_valid_resolved_path("{{ consts.DIR }}/file.tmpl.md"));
581    }
582}