| 1 |
/* |
| 2 |
Copyright 2015 Google Inc. All rights reserved. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
{ |
| 18 |
concat_array: [1, 2, 3] + [4], |
| 19 |
concat_string: '123' + 4, |
| 20 |
equality1: 1 == '1', |
| 21 |
equality2: [{}, { x: 3 - 1 }] |
| 22 |
== [{}, { x: 2 }], |
| 23 |
ex1: 1 + 2 * 3 / (4 + 5), |
| 24 |
// Bitwise operations first cast to int. |
| 25 |
ex2: self.ex1 | 3, |
| 26 |
// Modulo operator. |
| 27 |
ex3: self.ex1 % 2, |
| 28 |
// Boolean logic |
| 29 |
ex4: (4 > 3) && (1 <= 3) || false, |
| 30 |
// Mixing objects together |
| 31 |
obj: { a: 1, b: 2 } + { b: 3, c: 4 }, |
| 32 |
// Test if a field is in an object |
| 33 |
obj_member: 'foo' in { foo: 1 }, |
| 34 |
// String formatting |
| 35 |
str1: 'The value of self.ex2 is ' |
| 36 |
+ self.ex2 + '.', |
| 37 |
str2: 'The value of self.ex2 is %g.' |
| 38 |
% self.ex2, |
| 39 |
str3: 'ex1=%0.2f, ex2=%0.2f' |
| 40 |
% [self.ex1, self.ex2], |
| 41 |
// By passing self, we allow ex1 and ex2 to |
| 42 |
// be extracted internally. |
| 43 |
str4: 'ex1=%(ex1)0.2f, ex2=%(ex2)0.2f' |
| 44 |
% self, |
| 45 |
// Do textual templating of entire files: |
| 46 |
str5: ||| |
| 47 |
ex1=%(ex1)0.2f |
| 48 |
ex2=%(ex2)0.2f |
| 49 |
||| % self, |
| 50 |
} |