summaryrefslogtreecommitdiffstats
path: root/vendor/handlebars/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:31 +0000
commit2ff14448863ac1a1dd9533461708e29aae170c2d (patch)
tree85b9fea2bbfe3f06473cfa381eed11f273b57c5c /vendor/handlebars/tests
parentAdding debian version 1.64.0+dfsg1-1. (diff)
downloadrustc-2ff14448863ac1a1dd9533461708e29aae170c2d.tar.xz
rustc-2ff14448863ac1a1dd9533461708e29aae170c2d.zip
Adding debian version 1.65.0+dfsg1-2.debian/1.65.0+dfsg1-2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/handlebars/tests')
-rw-r--r--vendor/handlebars/tests/embed.rs29
-rw-r--r--vendor/handlebars/tests/escape.rs42
-rw-r--r--vendor/handlebars/tests/helper_macro.rs13
-rw-r--r--vendor/handlebars/tests/helper_with_space.rs54
-rw-r--r--vendor/handlebars/tests/templates/hello.hbs1
-rw-r--r--vendor/handlebars/tests/whitespace.rs24
6 files changed, 162 insertions, 1 deletions
diff --git a/vendor/handlebars/tests/embed.rs b/vendor/handlebars/tests/embed.rs
new file mode 100644
index 000000000..019f27db9
--- /dev/null
+++ b/vendor/handlebars/tests/embed.rs
@@ -0,0 +1,29 @@
+#[macro_use]
+extern crate serde_json;
+
+use handlebars::Handlebars;
+
+#[test]
+#[cfg(feature = "rust-embed")]
+fn test_embed() {
+ use rust_embed::RustEmbed;
+
+ #[derive(RustEmbed)]
+ #[folder = "tests/templates/"]
+ #[include = "*.hbs"]
+ struct Templates;
+
+ let mut hbs = Handlebars::new();
+ hbs.register_embed_templates::<Templates>().unwrap();
+
+ assert_eq!(1, hbs.get_templates().len());
+
+ let data = json!({
+ "name": "Andy"
+ });
+
+ assert_eq!(
+ hbs.render("hello.hbs", &data).unwrap().trim(),
+ "Hello, Andy"
+ );
+}
diff --git a/vendor/handlebars/tests/escape.rs b/vendor/handlebars/tests/escape.rs
index 563ab76b9..4a737f5ce 100644
--- a/vendor/handlebars/tests/escape.rs
+++ b/vendor/handlebars/tests/escape.rs
@@ -3,7 +3,7 @@ extern crate handlebars;
#[macro_use]
extern crate serde_json;
-use handlebars::{handlebars_helper, Handlebars};
+use handlebars::{handlebars_helper, no_escape, Handlebars};
#[test]
fn test_escape_216() {
@@ -41,3 +41,43 @@ fn test_string_no_escape_422() {
.unwrap()
);
}
+
+#[test]
+fn test_string_whitespace_467() {
+ const TEMPLATE_UNQUOTED: &str = r#"{{#each synonyms}}
+ {{this.name}} => '{{this.sym}}',
+ {{/each}}
+"#;
+
+ let mut hbs = Handlebars::new();
+ hbs.register_escape_fn(no_escape);
+ hbs.register_template_string("perl", TEMPLATE_UNQUOTED)
+ .unwrap();
+
+ let r = hbs
+ .render("perl", &json!({"synonyms": [{"name": "lt", "sym": "<"}]}))
+ .unwrap();
+ assert_eq!(" lt => '<',\n", r);
+}
+
+#[test]
+fn test_triple_bracket_expression_471() {
+ let mut hbs = Handlebars::new();
+
+ handlebars_helper!(replace: |input: str| {
+ input.replace("\n", "<br/>")
+ });
+ hbs.register_helper("replace", Box::new(replace));
+
+ assert_eq!(
+ "some&lt;br/&gt;path",
+ hbs.render_template("{{replace h}}", &json!({"h": "some\npath"}))
+ .unwrap()
+ );
+
+ assert_eq!(
+ "some<br/>path",
+ hbs.render_template("{{{replace h}}}", &json!({"h": "some\npath"}))
+ .unwrap()
+ );
+}
diff --git a/vendor/handlebars/tests/helper_macro.rs b/vendor/handlebars/tests/helper_macro.rs
index 9a8d2dc07..cc5ed914b 100644
--- a/vendor/handlebars/tests/helper_macro.rs
+++ b/vendor/handlebars/tests/helper_macro.rs
@@ -4,6 +4,8 @@ extern crate handlebars;
extern crate serde_json;
use handlebars::Handlebars;
+use time::format_description::{parse, well_known::Rfc2822};
+use time::OffsetDateTime;
handlebars_helper!(lower: |s: str| s.to_lowercase());
handlebars_helper!(upper: |s: str| s.to_uppercase());
@@ -14,6 +16,7 @@ handlebars_helper!(nargs: |*args| args.len());
handlebars_helper!(has_a: |{a:i64 = 99}, **kwargs|
format!("{}, {}", a, kwargs.get("a").is_some()));
handlebars_helper!(tag: |t: str| format!("<{}>", t));
+handlebars_helper!(date: |dt: OffsetDateTime| dt.format(&parse("[year]-[month]-[day]").unwrap()).unwrap());
#[test]
fn test_macro_helper() {
@@ -26,6 +29,7 @@ fn test_macro_helper() {
hbs.register_helper("nargs", Box::new(nargs));
hbs.register_helper("has_a", Box::new(has_a));
hbs.register_helper("tag", Box::new(tag));
+ hbs.register_helper("date", Box::new(date));
let data = json!("Teixeira");
@@ -73,4 +77,13 @@ fn test_macro_helper() {
hbs.render_template("{{{tag \"html\"}}}", &()).unwrap(),
"<html>"
);
+
+ assert_eq!(
+ hbs.render_template(
+ "{{date this}}",
+ &OffsetDateTime::parse("Wed, 18 Feb 2015 23:16:09 GMT", &Rfc2822).unwrap()
+ )
+ .unwrap(),
+ "2015-02-18"
+ );
}
diff --git a/vendor/handlebars/tests/helper_with_space.rs b/vendor/handlebars/tests/helper_with_space.rs
index 5a55ab122..853d5d24a 100644
--- a/vendor/handlebars/tests/helper_with_space.rs
+++ b/vendor/handlebars/tests/helper_with_space.rs
@@ -34,3 +34,57 @@ fn test_helper_with_space_param() {
.unwrap();
assert_eq!(s, "Output: Mozilla Firefox, Google Chrome".to_owned());
}
+
+#[test]
+fn test_empty_lines_472() {
+ let mut r = Handlebars::new();
+
+ r.register_template_string(
+ "t1",
+ r#"{{#each routes}}
+import { default as {{this.handler}} } from '{{this.file_path}}'
+{{/each}}
+
+addEventListener('fetch', (event) => {
+ event.respondWith(handleEvent(event))
+})"#,
+ )
+ .unwrap();
+
+ r.register_template_string(
+ "t2",
+ r#"addEventListener('fetch', (event) => {
+ event.respondWith(handleEvent(event))
+})
+
+{{#each routes}}
+import { default as {{this.handler}} } from '{{this.file_path}}'
+{{/each}}
+"#,
+ )
+ .unwrap();
+
+ let data = json!({"routes": [{"handler": "__hello_handler", "file_path": "./hello.js"},
+ {"handler": "__world_index_handler", "file_path": "./world/index.js"},
+ {"handler": "__index_handler", "file_path": "./index.js"}]});
+
+ let exp1 = r#"import { default as __hello_handler } from './hello.js'
+import { default as __world_index_handler } from './world/index.js'
+import { default as __index_handler } from './index.js'
+
+addEventListener('fetch', (event) => {
+ event.respondWith(handleEvent(event))
+})"#;
+
+ let exp2 = r#"addEventListener('fetch', (event) => {
+ event.respondWith(handleEvent(event))
+})
+
+import { default as __hello_handler } from './hello.js'
+import { default as __world_index_handler } from './world/index.js'
+import { default as __index_handler } from './index.js'
+"#;
+
+ assert_eq!(r.render("t1", &data).unwrap(), exp1);
+ assert_eq!(r.render("t2", &data).unwrap(), exp2);
+}
diff --git a/vendor/handlebars/tests/templates/hello.hbs b/vendor/handlebars/tests/templates/hello.hbs
new file mode 100644
index 000000000..a2344af53
--- /dev/null
+++ b/vendor/handlebars/tests/templates/hello.hbs
@@ -0,0 +1 @@
+Hello, {{name}}
diff --git a/vendor/handlebars/tests/whitespace.rs b/vendor/handlebars/tests/whitespace.rs
new file mode 100644
index 000000000..1c740556f
--- /dev/null
+++ b/vendor/handlebars/tests/whitespace.rs
@@ -0,0 +1,24 @@
+use handlebars::Handlebars;
+use serde_json::json;
+
+#[test]
+fn test_whitespaces_elision() {
+ let hbs = Handlebars::new();
+ assert_eq!(
+ "bar",
+ hbs.render_template(" {{~ foo ~}} ", &json!({"foo": "bar"}))
+ .unwrap()
+ );
+
+ assert_eq!(
+ "<bar/>",
+ hbs.render_template(" {{{~ foo ~}}} ", &json!({"foo": "<bar/>"}))
+ .unwrap()
+ );
+
+ assert_eq!(
+ "<bar/>",
+ hbs.render_template(" {{~ {foo} ~}} ", &json!({"foo": "<bar/>"}))
+ .unwrap()
+ );
+}