]>
git.proxmox.com Git - rustc.git/blob - vendor/tera/src/parser/tests/errors.rs
1 use crate :: parser
:: parse
;
3 fn assert_err_msg ( input
: & str , needles
: &[& str ]) {
4 let res
= parse ( input
);
6 let err
= res
. unwrap_err ();
7 let err_msg
= err
. to_string ();
8 println
!( " {} " , err_msg
);
9 println
!( "Looking for:" );
10 for needle
in needles
{
11 println
!( " {} " , needle
);
12 assert
!( err_msg
. contains ( needle
));
22 "expected `or`, `and`, `not`, `<=`, `>=`, `<`, `>`, `==`, `!=`, `+`, `-`, `*`, `/`, `%`, a filter, or a variable end (`}}`)"
29 assert_err_msg ( " {{ 1.2 >+ 3 } }" , &[ "1:9" , "expected an expression" ]);
33 fn wrong_start_block () {
38 "expected `or`, `and`, `not`, `<=`, `>=`, `<`, `>`, `==`, `!=`, `+`, `-`, `*`, `/`, `%`, a filter, or a variable end (`}}`)"
44 fn wrong_end_block () {
49 "expected an integer, a float, `true` or `false`, an identifier (must start with a-z), a dotted identifier (identifiers separated by `.`), a square bracketed identifier (identifiers separated by `.` or `[]`s), or an expression"
55 fn unterminated_variable_block () {
60 "expected `or`, `and`, `not`, `<=`, `>=`, `<`, `>`, `==`, `!=`, `+`, `-`, `*`, `/`, `%`, a filter, or a variable end (`}}`)"
66 fn unterminated_string () {
67 assert_err_msg ( r
# " {{ "hey } }" #, &[ "1:4" , "expected a value that can be negated" ]);
71 fn unterminated_if_tag () {
72 assert_err_msg ( r
# " {% if true %} sd" #, &[ "1:16" , r# "expected tag or some content" #]);
76 fn unterminated_filter_section () {
78 r
# " {% filter uppercase %} sd" #,
79 &[ "1:25" , r
# "expected tag or the filter section content" #],
84 fn invalid_filter_section_missing_name () {
86 r
# " {% filter %} sd {% endfilter %} " #,
87 &[ "1:11" , "expected an identifier (must start with a-z)" ],
92 fn invalid_macro_content () {
95 {% macro input(label, type) %}
100 &[ "3:5" , "unexpected tag; expected ` {% endmacro %} ` or the macro content" ],
105 fn invalid_macro_default_arg_value () {
108 {% macro input(label=something) %}
111 &[ "2:22" , "expected an integer, a float, a string, or `true` or `false`" ],
124 &[ "4:1" , "unexpected tag; expected an endif tag (` {% endif %} `) or some content" ],
137 &[ "4:1" , "unexpected tag; expected an endif tag (` {% endif %} `) or some content" ],
142 fn invalid_extends_position () {
146 {% extends "hey.html" %}
148 &[ "3:1" , "unexpected tag; expected end of input or some content" ],
153 fn invalid_operator () {
158 "expected `or`, `and`, `not`, `<=`, `>=`, `<`, `>`, `==`, `!=`, `+`, `-`, `*`, `/`, `%`, a filter, or a variable end (`}}`)"
164 fn missing_expression_with_not () {
165 assert_err_msg ( " {% if not %} " , &[ "1:11" , "expected an expression" ]);
169 fn missing_expression_in_if () {
170 assert_err_msg ( " {% if %} " , &[ "1:7" , "expected a value that can be negated" ]);
174 fn missing_container_name_in_forloop () {
175 assert_err_msg ( " {% for i in %} " , &[ "1:13" , "expected an expression or an array of values" ]);
179 fn missing_variable_name_in_set () {
180 assert_err_msg ( " {% set = 1 %} " , &[ "1:8" , "expected an identifier (must start with a-z)" ]);
184 fn missing_value_in_set () {
187 &[ "1:13" , "expected a value that can be negated or an array of values" ],
192 fn unterminated_fn_call () {
193 assert_err_msg ( " {{ a | slice( } }" , &[ "1:15" , "expected an identifier (must start with a-z)" ]);
197 fn invalid_fn_call_missing_value () {
199 " {{ a | slice(start=) } }" ,
200 &[ "1:20" , "expected a value that can be negated or an array of values" ],
205 fn unterminated_macro_call () {
206 assert_err_msg ( " {{ my::macro( } }" , &[ "1:15" , "expected an identifier (must start with a-z)" ]);
210 fn invalid_macro_call () {
215 "expected `or`, `and`, `not`, `<=`, `>=`, `<`, `>`, `==`, `!=`, `+`, `-`, `*`, `/`, `%`, a filter, or a variable end (`}}`)"
221 fn unterminated_include () {
222 assert_err_msg ( " {% include %} " , &[ "1:12" , "expected a string" ]);
226 fn invalid_include_no_string () {
227 assert_err_msg ( " {% include 1 %} " , &[ "1:12" , "expected a string" ]);
231 fn unterminated_extends () {
232 assert_err_msg ( " {% extends %} " , &[ "1:12" , "expected a string" ]);
236 fn invalid_extends_no_string () {
237 assert_err_msg ( " {% extends 1 %} " , &[ "1:12" , "expected a string" ]);
241 fn invalid_import_macros_missing_filename () {
242 assert_err_msg ( " {% import as macros %} " , &[ "1:11" , "expected a string" ]);
246 fn invalid_import_macros_missing_namespace () {
248 r
# " {% import "hello" as %} " #,
249 &[ "1:22" , "expected an identifier (must start with a-z)" ],
254 fn invalid_block_missing_name () {
255 assert_err_msg ( r
# " {% block %} " #, &[ "1:10" , "expected an identifier (must start with a-z)" ]);
259 fn unterminated_test () {
261 r
# " {% if a is odd( %} " #,
262 &[ "1:17" , "a test argument (any expressions including arrays)" ],
267 fn invalid_test_argument () {
269 r
# " {% if a is odd(key=1) %} " #,
272 "expected `or`, `and`, `not`, `<=`, `>=`, `<`, `>`, `==`, `!=`, `+`, `-`, `*`, `/`, `%`, or a filter"
278 fn unterminated_raw_tag () {
279 assert_err_msg ( r
# " {% raw %} sd" #, &[ "1:12" , "expected tag" ]);
283 fn invalid_break_outside_loop () {
284 assert_err_msg ( r
# " {% break %} " #, &[ "1:1" , " {% break %} " , "expected a template" ]);
288 fn invalid_continue_outside_loop () {
289 assert_err_msg ( r
# " {% continue %} " #, &[ "1:1" , " {% continue %} " , "expected a template" ]);