opal 0.3.43 → 0.3.44

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/CHANGELOG.md +19 -0
  2. data/README.md +1 -0
  3. data/Rakefile +29 -19
  4. data/examples/native/Gemfile +3 -0
  5. data/examples/native/README.md +17 -0
  6. data/examples/native/app/app.rb +38 -0
  7. data/examples/native/config.ru +8 -0
  8. data/examples/native/index.html.erb +12 -0
  9. data/lib/opal/lexer.rb +5 -1
  10. data/lib/opal/parser.rb +36 -10
  11. data/lib/opal/processor.rb +10 -9
  12. data/lib/opal/server.rb +17 -7
  13. data/lib/opal/target_scope.rb +2 -2
  14. data/lib/opal/version.rb +1 -1
  15. data/opal/opal-browser/script_loader.rb +8 -13
  16. data/opal/opal.rb +23 -5
  17. data/opal/opal/array.rb +128 -14
  18. data/opal/opal/boolean.rb +1 -1
  19. data/opal/opal/class.rb +92 -18
  20. data/opal/opal/enumerable.rb +90 -0
  21. data/opal/opal/error.rb +1 -1
  22. data/opal/opal/hash.rb +2 -2
  23. data/opal/opal/kernel.rb +3 -3
  24. data/opal/opal/numeric.rb +1 -1
  25. data/opal/opal/proc.rb +1 -1
  26. data/opal/opal/regexp.rb +31 -31
  27. data/opal/opal/runtime.js +181 -69
  28. data/opal/opal/string.rb +561 -40
  29. data/opal/opal/time.rb +1 -1
  30. data/opal/rbconfig.rb +17 -3
  31. data/opal/strscan.rb +41 -5
  32. data/spec/opal/class/new_spec.rb +27 -0
  33. data/spec/opal/native_spec.rb +127 -0
  34. data/spec/ospec/runner.rb +0 -2
  35. data/spec/parser/strscan/get_byte_spec.rb +29 -0
  36. data/spec/parser/strscan/skip_spec.rb +40 -0
  37. data/spec/rubyspec/core/array/each_spec.rb +1 -1
  38. data/spec/rubyspec/core/array/intersection_spec.rb +5 -0
  39. data/spec/rubyspec/core/array/max_spec.rb +32 -0
  40. data/spec/rubyspec/core/array/min_spec.rb +32 -0
  41. data/spec/rubyspec/core/array/minus_spec.rb +7 -5
  42. data/spec/rubyspec/core/array/multiply_spec.rb +1 -1
  43. data/spec/rubyspec/core/array/plus_spec.rb +1 -1
  44. data/spec/rubyspec/core/array/pop_spec.rb +1 -1
  45. data/spec/rubyspec/core/array/push_spec.rb +1 -1
  46. data/spec/rubyspec/core/array/rassoc_spec.rb +1 -1
  47. data/spec/rubyspec/core/array/reject_spec.rb +2 -2
  48. data/spec/rubyspec/core/array/reverse_each_spec.rb +2 -2
  49. data/spec/rubyspec/core/array/rindex_spec.rb +2 -2
  50. data/spec/rubyspec/core/array/select_spec.rb +1 -1
  51. data/spec/rubyspec/core/array/shift_spec.rb +1 -1
  52. data/spec/rubyspec/core/array/slice_spec.rb +1 -1
  53. data/spec/rubyspec/core/array/sort_spec.rb +15 -15
  54. data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
  55. data/spec/rubyspec/core/array/to_ary_spec.rb +1 -1
  56. data/spec/rubyspec/core/array/uniq_spec.rb +1 -1
  57. data/spec/rubyspec/core/array/unshift_spec.rb +1 -1
  58. data/spec/rubyspec/core/array/zip_spec.rb +1 -1
  59. data/spec/rubyspec/core/enumerable/select_spec.rb +4 -1
  60. data/spec/rubyspec/core/module/const_defined_spec.rb +86 -0
  61. data/spec/rubyspec/core/module/const_get_spec.rb +55 -3
  62. data/spec/rubyspec/core/module/const_set_spec.rb +2 -2
  63. data/spec/rubyspec/core/module/constants_spec.rb +49 -0
  64. data/spec/rubyspec/core/regexp/match_spec.rb +66 -1
  65. data/spec/rubyspec/core/string/center_spec.rb +71 -0
  66. data/spec/rubyspec/core/string/chomp_spec.rb +6 -1
  67. data/spec/rubyspec/core/string/clone_spec.rb +8 -0
  68. data/spec/rubyspec/core/string/dup_spec.rb +8 -0
  69. data/spec/rubyspec/core/string/end_with_spec.rb +5 -1
  70. data/spec/rubyspec/core/string/gsub_spec.rb +15 -1
  71. data/spec/rubyspec/core/string/lines_spec.rb +9 -0
  72. data/spec/rubyspec/core/string/ljust_spec.rb +17 -0
  73. data/spec/rubyspec/core/string/match_spec.rb +25 -3
  74. data/spec/rubyspec/core/string/rindex_spec.rb +50 -0
  75. data/spec/rubyspec/core/string/rjust_spec.rb +17 -0
  76. data/spec/rubyspec/core/string/scan_spec.rb +66 -0
  77. data/spec/rubyspec/core/string/sub_spec.rb +17 -1
  78. data/spec/rubyspec/core/string/tr_s_spec.rb +31 -0
  79. data/spec/rubyspec/core/string/tr_spec.rb +31 -0
  80. data/spec/rubyspec/fixtures/constants.rb +6 -0
  81. data/spec/rubyspec/language/class_spec.rb +4 -8
  82. data/spec/rubyspec/language/numbers_spec.rb +10 -4
  83. data/spec/rubyspec/language/predefined_spec.rb +69 -2
  84. data/spec/rubyspec/library/rbconfig/config_spec.rb +47 -0
  85. data/spec/rubyspec/spec_helper.rb +6 -0
  86. metadata +46 -25
  87. data/opal/opal-eventable.rb +0 -26
  88. data/opal/opal/native.rb +0 -115
  89. data/spec/opal/eventable_spec.rb +0 -75
  90. data/spec/opal/native/element_reference_spec.rb +0 -40
  91. data/spec/opal/native/equal_spec.rb +0 -17
  92. data/spec/opal/native/fixtures/classes.rb +0 -27
  93. data/spec/opal/native/global_spec.rb +0 -12
  94. data/spec/opal/native/initialize_spec.rb +0 -8
  95. data/spec/opal/native/method_missing_spec.rb +0 -53
  96. data/spec/opal/native/to_native_spec.rb +0 -8
  97. data/spec/rubyspec/core/string/demodulize_spec.rb +0 -10
  98. data/spec/rubyspec/core/string/underscore_spec.rb +0 -17
