File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ local function array_generate__index(methods)
6868 end
6969end
7070
71- local function array__newindex (methods )
71+ local function array__newindex (self , index , value )
7272 array_safe_set (self , index - 1 , value )
7373end
7474
Original file line number Diff line number Diff line change 1+ local lu = require " luaunit"
2+
3+ local Test = {}
4+
5+ function Test :test_array_index ()
6+ local arr = Array (1 , 3.14 , ' hello!' )
7+ lu .assert_nil (arr [0 ])
8+ lu .assert_equals (1 , arr [1 ])
9+ lu .assert_equals (3.14 , arr [2 ])
10+ lu .assert_equals (String ' hello!' , arr [3 ])
11+ lu .assert_nil (arr [4 ])
12+ end
13+
14+ function Test :test_array_newindex ()
15+ local arr = Array ()
16+ arr [1 ] = 1
17+ arr [2 ] = ' 2'
18+
19+ lu .assert_equals (1 , arr [1 ])
20+ lu .assert_equals (String ' 2' , arr [2 ])
21+ lu .assert_equals (2 , # arr )
22+
23+ arr [1 ] = 2
24+ arr [2 ] = ' 3'
25+
26+ lu .assert_equals (2 , arr [1 ])
27+ lu .assert_equals (String ' 3' , arr [2 ])
28+ lu .assert_equals (2 , # arr )
29+ end
30+
31+ return Test
You can’t perform that action at this time.
0 commit comments