| 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 |
std.assertEqual({}, { assert true, assert true }) && |
| 18 |
std.assertEqual({}, { assert true, assert 1 == 1 }) && |
| 19 |
std.assertEqual({ assert true, assert 1 == 1 }, {}) && |
| 20 |
std.assertEqual({ assert 1 == 1 }, {}) && |
| 21 |
std.assertEqual({ assert true, f: 1 }.f, 1) && |
| 22 |
std.assertEqual({ assert self.f == 1, f: 1 }.f, 1) && |
| 23 |
std.assertEqual({ assert self.f == g, f: 1, local g = 1 }.f, 1) && |
| 24 |
|
| 25 |
local x = { assert x.f == y.f, f: 1 }, |
| 26 |
y = { assert x.f == y.f, f: 1 }; |
| 27 |
|
| 28 |
std.assertEqual(x.f, y.f) && |
| 29 |
|
| 30 |
|
| 31 |
local Mixin1 = { |
| 32 |
assert self.x > 0, |
| 33 |
x: super.x, |
| 34 |
}; |
| 35 |
|
| 36 |
std.assertEqual({ x: 1 } + Mixin1, { x: 1 }) && |
| 37 |
|
| 38 |
local Mixin2 = { |
| 39 |
assert self.x > super.x, |
| 40 |
x+: self.increment, |
| 41 |
increment:: 1, |
| 42 |
}; |
| 43 |
|
| 44 |
std.assertEqual({ x: 1 } + Mixin2, { x: 2 }) && |
| 45 |
|
| 46 |
local Template = { |
| 47 |
assert self == output, |
| 48 |
local template = self, |
| 49 |
local output = { |
| 50 |
str: '%d %d' % [template.x, template.y], |
| 51 |
}, |
| 52 |
x:: error 'Must set x', |
| 53 |
y:: error 'Must set y', |
| 54 |
|
| 55 |
str: output.str, |
| 56 |
}; |
| 57 |
|
| 58 |
std.assertEqual(Template { x: 1, y: 2 }, { str: '1 2' }) && |
| 59 |
|
| 60 |
std.assertEqual(std.type({ assert false }), 'object') && |
| 61 |
|
| 62 |
std.assertEqual(std.length({ assert false }), 0) && |
| 63 |
|
| 64 |
std.assertEqual(std.objectHas({ assert false, f: 3 }, 'f'), true) && |
| 65 |
std.assertEqual(std.objectHas({ assert false, f: 3, g:: 3 }, 'g'), false) && |
| 66 |
std.assertEqual(std.objectHas({ assert false, f: 3, g:: 3 }, 'h'), false) && |
| 67 |
|
| 68 |
std.assertEqual(std.objectFields({ assert false, f: 3, g:: 3 }), ['f']) && |
| 69 |
|
| 70 |
std.assertEqual(std.objectHasAll({ assert false, f: 3 }, 'f'), true) && |
| 71 |
std.assertEqual(std.objectHasAll({ assert false, f: 3, g:: 3 }, 'g'), true) && |
| 72 |
std.assertEqual(std.objectHasAll({ assert false, f: 3, g:: 3 }, 'h'), false) && |
| 73 |
|
| 74 |
std.assertEqual(std.objectFieldsAll({ assert false, f: 3, g:: 3 }), ['f', 'g']) && |
| 75 |
|
| 76 |
true |