diff options
author | PizzasBear <43722034+PizzasBear@users.noreply.github.com> | 2023-11-22 17:09:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-22 16:09:33 +0100 |
commit | 696561003d9caaf5d1fd537d6a0f4f88fccca8ce (patch) | |
tree | 7e62fd238049cbf6a6e615b7e19ce6079a5b4cee /testing | |
parent | 48c6cd327d3c1df4218898be509250efcc56597c (diff) | |
download | askama-696561003d9caaf5d1fd537d6a0f4f88fccca8ce.tar.gz askama-696561003d9caaf5d1fd537d6a0f4f88fccca8ce.tar.bz2 askama-696561003d9caaf5d1fd537d6a0f4f88fccca8ce.zip |
Add better support for rust-like number literals (#908)
Signed-off-by: max <gmx.sht@gmail.com>
Diffstat (limited to 'testing')
-rw-r--r-- | testing/templates/num-literals.html | 11 | ||||
-rw-r--r-- | testing/tests/simple.rs | 23 |
2 files changed, 34 insertions, 0 deletions
diff --git a/testing/templates/num-literals.html b/testing/templates/num-literals.html new file mode 100644 index 0000000..90b07db --- /dev/null +++ b/testing/templates/num-literals.html @@ -0,0 +1,11 @@ +{% let plain_int = 9__0__ -%} +{% let neg_int = -9__0__isize -%} +{% let suffix_int = 9__0__i32 -%} +{% let bin_int = 0b__1__0__ -%} +{% let oct_int = 0o__7__0__ -%} +{% let hex_int = 0x__f__0__ -%} +{% let plain_float = 1__0__.5__0__ -%} +{% let suffix_float = 1__0__.5__0__f32 -%} +{% let exp_float = 1__0__e+__1__0__f32 -%} +{% let dotexp_float = 1__0__.5__0__e+__1__0__f32 -%} +[{{ plain_int }}, {{ neg_int }}, {{ suffix_int }}, {{ bin_int }}, {{ oct_int }}, {{ hex_int }}, {{ plain_float }}, {{ suffix_float }}, {{ exp_float }}, {{ dotexp_float }}] diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs index 627a8a3..f0f0a26 100644 --- a/testing/tests/simple.rs +++ b/testing/tests/simple.rs @@ -461,3 +461,26 @@ fn test_define_string_var() { let template = DefineStringVar; assert_eq!(template.render().unwrap(), ""); } + +#[derive(askama::Template)] +#[template(source = "{% let x = 4.5 %}{{ x }}", ext = "html")] +struct SimpleFloat; + +#[test] +fn test_simple_float() { + let template = SimpleFloat; + assert_eq!(template.render().unwrap(), "4.5"); +} + +#[derive(askama::Template)] +#[template(path = "num-literals.html")] +struct NumLiterals; + +#[test] +fn test_num_literals() { + let template = NumLiterals; + assert_eq!( + template.render().unwrap(), + "[90, -90, 90, 2, 56, 240, 10.5, 10.5, 100000000000, 105000000000]", + ); +} |