| 1 | #[macro_use] |
| 2 | extern crate handlebarsrust-analyzer cargo handlebars 5.1.2 handlebars/; |
| 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/::Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#; |
| 7 | use timerust-analyzer cargo time 0.3.34 crate/::format_descriptionrust-analyzer cargo time 0.3.34 format_description/::{parserust-analyzer cargo time 0.3.34 format_description/parse/parse()., well_knownrust-analyzer cargo time 0.3.34 format_description/well_known/::Rfc2822rust-analyzer cargo time 0.3.34 format_description/well_known/rfc2822/Rfc2822#}; |
| 8 | use timerust-analyzer cargo time 0.3.34 crate/::OffsetDateTimerust-analyzer cargo time 0.3.34 offset_date_time/OffsetDateTime#; |
| 9 | |
| 10 | handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(lowerrust-analyzer cargo handlebars 5.1.2 lower#: |s: str| s.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().()); |
| 11 | handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(upperrust-analyzer cargo handlebars 5.1.2 upper#: |s: str| s.to_uppercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_uppercase().()); |
| 12 | handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(hexrust-analyzer cargo handlebars 5.1.2 hex#: |v: i64| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("0x{:x}", v)); |
| 13 | handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(moneyrust-analyzer cargo handlebars 5.1.2 money#: |v: i64, {cur: str="$"}| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}{}.00", cur, v)); |
| 14 | handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(all_hashrust-analyzer cargo handlebars 5.1.2 all_hash#: |{cur: str="$"}| cur); |
| 15 | handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(nargsrust-analyzer cargo handlebars 5.1.2 nargs#: |*args| args.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 16 | handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(has_arust-analyzer cargo handlebars 5.1.2 has_a#: |{a:i64 = 99}, **kwargs| |
| 17 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}, {}", a, kwargs.getrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]get().("a").is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().())); |
| 18 | handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(tagrust-analyzer cargo handlebars 5.1.2 tag#: |t: str| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("<{}>", t)); |
| 19 | handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(daterust-analyzer cargo handlebars 5.1.2 date#: |dt: OffsetDateTimerust-analyzer cargo time 0.3.34 offset_date_time/OffsetDateTime#| dt.formatrust-analyzer cargo time 0.3.34 offset_date_time/impl#[OffsetDateTime]format().(&parserust-analyzer cargo time 0.3.34 format_description/parse/parse().("[year]-[month]-[day]").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 20 | |
| 21 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 22 | fn test_macro_helperrust-analyzer cargo handlebars 5.1.2 test_macro_helper().() { |
| 23 | let mut hbs = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 24 | |
| 25 | hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("lower", 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().(lowerrust-analyzer cargo handlebars 5.1.2 lower#)); |
| 26 | hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("upper", 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().(upperrust-analyzer cargo handlebars 5.1.2 upper#)); |
| 27 | hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("hex", 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().(hexrust-analyzer cargo handlebars 5.1.2 hex#)); |
| 28 | hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("money", 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().(moneyrust-analyzer cargo handlebars 5.1.2 money#)); |
| 29 | hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("nargs", 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().(nargsrust-analyzer cargo handlebars 5.1.2 nargs#)); |
| 30 | hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("has_a", 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().(has_arust-analyzer cargo handlebars 5.1.2 has_a#)); |
| 31 | hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("tag", 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().(tagrust-analyzer cargo handlebars 5.1.2 tag#)); |
| 32 | hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("date", 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().(daterust-analyzer cargo handlebars 5.1.2 date#)); |
| 33 | |
| 34 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!("Teixeira"); |
| 35 | |
| 36 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 37 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{lower this}}", &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 38 | "teixeira" |
| 39 | ); |
| 40 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 41 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{upper this}}", &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 42 | "TEIXEIRA" |
| 43 | ); |
| 44 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{hex 16}}", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "0x10"); |
| 45 | |
| 46 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 47 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{money 5000}}", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 48 | "$5000.00" |
| 49 | ); |
| 50 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 51 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{money 5000 cur=\"£\"}}", &()) |
| 52 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 53 | "£5000.00" |
| 54 | ); |
| 55 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 56 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{nargs 1 1 1 1 1}}", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 57 | "5" |
| 58 | ); |
| 59 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{nargs}}", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "0"); |
| 60 | |
| 61 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 62 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{has_a a=1 b=2}}", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 63 | "1, true" |
| 64 | ); |
| 65 | |
| 66 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 67 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{has_a x=1 b=2}}", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 68 | "99, false" |
| 69 | ); |
| 70 | |
| 71 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 72 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{tag \"html\"}}", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 73 | "<html>" |
| 74 | ); |
| 75 | |
| 76 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 77 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{{tag \"html\"}}}", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 78 | "<html>" |
| 79 | ); |
| 80 | |
| 81 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 82 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().( |
| 83 | "{{date this}}", |
| 84 | &OffsetDateTimerust-analyzer cargo time 0.3.34 offset_date_time/OffsetDateTime#::parserust-analyzer cargo time 0.3.34 offset_date_time/impl#[OffsetDateTime]parse().("Wed, 18 Feb 2015 23:16:09 GMT", &Rfc2822rust-analyzer cargo time 0.3.34 format_description/well_known/rfc2822/Rfc2822#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 85 | ) |
| 86 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 87 | "2015-02-18" |
| 88 | ); |
| 89 | |
| 90 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 91 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{eq image.link null}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"image": {"link": null}})) |
| 92 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 93 | "true" |
| 94 | ); |
| 95 | |
| 96 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 97 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().( |
| 98 | "{{eq image.link null}}", |
| 99 | &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"image": {"link": "https://url"}}) |
| 100 | ) |
| 101 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 102 | "false" |
| 103 | ); |
| 104 | |
| 105 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 106 | hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{tag 'html'}}", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 107 | "<html>" |
| 108 | ); |
| 109 | } |