| 1 | use handlebarsrust-analyzer cargo handlebars 5.1.2 crate/::Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#; |
| 2 | use serde_jsonrust-analyzer cargo serde_json 1.0.114 crate/::jsonrust-analyzer cargo serde_json 1.0.114 macros/json!; |
| 3 | |
| 4 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5 | fn test_partial_with_blocksrust-analyzer cargo handlebars 5.1.2 test_partial_with_blocks().() { |
| 6 | let hbs = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 7 | |
| 8 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({ |
| 9 | "a": [ |
| 10 | {"b": 1}, |
| 11 | {"b": 2}, |
| 12 | ], |
| 13 | }); |
| 14 | |
| 15 | let template = "{{#*inline \"test\"}}{{b}};{{/inline}}{{#each a as |z|}}{{> test z}}{{/each}}"; |
| 16 | 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().(), "1;2;"); |
| 17 | } |
| 18 | |
| 19 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 20 | fn test_root_with_blocksrust-analyzer cargo handlebars 5.1.2 test_root_with_blocks().() { |
| 21 | let hbs = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 22 | |
| 23 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({ |
| 24 | "a": [ |
| 25 | {"b": 1}, |
| 26 | {"b": 2}, |
| 27 | ], |
| 28 | "b": 3, |
| 29 | }); |
| 30 | |
| 31 | let template = |
| 32 | "{{#*inline \"test\"}}{{b}}:{{@root.b}};{{/inline}}{{#each a}}{{> test}}{{/each}}"; |
| 33 | 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().(), "1:3;2:3;"); |
| 34 | } |
| 35 | |
| 36 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 37 | fn test_singular_and_pair_block_paramsrust-analyzer cargo handlebars 5.1.2 test_singular_and_pair_block_params().() { |
| 38 | let hbs = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 39 | |
| 40 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!([ |
| 41 | {"value": 11}, |
| 42 | {"value": 22}, |
| 43 | ]); |
| 44 | |
| 45 | let template = |
| 46 | "{{#each this as |b index|}}{{b.value}}{{#each this as |value key|}}:{{key}},{{/each}}{{/each}}"; |
| 47 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 48 | 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().(), |
| 49 | "11:value,22:value," |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 54 | fn test_nested_eachrust-analyzer cargo handlebars 5.1.2 test_nested_each().() { |
| 55 | let hbs = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 56 | |
| 57 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({ |
| 58 | "classes": [ |
| 59 | { |
| 60 | "methods": [ |
| 61 | {"id": 1}, |
| 62 | {"id": 2} |
| 63 | ] |
| 64 | }, |
| 65 | { |
| 66 | "methods": [ |
| 67 | {"id": 3}, |
| 68 | {"id": 4} |
| 69 | ] |
| 70 | }, |
| 71 | ], |
| 72 | }); |
| 73 | |
| 74 | let template = "{{#each classes as |class|}}{{#each class.methods as |method|}}{{method.id}};{{/each}}{{/each}}"; |
| 75 | 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().(), "1;2;3;4;"); |
| 76 | } |
| 77 | |
| 78 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 79 | fn test_referencing_block_param_from_upper_scoperust-analyzer cargo handlebars 5.1.2 test_referencing_block_param_from_upper_scope().() { |
| 80 | let hbs = Handlebarsrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 81 | |
| 82 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({ |
| 83 | "classes": [ |
| 84 | { |
| 85 | "methods": [ |
| 86 | {"id": 1}, |
| 87 | {"id": 2} |
| 88 | ], |
| 89 | "private": false |
| 90 | }, |
| 91 | { |
| 92 | "methods": [ |
| 93 | {"id": 3}, |
| 94 | {"id": 4} |
| 95 | ], |
| 96 | "private": true |
| 97 | }, |
| 98 | ], |
| 99 | }); |
| 100 | |
| 101 | let template = "{{#each classes as |class|}}{{#each class.methods as |method|}}{{class.private}}|{{method.id}};{{/each}}{{/each}}"; |
| 102 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 103 | 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().(), |
| 104 | "false|1;false|2;true|3;true|4;" |
| 105 | ); |
| 106 | } |