mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 07:20:55 +00:00
Added range test case
This commit is contained in:
parent
e021e027ba
commit
7609f00c4b
@ -70,11 +70,11 @@ fn test_for_range() {
|
|||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(source = "{% for i in [1, 2, 3] %}{{ i }}{% endfor %}", ext = "txt")]
|
#[template(source = "{% for i in [1, 2, 3] %}{{ i }}{% endfor %}", ext = "txt")]
|
||||||
struct ForArrayTemplate {}
|
struct ForArrayTemplate;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_for_array() {
|
fn test_for_array() {
|
||||||
let t = ForArrayTemplate {};
|
let t = ForArrayTemplate;
|
||||||
assert_eq!(t.render().unwrap(), "123");
|
assert_eq!(t.render().unwrap(), "123");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,11 +83,11 @@ fn test_for_array() {
|
|||||||
source = "{% for i in [1, 2, 3].iter() %}{{ i }}{% endfor %}",
|
source = "{% for i in [1, 2, 3].iter() %}{{ i }}{% endfor %}",
|
||||||
ext = "txt"
|
ext = "txt"
|
||||||
)]
|
)]
|
||||||
struct ForMethodCallTemplate {}
|
struct ForMethodCallTemplate;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_for_method_call() {
|
fn test_for_method_call() {
|
||||||
let t = ForMethodCallTemplate {};
|
let t = ForMethodCallTemplate;
|
||||||
assert_eq!(t.render().unwrap(), "123");
|
assert_eq!(t.render().unwrap(), "123");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,10 +108,26 @@ fn test_for_path_call() {
|
|||||||
source = "{% for i in [1, 2, 3, 4, 5][3..] %}{{ i }}{% endfor %}",
|
source = "{% for i in [1, 2, 3, 4, 5][3..] %}{{ i }}{% endfor %}",
|
||||||
ext = "txt"
|
ext = "txt"
|
||||||
)]
|
)]
|
||||||
struct ForIndexTemplate {}
|
struct ForIndexTemplate;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_for_index() {
|
fn test_for_index() {
|
||||||
let t = ForIndexTemplate {};
|
let t = ForIndexTemplate;
|
||||||
assert_eq!(t.render().unwrap(), "45");
|
assert_eq!(t.render().unwrap(), "45");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(
|
||||||
|
source = "{% for (i, j) in (0..10).zip(10..20).zip(30..40) %}{{ i.0 }} {{ i.1 }} {{ j }} {% endfor %}",
|
||||||
|
ext = "txt"
|
||||||
|
)]
|
||||||
|
struct ForZipRangesTemplate;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_for_zip_ranges() {
|
||||||
|
let t = ForZipRangesTemplate;
|
||||||
|
assert_eq!(
|
||||||
|
t.render().unwrap(),
|
||||||
|
"0 10 30 1 11 31 2 12 32 3 13 33 4 14 34 5 15 35 6 16 36 7 17 37 8 18 38 9 19 39 "
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user