Debian Codegraph @

src/helpers/helper_each.rs

raw symbols SCIP
1 use serde_jsonrust-analyzer cargo serde_json 1.0.114 crate/::valuerust-analyzer cargo serde_json 1.0.114 value/::Valuerust-analyzer cargo serde_json 1.0.114 value/Value# as Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#;
2
3 use superrust-analyzer cargo handlebars 5.1.2 helpers/::block_utilrust-analyzer cargo handlebars 5.1.2 helpers/block_util/::create_blockrust-analyzer cargo handlebars 5.1.2 helpers/block_util/create_block().;
4 use craterust-analyzer cargo handlebars 5.1.2 crate/::blockrust-analyzer cargo handlebars 5.1.2 block/::{BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#, BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#};
5 use craterust-analyzer cargo handlebars 5.1.2 crate/::contextrust-analyzer cargo handlebars 5.1.2 context/::Contextrust-analyzer cargo handlebars 5.1.2 context/Context#;
6 use craterust-analyzer cargo handlebars 5.1.2 crate/::errorrust-analyzer cargo handlebars 5.1.2 error/::RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#;
7 use craterust-analyzer cargo handlebars 5.1.2 crate/::helpersrust-analyzer cargo handlebars 5.1.2 helpers/::{HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef#, HelperResultrust-analyzer cargo handlebars 5.1.2 helpers/HelperResult#};
8 use craterust-analyzer cargo handlebars 5.1.2 crate/::jsonrust-analyzer cargo handlebars 5.1.2 json/::valuerust-analyzer cargo handlebars 5.1.2 json/value/::to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().;
9 use craterust-analyzer cargo handlebars 5.1.2 crate/::outputrust-analyzer cargo handlebars 5.1.2 output/::Outputrust-analyzer cargo handlebars 5.1.2 output/Output#;
10 use craterust-analyzer cargo handlebars 5.1.2 crate/::registryrust-analyzer cargo handlebars 5.1.2 registry/::Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#;
11 use craterust-analyzer cargo handlebars 5.1.2 crate/::renderrust-analyzer cargo handlebars 5.1.2 render/::{Helperrust-analyzer cargo handlebars 5.1.2 render/Helper#, RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#, Renderablerust-analyzer cargo handlebars 5.1.2 render/Renderable#};
12 use craterust-analyzer cargo handlebars 5.1.2 crate/::utilrust-analyzer cargo handlebars 5.1.2 util/::copy_on_push_vecrust-analyzer cargo handlebars 5.1.2 util/copy_on_push_vec().;
13 use craterust-analyzer cargo handlebars 5.1.2 crate/::RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#;
14
15 fn update_block_contextrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/update_block_context().(
16 block: &mut BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#<'_>,
17 base_path: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>,
18 relative_path: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
19 is_first: bool,
20 value: &Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#,
21 ) {
22 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(p) = base_path {
23 if is_first {
24 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().block.base_path_mutrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_path_mut().() = copy_on_push_vecrust-analyzer cargo handlebars 5.1.2 util/copy_on_push_vec().(p, relative_path);
25 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ptr) = block.base_path_mutrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_path_mut().().last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().() {
26 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().ptr = relative_path;
27 }
28 } else {
29 block.set_base_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_base_value().(value.clonerust-analyzer cargo serde_json 1.0.114 value/impl#[Value][Clone]clone().());
30 }
31 }
32
33 fn set_block_paramrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/set_block_param().<'rc>(
34 block: &mut BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#<'rc>,
35 h: &Helperrust-analyzer cargo handlebars 5.1.2 render/Helper#<'rc>,
36 base_path: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>,
37 k: &Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#,
38 v: &Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#,
39 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> {
40 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(bp_val) = h.block_paramrust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]block_param().() {
41 let mut params = BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#::newrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]new().();
42 if base_path.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
43 params.add_pathrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]add_path().(bp_val, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(0))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
44 } else {
45 params.add_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]add_value().(bp_val, v.clonerust-analyzer cargo serde_json 1.0.114 value/impl#[Value][Clone]clone().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
46 }
47
48 block.set_block_paramsrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_block_params().(params);
49 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((bp_val, bp_key)) = h.block_param_pairrust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]block_param_pair().() {
50 let mut params = BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#::newrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]new().();
51 if base_path.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
52 params.add_pathrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]add_path().(bp_val, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(0))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
53 } else {
54 params.add_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]add_value().(bp_val, v.clonerust-analyzer cargo serde_json 1.0.114 value/impl#[Value][Clone]clone().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
55 }
56 params.add_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]add_value().(bp_key, k.clonerust-analyzer cargo serde_json 1.0.114 value/impl#[Value][Clone]clone().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
57
58 block.set_block_paramsrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_block_params().(params);
59 }
60
61 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
62 }
63
64 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
65 pub struct EachHelperrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/EachHelper#;
66
67 impl HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef# for EachHelperrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/EachHelper# {
68 fn callrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/impl#[EachHelper][HelperDef]call().<'reg: 'rc, 'rc>(
69 &self,
70 h: &Helperrust-analyzer cargo handlebars 5.1.2 render/Helper#<'rc>,
71 r: &'reg Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg>,
72 ctx: &'rc Contextrust-analyzer cargo handlebars 5.1.2 context/Context#,
73 rc: &mut RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#<'reg, 'rc>,
74 out: &mut dyn Outputrust-analyzer cargo handlebars 5.1.2 output/Output#,
75 ) -> HelperResultrust-analyzer cargo handlebars 5.1.2 helpers/HelperResult# {
76 let value = h
77 .paramrust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]param().(0)
78 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#::ParamNotFoundForIndexrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#ParamNotFoundForIndex#("each", 0))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
79
80 let template = h.templaterust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]template().();
81
82 match template {
83 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) => match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().value.valuerust-analyzer cargo handlebars 5.1.2 json/value/impl#[`PathAndJson<'rc>`]value().() {
84 Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#::Arrayrust-analyzer cargo serde_json 1.0.114 value/Value#Array#(ref list)
85 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().list.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() || (list.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() && h.inverserust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]inverse().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()) =>
86 {
87 let block_context = create_blockrust-analyzer cargo handlebars 5.1.2 helpers/block_util/create_block().(value);
88 rc.push_blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]push_block().(block_context);
89
90 let len = list.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().();
91
92 let array_path = value.context_pathrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`PathAndJson<'rc>`]context_path().();
93
94 for (i, v) in list.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(len) {
95 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut block) = rc.block_mutrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]block_mut().() {
96 let is_first = i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0usize;
97 let is_last = i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1;
98
99 let index = to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().(i);
100 block.set_local_varrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_local_var().("first", to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().(is_first));
101 block.set_local_varrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_local_var().("last", to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().(is_last));
102 block.set_local_varrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_local_var().("index", index.clonerust-analyzer cargo serde_json 1.0.114 value/impl#[Value][Clone]clone().());
103
104 update_block_contextrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/update_block_context().(block, array_path, i.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), is_first, v);
105 set_block_paramrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/set_block_param().(block, h, array_path, &index, v)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
106 }
107
108 t.renderrust-analyzer cargo handlebars 5.1.2 render/impl#[Template][Renderable]render().(r, ctx, rc, out)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
109 }
110
111 rc.pop_blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]pop_block().();
112 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
113 }
114 Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#::Objectrust-analyzer cargo serde_json 1.0.114 value/Value#Object#(ref obj)
115 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().obj.is_emptyrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]is_empty().() || (obj.is_emptyrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]is_empty().() && h.inverserust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]inverse().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()) =>
116 {
117 let block_context = create_blockrust-analyzer cargo handlebars 5.1.2 helpers/block_util/create_block().(value);
118 rc.push_blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]push_block().(block_context);
119
120 let len = obj.lenrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]len().();
121
122 let obj_path = value.context_pathrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`PathAndJson<'rc>`]context_path().();
123
124 for (i, (k, v)) in obj.iterrust-analyzer cargo serde_json 1.0.114 map/impl#[`Map<String, Value>`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
125 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut block) = rc.block_mutrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]block_mut().() {
126 let is_first = i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0usize;
127 let is_last = i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1;
128
129 let key = to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().(k);
130 block.set_local_varrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_local_var().("first", to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().(is_first));
131 block.set_local_varrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_local_var().("last", to_jsonrust-analyzer cargo handlebars 5.1.2 json/value/to_json().(is_last));
132 block.set_local_varrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_local_var().("key", key.clonerust-analyzer cargo serde_json 1.0.114 value/impl#[Value][Clone]clone().());
133
134 update_block_contextrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/update_block_context().(block, obj_path, k.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), is_first, v);
135 set_block_paramrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/set_block_param().(block, h, obj_path, &key, v)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
136 }
137
138 t.renderrust-analyzer cargo handlebars 5.1.2 render/impl#[Template][Renderable]render().(r, ctx, rc, out)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
139 }
140
141 rc.pop_blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]pop_block().();
142 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
143 }
144 _ => {
145 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(else_template) = h.inverserust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]inverse().() {
146 else_template.renderrust-analyzer cargo handlebars 5.1.2 render/impl#[Template][Renderable]render().(r, ctx, rc, out)
147 } else if r.strict_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]strict_mode().() {
148 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#::strict_errorrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError]strict_error().(value.relative_pathrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`PathAndJson<'rc>`]relative_path().()))
149 } else {
150 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
151 }
152 }
153 },
154 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()),
155 }
156 }
157 }
158
159 pub static EACH_HELPERrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/EACH_HELPER.: EachHelperrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/EachHelper# = EachHelperrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/EachHelper#;
160
161 #[cfg(test)]
162 mod testrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/ {
163 use craterust-analyzer cargo handlebars 5.1.2 crate/::registryrust-analyzer cargo handlebars 5.1.2 registry/::Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#;
164 use serde_jsonrust-analyzer cargo serde_json 1.0.114 crate/::valuerust-analyzer cargo serde_json 1.0.114 value/::Valuerust-analyzer cargo serde_json 1.0.114 value/Value# as Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#;
165 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#;
166 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
167
168 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
169 fn test_empty_eachrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_empty_each().() {
170 let mut hbs = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
171 hbs.set_strict_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_strict_mode().(true);
172
173 let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
174 "a": [ ],
175 });
176
177 let template = "{{#each a}}each{{/each}}";
178 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().(template, &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "");
179 }
180
181 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
182 fn test_eachrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_each().() {
183 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
184 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
185 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
186 "t0",
187 "{{#each this}}{{@first}}|{{@last}}|{{@index}}:{{this}}|{{/each}}",
188 )
189 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
190 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
191 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
192 "t1",
193 "{{#each this}}{{@first}}|{{@last}}|{{@key}}:{{this}}|{{/each}}",
194 )
195 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
196
197 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1u16, 2u16, 3u16]);
198 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
199 r0.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
200 "true|false|0:1|false|false|1:2|false|true|2:3|".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
201 );
202
203 let mut m: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, u16> = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().();
204 m.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().("ftp".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 21);
205 m.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().("gopher".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 70);
206 m.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().("http".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 80);
207 let r1 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t1", &m);
208 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
209 r1.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
210 "true|false|ftp:21|false|false|gopher:70|false|true|http:80|".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
211 );
212 }
213
214 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
215 fn test_each_with_parentrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_each_with_parent().() {
216 let json_str = r#"{"a":{"a":99,"c":[{"d":100},{"d":200}]}}"#;
217
218 let data = Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#::from_strrust-analyzer cargo serde_json 1.0.114 value/de/impl#[Value][FromStr]from_str().(json_str).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
219 // println!("data: {}", data);
220 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
221
222 // previously, to access the parent in an each block,
223 // a user would need to specify ../../b, as the path
224 // that is computed includes the array index: ./a.c.[0]
225 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
226 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{#each a.c}} d={{d}} b={{../a.a}} {{/each}}")
227 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
228
229 let r1 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &data);
230 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), " d=100 b=99 d=200 b=99 ".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
231 }
232
233 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
234 fn test_nested_each_with_parentrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_nested_each_with_parent().() {
235 let json_str = r#"{"a": [{"b": [{"d": 100}], "c": 200}]}"#;
236
237 let data = Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#::from_strrust-analyzer cargo serde_json 1.0.114 value/de/impl#[Value][FromStr]from_str().(json_str).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
238 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
239 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
240 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
241 "t0",
242 "{{#each a}}{{#each b}}{{d}}:{{../c}}{{/each}}{{/each}}",
243 )
244 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
245
246 let r1 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &data);
247 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "100:200".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
248 }
249
250 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
251 fn test_nested_eachrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_nested_each().() {
252 let json_str = r#"{"a": [{"b": true}], "b": [[1, 2, 3],[4, 5]]}"#;
253
254 let data = Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#::from_strrust-analyzer cargo serde_json 1.0.114 value/de/impl#[Value][FromStr]from_str().(json_str).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
255
256 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
257 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
258 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
259 "t0",
260 "{{#each b}}{{#if ../a}}{{#each this}}{{this}}{{/each}}{{/if}}{{/each}}",
261 )
262 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
263
264 let r1 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &data);
265 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "12345".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
266 }
267
268 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
269 fn test_nested_arrayrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_nested_array().() {
270 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
271 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
272 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{#each this.[0]}}{{this}}{{/each}}")
273 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
274
275 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2, 3]]));
276
277 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "123".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
278 }
279
280 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
281 fn test_empty_keyrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_empty_key().() {
282 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
283 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
284 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{#each this}}{{@key}}-{{value}}\n{{/each}}")
285 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
286
287 let r0 = handlebars
288 .renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().(
289 "t0",
290 &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
291 "foo": {
292 "value": "bar"
293 },
294 "": {
295 "value": "baz"
296 }
297 }),
298 )
299 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
300
301 let mut r0_sp: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = r0.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('\n').collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
302 r0_sp.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().();
303
304 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0_sp, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["", "-baz", "foo-bar"]);
305 }
306
307 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
308 fn test_each_elserust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_each_else().() {
309 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
310 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
311 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{#each a}}1{{else}}empty{{/each}}")
312 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
313 let m1 = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
314 "a": []
315 });
316 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &m1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
317 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0, "empty");
318
319 let m2 = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
320 "b": []
321 });
322 let r1 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &m2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
323 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1, "empty");
324 }
325
326 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
327 fn test_block_paramrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_block_param().() {
328 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
329 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
330 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{#each a as |i|}}{{i}}{{/each}}")
331 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
332 let m1 = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
333 "a": [1,2,3,4,5]
334 });
335 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &m1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
336 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0, "12345");
337 }
338
339 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
340 fn test_each_object_block_paramrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_each_object_block_param().() {
341 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
342 let template = "{{#each this as |v k|}}\
343 {{#with k as |inner_k|}}{{inner_k}}{{/with}}:{{v}}|\
344 {{/each}}";
345 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", template).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
346
347 let m = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
348 "ftp": 21,
349 "http": 80
350 });
351 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &m);
352 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "ftp:21|http:80|".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
353 }
354
355 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
356 fn test_each_object_block_param2rust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_each_object_block_param2().() {
357 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
358 let template = "{{#each this as |v k|}}\
359 {{#with v as |inner_v|}}{{k}}:{{inner_v}}{{/with}}|\
360 {{/each}}";
361
362 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", template).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
363
364 let m = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
365 "ftp": 21,
366 "http": 80
367 });
368 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &m);
369 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "ftp:21|http:80|".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
370 }
371
372 fn test_nested_each_with_path_upsrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_nested_each_with_path_ups().() {
373 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
374 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
375 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
376 "t0",
377 "{{#each a.b}}{{#each c}}{{../../d}}{{/each}}{{/each}}",
378 )
379 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
380
381 let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
382 "a": {
383 "b": [{"c": [1]}]
384 },
385 "d": 1
386 });
387
388 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &data);
389 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "1".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
390 }
391
392 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
393 fn test_nested_each_with_path_up_thisrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_nested_each_with_path_up_this().() {
394 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
395 let template = "{{#each variant}}{{#each ../typearg}}\
396 {{#if @first}}template<{{/if}}{{this}}{{#if @last}}>{{else}},{{/if}}\
397 {{/each}}{{/each}}";
398 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", template).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
399 let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
400 "typearg": ["T"],
401 "variant": ["1", "2"]
402 });
403 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &data);
404 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "template<T>template<T>".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
405 }
406
407 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
408 fn test_key_iteration_with_unicoderust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_key_iteration_with_unicode().() {
409 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
410 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
411 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{#each this}}{{@key}}: {{this}}\n{{/each}}")
412 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
413 let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
414 "normal": 1,
415 "你好": 2,
416 "#special key": 3,
417 "😂": 4,
418 "me.dot.key": 5
419 });
420 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &data).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
421 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r0.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("normal: 1"));
422 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r0.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("你好: 2"));
423 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r0.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("#special key: 3"));
424 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r0.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("😂: 4"));
425 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r0.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("me.dot.key: 5"));
426 }
427
428 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
429 fn test_base_path_after_eachrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_base_path_after_each().() {
430 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
431 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
432 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{#each a}}{{this}}{{/each}} {{b}}")
433 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
434 let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
435 "a": [1, 2, 3, 4],
436 "b": "good",
437 });
438
439 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &data).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
440
441 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("1234 good", r0);
442 }
443
444 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
445 fn test_else_contextrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_else_context().() {
446 let reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
447 let template = "{{#each list}}A{{else}}{{foo}}{{/each}}";
448 let input = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"list": [], "foo": "bar"});
449 let rendered = reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(template, &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
450 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("bar", rendered);
451 }
452
453 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
454 fn test_block_context_leakrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_block_context_leak().() {
455 let reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
456 let template = "{{#each list}}{{#each inner}}{{this}}{{/each}}{{foo}}{{/each}}";
457 let input = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"list": [{"inner": [], "foo": 1}, {"inner": [], "foo": 2}]});
458 let rendered = reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(template, &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
459 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("12", rendered);
460 }
461
462 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
463 fn test_derived_array_as_block_paramsrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_derived_array_as_block_params().() {
464 handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(rangerust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/range#: |x: u64| (0..x).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u64>>());
465 let mut reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
466 reg.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("range", 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().(rangerust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/range#));
467 let template = "{{#each (range 3) as |i|}}{{i}}{{/each}}";
468 let input = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!(0);
469 let rendered = reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(template, &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
470 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("012", rendered);
471 }
472
473 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
474 fn test_derived_object_as_block_paramsrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_derived_object_as_block_params().() {
475 handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(pointrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/point#: |x: u64, y: u64| jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"x":x, "y":y}));
476 let mut reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
477 reg.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("point", 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().(pointrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/point#));
478 let template = "{{#each (point 0 1) as |i|}}{{i}}{{/each}}";
479 let input = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!(0);
480 let rendered = reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(template, &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
481 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("01", rendered);
482 }
483
484 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
485 fn test_derived_array_without_block_paramrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_derived_array_without_block_param().() {
486 handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(rangerust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/range#: |x: u64| (0..x).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u64>>());
487 let mut reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
488 reg.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("range", 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().(rangerust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/range#));
489 let template = "{{#each (range 3)}}{{this}}{{/each}}";
490 let input = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!(0);
491 let rendered = reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(template, &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
492 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("012", rendered);
493 }
494
495 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
496 fn test_derived_object_without_block_paramsrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_derived_object_without_block_params().() {
497 handlebars_helperrust-analyzer cargo handlebars 5.1.2 macros/handlebars_helper!!(pointrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/point#: |x: u64, y: u64| jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"x":x, "y":y}));
498 let mut reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
499 reg.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("point", 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().(pointrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/point#));
500 let template = "{{#each (point 0 1)}}{{this}}{{/each}}";
501 let input = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!(0);
502 let rendered = reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(template, &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
503 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("01", rendered);
504 }
505
506 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
507 fn test_non_iterablerust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_non_iterable().() {
508 let reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
509 let template = "{{#each this}}each block{{else}}else block{{/each}}";
510 let input = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!("strings aren't iterable");
511 let rendered = reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(template, &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
512 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("else block", rendered);
513 }
514
515 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
516 fn test_render_array_without_trailig_commasrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_render_array_without_trailig_commas().() {
517 let reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
518 let template = "Array: {{array}}";
519 let input = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"array": [1, 2, 3]});
520 let rendered = reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(template, &input);
521
522 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("Array: [1, 2, 3]", rendered.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
523 }
524
525 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
526 fn test_recursionrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_recursion().() {
527 let mut reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
528 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reg
529 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
530 "walk",
531 "(\
532 {{#each this}}\
533 {{#if @key}}{{@key}}{{else}}{{@index}}{{/if}}: \
534 {{this}} \
535 {{> walk this}}, \
536 {{/each}}\
537 )",
538 )
539 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
540
541 let input = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
542 "array": [42, {"wow": "cool"}, [[]]],
543 "object": { "a": { "b": "c", "d": ["e"] } },
544 "string": "hi"
545 });
546 let expected_output = "(\
547 array: [42, [object], [[]]] (\
548 0: 42 (), \
549 1: [object] (wow: cool (), ), \
550 2: [[]] (0: [] (), ), \
551 ), \
552 object: [object] (\
553 a: [object] (\
554 b: c (), \
555 d: [e] (0: e (), ), \
556 ), \
557 ), \
558 string: hi (), \
559 )";
560
561 let rendered = reg.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("walk", &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
562 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected_output, rendered);
563 }
564
565 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
566 fn test_strict_eachrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/test_strict_each().() {
567 let mut reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
568
569 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reg
570 .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{#each data}}{{/each}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({}))
571 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
572 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reg
573 .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{#each data}}{{/each}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"data": 24}))
574 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
575
576 reg.set_strict_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_strict_mode().(true);
577
578 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reg
579 .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{#each data}}{{/each}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({}))
580 .is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
581 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reg
582 .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{#each data}}{{/each}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"data": 24}))
583 .is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
584 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reg
585 .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{#each data}}{{else}}food{{/each}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({}))
586 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
587 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reg
588 .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{#each data}}{{else}}food{{/each}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"data": 24}))
589 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
590 }
591
592 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
593 fn newline_stripping_for_eachrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/test/newline_stripping_for_each().() {
594 let reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
595
596 let tpl = r#"<ul>
597 {{#each a}}
598 {{!-- comment --}}
599 <li>{{this}}</li>
600 {{/each}}
601 </ul>"#;
602 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
603 r#"<ul>
604 <li>0</li>
605 <li>1</li>
606 </ul>"#,
607 reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(tpl, &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"a": [0, 1]})).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
608 );
609 }
610 }