@@ -1,7 +1,6 @@
1
1
  require File.expand_path('../../../spec_helper', __FILE__)
2
2
  require File.expand_path('../../../fixtures/constants', __FILE__)
3
3
 
4
-
5
4
  module ConstantSpecs
6
5
  end
7
6
 
@@ -37,7 +36,8 @@ describe "Module#const_set" do
37
36
  lambda { ConstantSpecs.const_set "::Name", 1 }.should raise_error(NameError)
38
37
  end
39
38
 
40
- it "raises a NameError if the name contains non-alphabetic characters except '_'" do
39
+ it "raises a NameError if the name contains non-word characters" do
40
+ # underscore (i.e., _) is a valid word character
41
41
  ConstantSpecs.const_set("CS_CONST404", :const404).should == :const404
42
42
  lambda { ConstantSpecs.const_set "Name=", 1 }.should raise_error(NameError)
43
43
  lambda { ConstantSpecs.const_set "Name?", 1 }.should raise_error(NameError)
@@ -0,0 +1,49 @@
1
+ module ConstantsSpecsModule
2
+ MOD_CONST1 = "1"
3
+ MOD_CONST2 = "2"
4
+ MOD_CONST3 = "3"
5
+
6
+ module Foo
7
+ FOO = "foo"
8
+ end
9
+ end
10
+
11
+ class ConstantsSpecsClass
12
+ CLASS_CONST1 = "1"
13
+ CLASS_CONST2 = "2"
14
+ CLASS_CONST3 = "3"
15
+ end
16
+
17
+ class SubConstantsSpecsClass < ConstantsSpecsClass
18
+ CLASS_CONST4 = "4"
19
+ end
20
+
21
+ describe "Module#constants" do
22
+ it "should return constants in global scope when called from Module or Class" do
23
+ result = Module.constants
24
+ result.should include("Module", "Object", "TrueClass", "FalseClass", "RUBY_ENGINE")
25
+ result2 = Class.constants
26
+ result.should == result2
27
+ end
28
+
29
+ it "should only return constants and child modules defined directly on module" do
30
+ result = ConstantsSpecsModule.constants
31
+ result.size.should == 4
32
+ result.should include("MOD_CONST1", "MOD_CONST2", "MOD_CONST3", "Foo")
33
+ result = ConstantsSpecsModule::Foo.constants
34
+ result.size.should == 1
35
+ result.should include("FOO")
36
+ end
37
+
38
+ it "should only return constants defined directly on class" do
39
+ result = ConstantsSpecsClass.constants
40
+ result.size.should == 3
41
+ result.should include("CLASS_CONST1", "CLASS_CONST2", "CLASS_CONST3")
42
+ end
43
+
44
+ it "should include constants inherited from superclass" do
45
+ result = SubConstantsSpecsClass.constants
46
+ result.size.should == 4
47
+ result.should include("ClASS_CONST4", "CLASS_CONST1", "CLASS_CONST2", "CLASS_CONST3")
48
+ end
49
+ end
@@ -17,6 +17,71 @@ describe "Regexp#match on a successful match" do
17
17
  /1/.match(nil)
