Debian Codegraph @

doc/_includes/examples/arith.jsonnet

raw
1 {
2 concat_array: [1, 2, 3] + [4],
3 concat_string: '123' + 4,
4 equality1: 1 == '1',
5 equality2: [{}, { x: 3 - 1 }]
6 == [{}, { x: 2 }],
7 ex1: 1 + 2 * 3 / (4 + 5),
8 // Bitwise operations first cast to int.
9 ex2: self.ex1 | 3,
10 // Modulo operator.
11 ex3: self.ex1 % 2,
12 // Boolean logic
13 ex4: (4 > 3) && (1 <= 3) || false,
14 // Mixing objects together
15 obj: { a: 1, b: 2 } + { b: 3, c: 4 },
16 // Test if a field is in an object
17 obj_member: 'foo' in { foo: 1 },
18 // String formatting
19 str1: 'The value of self.ex2 is '
20 + self.ex2 + '.',
21 str2: 'The value of self.ex2 is %g.'
22 % self.ex2,
23 str3: 'ex1=%0.2f, ex2=%0.2f'
24 % [self.ex1, self.ex2],
25 // By passing self, we allow ex1 and ex2 to
26 // be extracted internally.
27 str4: 'ex1=%(ex1)0.2f, ex2=%(ex2)0.2f'
28 % self,
29 // Do textual templating of entire files:
30 str5: |||
31 ex1=%(ex1)0.2f
32 ex2=%(ex2)0.2f
33 ||| % self,
34 }