Debian Codegraph @

tests/escape.rs

raw symbols SCIP
1 extern crate handlebarsrust-analyzer cargo handlebars 5.1.2 handlebars/;
2
3 #[macro_use]
4 extern crate serde_jsonrust-analyzer cargo handlebars 5.1.2 serde_json/;
5
6 use handlebarsrust-analyzer cargo handlebars 5.1.2 crate/::{handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!, no_escaperust-analyzer cargo handlebars 5.1.2 registry/no_escape()., Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#};
7
8 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
9 fn test_escape_216rust-analyzer cargo handlebars 5.1.2 test_escape_216().() {
10 let hbs = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
11
12 let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
13 "FOO": "foo",
14 "BAR": "bar"
15 });
16
17 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
18 hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(r"\\\\ {{FOO}} {{BAR}} {{FOO}}{{BAR}} {{FOO}}#{{BAR}} {{FOO}}//{{BAR}} {{FOO}}\\{{FOO}} {{FOO}}\\\\{{FOO}}\\\{{FOO}} \\\{{FOO}} \{{FOO}} \{{FOO}}", &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
19 r"\\\\ foo bar foobar foo#bar foo//bar foo\foo foo\\\foo\\foo \\foo {{FOO}} {{FOO}}"
20 );
21 }
22
23 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
24 fn test_string_no_escape_422rust-analyzer cargo handlebars 5.1.2 test_string_no_escape_422().() {
25 let mut hbs = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
26
27 handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(replacerust-analyzer cargo handlebars 5.1.2 replace#: |input: str, from: str, to: str| {
28 input.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(from, to)
29 });
30 handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(echorust-analyzer cargo handlebars 5.1.2 echo#: |input: str| {
31 input
32 });
33 hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("replace", Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(replacerust-analyzer cargo handlebars 5.1.2 replace#));
34 hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("echo", Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(echorust-analyzer cargo handlebars 5.1.2 echo#));
35
36 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
37 r#"some\ path"#,
38 hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(r#"{{replace "some/path" "/" "\\ " }}"#, &())
39 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
40 );
41 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
42 r#"some\ path"#,
43 hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(r#"{{replace 'some/path' '/' '\\ ' }}"#, &())
44 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
45 );
46
47 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
48 r#"some\path"#,
49 hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(r#"{{replace "some/path" "/" "\\" }}"#, &())
50 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
51 );
52 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
53 r#"some\path"#,
54 hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(r#"{{replace 'some/path' '/' '\\' }}"#, &())
55 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
56 );
57
58 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
59 r#"double-quoted \ &#x27;with&#x27; &quot;nesting&quot;"#,
60 hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(r#"{{echo "double-quoted \\ 'with' \"nesting\""}}"#, &())
61 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
62 );
63 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
64 r#"single-quoted \ &#x27;with&#x27; &quot;nesting&quot;"#,
65 hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(r#"{{echo 'single-quoted \\ \'with\' "nesting"'}}"#, &())
66 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
67 );
68 }
69
70 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
71 fn test_string_whitespace_467rust-analyzer cargo handlebars 5.1.2 test_string_whitespace_467().() {
72 const TEMPLATE_UNQUOTEDrust-analyzer cargo handlebars 5.1.2 TEMPLATE_UNQUOTED.: &str = r#"{{#each synonyms}}
73 {{this.name}} => '{{this.sym}}',
74 {{/each}}
75 "#;
76
77 let mut hbs = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
78 hbs.register_escape_fnrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_escape_fn().(no_escaperust-analyzer cargo handlebars 5.1.2 registry/no_escape().);
79 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("perl", TEMPLATE_UNQUOTEDrust-analyzer cargo handlebars 5.1.2 TEMPLATE_UNQUOTED.)
80 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
81
82 let r = hbs
83 .renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("perl", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"synonyms": [{"name": "lt", "sym": "<"}]}))
84 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
85 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(" lt => '<',\n", r);
86 }
87
88 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
89 fn test_triple_bracket_expression_471rust-analyzer cargo handlebars 5.1.2 test_triple_bracket_expression_471().() {
90 let mut hbs = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
91
92 handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(replacerust-analyzer cargo handlebars 5.1.2 replace#: |input: str| {
93 input.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("\n", "<br/>")
94 });
95 hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("replace", Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(replacerust-analyzer cargo handlebars 5.1.2 replace#));
96
97 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
98 "some&lt;br/&gt;path",
99 hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{replace h}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"h": "some\npath"}))
100 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
101 );
102
103 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
104 "some<br/>path",
105 hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{{replace h}}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"h": "some\npath"}))
106 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
107 );
108 }
109
110 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
111 fn test_trimmed_nonescaped_variablerust-analyzer cargo handlebars 5.1.2 test_trimmed_nonescaped_variable().() {
112 let mut handlebars = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
113 handlebars
114 .register_partialrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_partial().("system", "system: {{~{system}~}}")
115 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
116
117 let output = handlebars
118 .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{>system system=\"hello\" prompt=\" world\"}}", &())
119 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
120
121 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, "system:hello");
122 }