Skip to content

Commit 0bd3978

Browse files
author
Adrian Niculescu
committed
Added regression test for indexed access on non-NSArray collections
1 parent c210aa5 commit 0bd3978

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

TestRunner/app/tests/ApiTests.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ describe(module.id, function () {
2222
expect(res[0].constructor.name).toEqual("NSURL");
2323
});
2424

25+
it("indexed access works for non-NSArray indexable collections", function () {
26+
// NSOrderedSet is not an NSArray but responds to count + objectAtIndex:,
27+
// so obj[i] should resolve the same elements as objectAtIndex(i).
28+
const set = NSOrderedSet.orderedSetWithArray(['a', 'b', 'c']);
29+
expect(set.count).toBe(3);
30+
expect(set[0]).toBe(set.objectAtIndex(0));
31+
expect(set[1]).toBe(set.objectAtIndex(1));
32+
expect(set[2]).toBe(set.objectAtIndex(2));
33+
expect(set[0]).toBe('a');
34+
expect(set[2]).toBe('c');
35+
// Out-of-range index returns undefined instead of throwing.
36+
expect(set[3]).toBeUndefined();
37+
});
38+
2539
it("MethodCalledInDealloc", function () {
2640
expect(function () {
2741
(function () {

0 commit comments

Comments
 (0)