Debian Codegraph @

test_suite/oop_extra.jsonnet

raw
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 // Simple super
18 std.assertEqual(({ x: 0, y: self.x } + { x: 1, y: super.y }).y, 1) &&
19
20 // returning self
21 std.assertEqual(({ x: 0, y: self.x } + { x: 1, z: self }).z.y, 1) &&
22
23 // extending self on the right
24 std.assertEqual(({ x: 0, y: self.x } + { x: 1, z: (self + {}).y }).z, 1) &&
25 std.assertEqual(({ x: 0, y: self.x } + { x: 1, z: (self + {}) }).z.y, 1) &&
26
27 // extending self on the right has dynamic binding
28 std.assertEqual(({ x: 0, y: self.x } + { x: 2, z: (self + { x: 1 }).y }).z, 1) &&
29 std.assertEqual(({ x: 0, y: self.x } + { x: 2, z: (self + { x: 1 }) }).z.y, 1) &&
30
31 std.assertEqual(({ x: 0, y: self.x } + { x: 2, w: 1, z: (self + { x: super.w }).y }).z, 1) &&
32 std.assertEqual(({ x: 0, y: self.x } + { x: 2, w: 1, z: (self + { x: super.w }) }).z.y, 1) &&
33 std.assertEqual(({ x: 0, y: self.x } + { x: 2, w: 1, z: (self + { x: self.w }).y }).z, 1) &&
34 std.assertEqual(({ x: 0, y: self.x } + { x: 2, w: 1, z: (self + { x: self.w }) }).z.y, 1) &&
35
36 // self + self
37 std.assertEqual(({ x: 1, y: super.x } + { z: (self + self).y }).z, 1) &&
38
39 // extending self on the left
40 std.assertEqual(({ x: 0, y: self.x } + { x: 1, z: ({} + self).y }).z, 1) &&
41 std.assertEqual(({ x: 0, y: self.x } + { x: 1, z: ({} + self) }).z.y, 1) &&
42
43 std.assertEqual(({ x: 1, z: ({ x: 0, y: self.x } + self).y }).z, 1) &&
44 std.assertEqual(({ x: 1, z: ({ x: 0, y: self.x } + self) }).z.y, 1) &&
45
46 std.assertEqual(({ x: 0, z: ({ w: 1, x: 2, y: self.w } + self).y }).z, 1) &&
47 std.assertEqual(({ x: 0, z: ({ w: 1, x: 2, y: self.w } + self) }).z.y, 1) &&
48
49 std.assertEqual(({ x: 1, w: self.x, z: ({ x: 2, y: self.w } + self).y }).z, 1) &&
50 std.assertEqual(({ x: 1, w: self.x, z: ({ x: 2, y: self.w } + self) }).z.y, 1) &&
51
52
53 // extra
54
55 std.assertEqual({ a: ({ b: self.c, c: 1 } + self).b }.a, 1) &&
56
57 true