2024-08-05 21:44:49 -05:00
|
|
|
// This tests evaluating properties of objects.
|
|
|
|
|
2024-11-04 20:34:22 -06:00
|
|
|
|
2024-11-25 09:21:55 +13:00
|
|
|
obj = { foo = 1, bar = 0 }
|
2024-08-05 21:44:49 -05:00
|
|
|
|
|
|
|
// Test: the property is a literal.
|
|
|
|
|
|
|
|
|
2024-11-04 20:34:22 -06:00
|
|
|
one_a = obj["foo"]
|
|
|
|
|
|
|
|
assertLessThanOrEq(one_a, 1, "Literal property lookup")
|
2024-08-05 21:44:49 -05:00
|
|
|
assertGreaterThanOrEq(one_a, 1, "Literal property lookup")
|
|
|
|
|
|
|
|
// Test: the property is a variable,
|
|
|
|
// which must be evaluated before looking it up.
|
|
|
|
|
|
|
|
|
2024-11-04 20:34:22 -06:00
|
|
|
p = "foo"
|
|
|
|
one_b = obj[p]
|
|
|
|
|
|
|
|
assertLessThanOrEq(one_b, 1, "Computed property lookup")
|
2024-08-05 21:44:49 -05:00
|
|
|
assertGreaterThanOrEq(one_b, 1, "Computed property lookup")
|
|
|
|
|
|
|
|
// Test: multiple literal properties.
|
|
|
|
|
|
|
|
|
2024-11-25 09:21:55 +13:00
|
|
|
obj2 = { inner = obj }
|
2024-08-05 21:44:49 -05:00
|
|
|
|
2024-11-04 20:34:22 -06:00
|
|
|
one_c = obj2.inner["foo"]
|
|
|
|
|
|
|
|
assertLessThanOrEq(one_c, 1, "Literal property lookup")
|
2024-08-05 21:44:49 -05:00
|
|
|
assertGreaterThanOrEq(one_c, 1, "Literal property lookup")
|
|
|
|
|
|
|
|
// Test: multiple properties, mix of literal and computed.
|
|
|
|
|
|
|
|
|
2024-11-04 20:34:22 -06:00
|
|
|
one_d = obj2.inner[p]
|
|
|
|
|
|
|
|
assertLessThanOrEq(one_d, 1, "Computed property lookup")
|
2024-08-05 21:44:49 -05:00
|
|
|
assertGreaterThanOrEq(one_d, 1, "Computed property lookup")
|