This repository has been archived by the owner on Aug 18, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple implementation for working numeric array indexes.
- Loading branch information
Showing
3 changed files
with
63 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require File.expand_path(File.join(File.dirname(__FILE__), "/../../helper")) | ||
|
||
module Johnson | ||
module Conversions | ||
class ArrayTest < Johnson::TestCase | ||
def setup | ||
@context = Johnson::Context.new | ||
end | ||
|
||
def test_array_index_get | ||
@context[:list] = [1, 2, 3, 4] | ||
assert_equal(1, @context.evaluate("list[0]")) | ||
end | ||
|
||
def test_array_index_set | ||
@context[:list] = [] | ||
@context.evaluate("list[0] = 42") | ||
assert_equal(42, @context[:list][0]) | ||
end | ||
|
||
def test_array_works_with_for_in | ||
list = [1, 2, 3, 4] | ||
|
||
@context['alert'] = lambda { |x| p x } | ||
@context['list'] = list | ||
@context.evaluate(" | ||
var new_list = []; | ||
for(x in list) { | ||
new_list.push(x + 1); | ||
} | ||
") | ||
assert_equal(list.map { |x| x + 1}, @context['new_list'].to_a) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters