File tree Expand file tree Collapse file tree 4 files changed +32
-0
lines changed
test/end-to-end/__snapshots__/test_simple
test-data/recipes/jinja-types Expand file tree Collapse file tree 4 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -199,6 +199,28 @@ You can also check for the existence of an environment variable:
199
199
- ` ${{ env.exists("MY_ENV_VAR") }}` will return `true` if the environment
200
200
variable `MY_ENV_VAR` is set and `false` otherwise.
201
201
202
+ # # Tests
203
+
204
+ You can write tests using minijinja to check whether objects have certain properties.
205
+ The syntax for a filter is `{{ variable is test_name }}`.
206
+
207
+ - `undefined` : Check whether a variable is undefined.
208
+ - `defined` : Check whether a variable is defined.
209
+ - `none` : Check whether a variable is none.
210
+ - `safe` : Check whether a variable is safe.
211
+ - `escaped` : Check whether a variable is escaped. Same as `is safe`.
212
+ - `odd` : Check whether a number is odd.
213
+ - `even` : Check whether a number is even.
214
+ - `number` : Check whether a variable is a number.
215
+ - `integer` : Check whether a variable is an integer.
216
+ - `int` : Check whether a variable is an integer. Same as `is integer`.
217
+ - `float` : Check whether a variable is a float.
218
+ - `string` : Check whether a variable is a string.
219
+ - `sequence` : Check whether a variable is a sequence.
220
+ - `boolean` : Check whether a variable is a boolean.
221
+ - `startingwith` : Check whether a variable is starting with another string: `{{ python is startingwith('3.12') }}`
222
+ - `endingwith` : Check whether a variable is starting with another string: `{{ python is endingwith('.*') }}`
223
+
202
224
# # Filters
203
225
204
226
A feature of `jinja` is called "filters". Filters are functions that can be
Original file line number Diff line number Diff line change @@ -309,6 +309,8 @@ fn default_tests(env: &mut Environment) {
309
309
env. add_test ( "string" , minijinja:: tests:: is_string) ;
310
310
env. add_test ( "sequence" , minijinja:: tests:: is_sequence) ;
311
311
env. add_test ( "boolean" , minijinja:: tests:: is_boolean) ;
312
+ env. add_test ( "startingwith" , minijinja:: tests:: is_startingwith) ;
313
+ env. add_test ( "endingwith" , minijinja:: tests:: is_endingwith) ;
312
314
313
315
// operators
314
316
env. add_test ( "eq" , minijinja:: tests:: is_eq) ;
Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ context:
32
32
# quoted bool is quoted in variants.yaml and thus should be a string
33
33
is_quoted_true_var : ${{ quoted_bool is string }}
34
34
is_quoted_int_var : ${{ quoted_int is string }}
35
+ starting_with : ${{ xstring is startingwith('blah') }}
36
+ not_starting_with : ${{ xstring is startingwith('foo') }}
37
+ ending_with : ${{ xstring is startingwith('blah') }}
38
+ not_ending_with : ${{ xstring is startingwith('foo') }}
35
39
36
40
package :
37
41
name : testtypes
Original file line number Diff line number Diff line change 7
7
"cquoted" : " 5" ,
8
8
"cquoted_bool" : " true" ,
9
9
"cstring" : " blah" ,
10
+ "ending_with" : true ,
10
11
"float" : " 1.23" ,
11
12
"inline_list" : [
12
13
" a" ,
35
36
" b" ,
36
37
" c"
37
38
],
39
+ "not_ending_with" : false ,
40
+ "not_starting_with" : false ,
41
+ "starting_with" : true ,
38
42
"string" : " blah"
39
43
}
You can’t perform that action at this time.
0 commit comments