18
18
  $~.should be_nil
19
19
  end
20
+
21
+ it "returns a MatchData object that exposes pre_match and post_match strings for inline regexp" do
22
+ re = /note: /i
23
+ result = re.match('preamble NOTE: This is just a test.')
24
+ result.pre_match.should == 'preamble '
25
+ result.post_match.should == 'This is just a test.'
26
+ end
27
+
28
+ it "returns a MatchData object that exposes pre_match and post_match strings for constructed regexp" do
29
+ re = Regexp.new(/note: /i)
30
+ result = re.match('preamble NOTE: This is just a test.')
31
+ result.pre_match.should == 'preamble '
32
+ result.post_match.should == 'This is just a test.'
33
+ end
34
+
35
+ it "sets $` and $' variables on match" do
36
+ re = /note: /i
37
+ re.match('preamble NOTE: This is just a test.')
38
+ $`.should == 'preamble '
39
+ $'.should == 'This is just a test.'
40
+ end
41
+
42
+ it "resets $` and $' when no match" do
43
+ re = /note: /i
44
+ re.match('preamble NOTE: This is just a test.')
45
+ $`.should_not be_nil
46
+ $'.should_not be_nil
47
+ re.match(nil)
48
+ $`.should be_nil
49
+ $'.should be_nil
50
+ end
51
+
52
+ it "returns a MatchData object that exposes match array" do
53
+ re = /(note): (.*)/i
54
+ result = re.match('preamble NOTE: This is just a test.')
55
+ result.length.should == 3
56
+ result.size.should == 3
57
+ result.captures.should == ['NOTE', 'This is just a test.']
58
+ result.to_a.should == ['NOTE: This is just a test.', 'NOTE', 'This is just a test.']
59
+ result[1].should == ['NOTE']
60
+ result.values_at(1, -1).should == ['NOTE', 'This is just a test.']
61
+ result.values_at(-3, 0).should == [nil, 'NOTE: This is just a test.']
62
+ end
63
+
64
+ it "replaces undefined with nil in match array" do
65
+ re = /(a(b)c)?(def)/
66
+ result = re.match("def")
67
+ result.to_a.size.should == 4
68
+ result.to_a.should == ["def", nil, nil, "def"]
69
+ end
70
+
71
+ it "returns a MatchData object that exposes regexp and string" do
72
+ re = /(note): (.*)/i
73
+ result = re.match('preamble NOTE: This is just a test.')
74
+ result.string.should == 'preamble NOTE: This is just a test.'
75
+ result.regexp.to_s.should == re.to_s
76
+ end
77
+
78
+ it "returns a MatchData object that provides access to offset of 0th element only" do
79
+ re = /(note): (.*)/i
80
+ result = re.match('preamble NOTE: This is just a test.')
81
+ result.begin(0).should == 9
82
+ result.begin(1).should == 9
83
+ lambda { result.begin(2) }.should raise_error(ArgumentError)
84
+ end
20
85
  end
21
86
 
22
87
  describe :regexp_match do
@@ -27,4 +92,4 @@ describe :regexp_match do
27
92
  it "returns nil if the object is nil" do
28
93
  /xyz/.match(nil).should be_nil
29
94
  end
