41 lines
1020 B
Plaintext
41 lines
1020 B
Plaintext
// This tests evaluating properties of objects.
|
|
|
|
|
|
obj = { foo = 1, bar = 0 }
|
|
|
|
// Test: the property is a literal.
|
|
|
|
|
|
one_a = obj["foo"]
|
|
|
|
assert(one_a, isLessThanOrEqual = 1, error = "Literal property lookup")
|
|
assert(one_a, isGreaterThanOrEqual = 1, error = "Literal property lookup")
|
|
|
|
// Test: the property is a variable,
|
|
// which must be evaluated before looking it up.
|
|
|
|
|
|
p = "foo"
|
|
one_b = obj[p]
|
|
|
|
assert(one_b, isLessThanOrEqual = 1, error = "Computed property lookup")
|
|
assert(one_b, isGreaterThanOrEqual = 1, error = "Computed property lookup")
|
|
|
|
// Test: multiple literal properties.
|
|
|
|
|
|
obj2 = { inner = obj }
|
|
|
|
one_c = obj2.inner["foo"]
|
|
|
|
assert(one_c, isLessThanOrEqual = 1, error = "Literal property lookup")
|
|
assert(one_c, isGreaterThanOrEqual = 1, error = "Literal property lookup")
|
|
|
|
// Test: multiple properties, mix of literal and computed.
|
|
|
|
|
|
one_d = obj2.inner[p]
|
|
|
|
assert(one_d, isLessThanOrEqual = 1, error = "Computed property lookup")
|
|
assert(one_d, isGreaterThanOrEqual = 1, error = "Computed property lookup")
|