30
- end
95
+ end
@@ -0,0 +1,71 @@
1
+ describe "String#center" do
2
+
3
+ it "does nothing if the specified width is lower than the string's size" do
4
+ "abc".center(2).should == "abc"
5
+ end
6
+
7
+ it "center a string with a strange pattern" do
8
+ "ab".center(17, '12345').should == "1234512ab12345123"
9
+ end
10
+
11
+ describe "centers an odd string with a odd number of padding strings" do
12
+ it "uses default padding" do
13
+ "abc".center(5).should == " abc "
14
+ end
15
+
16
+ it "uses a custum padding" do
17
+ "abc".center(5, '-').should == "-abc-"
18
+ end
19
+
20
+ it "works with bigger patterns" do
21
+ "abc".center(7, '~!{').should == "~!abc~!"
22
+ end
23
+
24
+ it "repeats the pattern if needed" do
25
+ "abc".center(10, '~!{').should == "~!{abc~!{~"
26
+ end
27
+ end
28
+
29
+ describe "centers an even string with an odd number of padding strings" do
30
+ it "uses default padding" do
31
+ "abcd".center(7).should == " abcd "
32
+ end
33
+
34
+ it "works with bigger patterns" do
35
+ "abcd".center(7, '~!{').should == "~abcd~!"
36
+ end
37
+
38
+ it "repeats the pattern if needed" do
39
+ "abcd".center(11, '~!{').should == "~!{abcd~!{~"
40
+ end
41
+ end
42
+
43
+ describe "centers an even string with an even number of padding strings" do
44
+ it "uses default padding" do
45
+ "abcd".center(8).should == " abcd "
46
+ end
47
+
48
+ it "works with bigger patterns" do
49
+ "abcd".center(8, '~!{').should == "~!abcd~!"
50
+ end
51
+
52
+ it "repeats the pattern if needed" do
53
+ "abcd".center(12, '~!{').should == "~!{~abcd~!{~"
54
+ end
55
+ end
56
+
57
+ describe "center an odd string with an even number" do
58
+ it "uses default padding" do
59
+ "abc".center(4).should == "abc "
60
+ end
61
+
62
+ it "works with bigger patterns" do
63
+ "abc".center(4, '~!{').should == "abc~"
64
+ end
65
+
66
+ it "repeats the pattern if needed" do
67
+ "abc".center(12, '~!{').should == "~!{~abc~!{~!"
68
+ end
69
+ end
70
+
71
+ end
@@ -30,6 +30,11 @@ describe "String#chomp with separator" do
30
30
  "hello\n\r\n".chomp("\r\n").should == "hello\n"
31
31
  end
32
32
 
33
+ it "removes separator character" do
34
+ "hello)".chomp(")").should == "hello"
35
+ "hello*)".chomp("*)").should == "hello"
36
+ end
37
+
33
38
  it "returns self if the separator is nil" do
34
39
  "hello\n\n".chomp(nil).should == "hello\n\n"
35
40
  end
@@ -40,4 +45,4 @@ describe "String#chomp with separator" do
40
45
  "".chomp("").should == ""
41
46
  "".chomp(nil).should == ""
42
47
  end
43
- end
48
+ end
@@ -0,0 +1,8 @@
1
+ describe "String#clone" do
2
+ it "produces a copy of the original" do
3
+ str = "a string"
4
+ str_copy = str.dup
5
+ str_copy.should == str
6
+ str_copy.object_id.should_not == str.object_id
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ describe "String#dup" do
2
+ it "produces a copy of the original" do
3
+ str = "a string"
4
+ str_copy = str.dup
5
+ str_copy.should == str
6
+ str_copy.object_id.should_not == str.object_id
7
+ end
8
+ end
@@ -9,4 +9,8 @@ describe "String#end_with?" do
9
9
  it "returns true only if any ending match" do
10
10
  "hello".end_with?('x', 'y', 'llo', 'z').should be_true
11
11
  end
12
- end
12
+
13
+ it "should not return true if suffix length is 1 greater than string length" do
14
+ "-".end_with?(' +').should be_false
15
+ end
16
+ end
@@ -14,4 +14,18 @@ describe "String#gsub with pattern and block" do
14
14
  "hello!".gsub(/(.)(.)/) { |*a| a.inspect }.should == '["he"]["ll"]["o!"]'
15
15
  "hello".gsub('l') { 'x'}.should == 'hexxo'
16
16
  end
17
- end
17
+
18
+ it "should set the global match variable $~ inside block" do
19
+ match_data = nil
20
+ "hello".gsub(/(.)(.)(.)(.)(.)/) { match_data = $~; $~[1] }.should == "h"
21
+ match_data.length.should == 6
22
+ match_data.should == ["hello", "h", "e", "l", "l", "o"]
23
+ end
24
+
25
+ it "should replace match group with undefined value with nil in match array" do
26
+ match_data = nil
27
+ "def".gsub(/(a(b)c)?d(e)f/) { match_data = $~; $~[3] }.should == "e"
28
+ match_data.length.should == 4
29
+ match_data.should == ["def", nil, nil, "e"]
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ describe "String#lines" do
2
+ pending "should split on the default record separator and return enumerator if not block is given" do
3
+ "first\nsecond\nthird".lines.class.should == Enumerator
4
+ "first\nsecond\nthird".lines.entries.class.should == Array
5
+ "first\nsecond\nthird".lines.entries.size.should == 3
6
+ "first\nsecond\nthird".lines.entries.should == ["first\n", "second\n", "third"]
7
+ "first\nsecond\nthird\n".lines.entries.should == ["first\n", "second\n", "third\n"]
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ describe "String#ljust" do
2
+ it "does nothing if the specified width is lower than the string's size" do
3
+ "abc".ljust(2).should == "abc"
4
+ end
5
+
6
+ it "uses default padding" do
7
+ "abc".ljust(5).should == " abc"
8
+ end
9
+
10
+ it "uses a custum padding" do
11
+ "abc".ljust(5, '-').should == "--abc"
12
+ end
13
+
14
+ it "uses wisely a bigger pattern" do
15
+ "abc".ljust(10, "123").should == "1231231abc"
16
+ end
17
+ end
@@ -1,10 +1,18 @@
1
1
  describe "String#=~" do
2
2
  it "sets $~ to MatchData when there is a match and nil then there's none" do
3
- 'hello' =~ /./
4
- $~[0].should == 'h'
3
+ 'hello' =~ /(l)(l)/
4
+ $~.should be_kind_of(MatchData)
5
+ $~[0].should == "ll"
6
+ $~.captures.should == ["l", "l"]
7
+ $~.pre_match.should == "he"
8
+ $`.should == "he"
9
+ $~.post_match.should == "o"
10
+ $'.should == "o"
5
11
 
6
12
  'hello' =~ /not/
7
13
  $~.should == nil
14
+ $`.should == nil
15
+ $'.should == nil
8
16
  end
9
17
  end
10
18
 
@@ -24,4 +32,18 @@ describe "String#match" do
24
32
  'hello'.match(/X/)
25
33
  $~.should == nil
26
34
  end
27
- end
35
+
36
+ it "sets $` to pre_match and $' to post_match or nil when there is no match" do
37
+ result = 'hello'.match(/ll/)
38
+ $`.should == 'he'
39
+ $'.should == 'o'
40
+ result.pre_match.should == 'he'
41
+ result.post_match.should == 'o'
42
+
43
+ 'hello'.match(/X/)
44
+ $`.should == nil
45
+ $'.should == nil
46
+ result.pre_match.should == 'he'
47
+ result.post_match.should == 'o'
48
+ end
49
+ end
@@ -0,0 +1,50 @@
1
+ describe "String#rindex" do
2
+ it "should return index of last occurrence of search string" do
3
+ "camal".rindex("a").should == 3
4
+ end
5
+
6
+ it "should return index of last occurrence of RegExp match" do
7
+ "camal".rindex(/a/).should == 3
8
+ end
9
+
10
+ it "should return nil if non-empty search is not found" do
11
+ "camal".rindex("x").should be_nil
12
+ end
13
+
14
+ it "should return nil if RegExp is not matched" do
15
+ "camal".rindex(/x/).should be_nil
16
+ end
17
+
18
+ it "should return 0 if string and search string are both empty" do
19
+ "".rindex("").should == 0
20
+ end
21
+
22
+ it "should return index of last occurrence of search string from offset" do
23
+ "camal".rindex("a", 1).should == 1
24
+ "camal".rindex(/a/, 4).should == 3
25
+ "camal".rindex("a", -4).should == 1
26
+ "camal".rindex("a", -2).should == 3
27
+ end
28
+
29
+ it "should return index of last occurrence of RegExp match from offset" do
30
+ "camal".rindex(/a/, 1).should == 1
31
+ "camal".rindex(/a/, 4).should == 3
32
+ "camal".rindex(/a/, -4).should == 1
33
+ "camal".rindex(/a/, -2).should == 3
34
+ end
35
+
36
+ it "should return nil of last occurrence is after offset" do
37
+ "camal".rindex("a", 0).should be_nil
38
+ "camal".rindex("a", -5).should be_nil
39
+ end
40
+
41
+ it "should return nil of last occurrence of RegExp match is after offset" do
42
+ "camal".rindex(/a/, 0).should be_nil
43
+ "camal".rindex(/a/, -5).should be_nil
44
+ end
45
+
46
+ it "should raise TypeError if search is not String or RegExp" do
47
+ lambda { "camal".rindex(nil) }.should raise_error(TypeError)
48
+ lambda { "camal".rindex(1) }.should raise_error(TypeError)
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ describe "String#rjust" do
2
+ it "does nothing if the specified width is lower than the string's size" do
3
+ "abc".rjust(2).should == "abc"
4
+ end
5
+
6
+ it "uses default padding" do
7
+ "abc".rjust(5).should == "abc "
8
+ end
9
+
10
+ it "uses a custum padding" do
11
+ "abc".rjust(5, '-').should == "abc--"
12
+ end
13
+
14
+ it "uses wisely a bigger pattern" do
15
+ "abc".rjust(10, "123").should == "abc1231231"
16
+ end
17
+ end
@@ -0,0 +1,66 @@
1
+ describe "String#scan" do
2
+ VOWELS_RE_NO_CAPTURE = /[aeiou]/
3
+ VOWELS_RE_CAPTURE = /([aeiou])/
4
+ it "should create one-dimensional array of matches if pattern has no capture groups" do
5
+ result = "string-a-long".scan(VOWELS_RE_NO_CAPTURE)
6
+ result.should be_kind_of(Array)
7
+ result.size.should == 3
8
+ result.should == ["i", "a", "o"]
9
+ end
10
+
11
+ it "should create two-dimensional array of matches if pattern has capture groups" do
12
+ result = "string-a-long".scan(VOWELS_RE_CAPTURE)
13
+ result.should be_kind_of(Array)
14
+ result.size.should == 3
15
+ result.should == [["i"], ["a"], ["o"]]
16
+ end
17
+
18
+ it "should set implicit match variables to final match when no block" do
19
+ result = "string-a-long".scan(VOWELS_RE_CAPTURE)
20
+ $~.should be_kind_of(MatchData)
21
+ $~.size.should == 2
22
+ $~[0].should == "o"
23
+ $~[1].should == "o"
24
+ $`.should == "string-a-l"
25
+ $~.pre_match.should == "string-a-l"
26
+ $'.should == "ng"
27
+ $~.post_match == "ng"
28
+ result.should == [["i"], ["a"], ["o"]]
29
+ end
30
+
31
+ it "should set implicit match variables for each iteration of block" do
32
+ iterations = 0
33
+ vals = {
34
+ :match_data => [],
35
+ :capture1 => [],
36
+ :pre_match => [],
37
+ :post_match => []
38
+ }
39
+
40
+ result = "string-a-long".scan(VOWELS_RE_CAPTURE) do |capture1|
41
+ iterations += 1
42
+ vals[:match_data] << $~
43
+ vals[:capture1] << capture1
44
+ vals[:pre_match] << $`
45
+ vals[:post_match] << $'
46
+ end
47
+
48
+ iterations.should == 3
49
+ vals[:capture1].should == ["i", "a", "o"]
50
+ vals[:pre_match].should == ["str", "string-", "string-a-l"]
51
+ vals[:post_match].should == ["ng-a-long", "-long", "ng"]
52
+ vals[:match_data][0][0].should == "i"
53
+ vals[:match_data][1][0].should == "a"
54
+ vals[:match_data][2][0].should == "o"
55
+ result.should == "string-a-long"
56
+ end
57
+
58
+ # this verifies that the lastIndex is reset before using the regexp
59
+ it "should get same matches on consecutive runs" do
60
+ re = Regexp.new('[aeiou]', 'g')
61
+ results1 = 'hello'.scan(re)
62
+ results2 = 'hello'.scan(re)
63
+ results1.should == ["e", "o"]
64
+ results2.should == results1
65
+ end
66
+ end