scaruby 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,92 +1,92 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'scaruby/core_ext'
4
-
5
- describe Hash do
6
-
7
- hash = {123 => 'abc', 234 => 'bcd', 345 => 'cde', 4 => 'd', 56 => 'ef', 7 => 'g', 89 => 'hi' }
8
-
9
- it 'has #contains' do
10
- hash.contains(123).should eq(true)
11
- hash.contains(999).should eq(false)
12
- end
13
- it 'has #count' do
14
- hash.count {|k,v| k.to_s.length >= 2 }.should eq(5)
15
- end
16
- it 'hash Map.empty' do
17
- Map.empty.should eq({})
18
- end
19
- it 'has #exists' do
20
- hash.exists {|k,v| k.to_s.length == 1 }.should eq(true)
21
- end
22
- it 'has #filter' do
23
- hash.filter {|k,v| k.to_s.length < 3 }.to_hash.size.should eq(4)
24
- end
25
- it 'has #filter_keys' do
26
- hash.filter_keys {|k| k.to_s.length < 3 }.to_hash.size.should eq(4)
27
- end
28
- it 'has #filter_not' do
29
- hash.filter_not {|k,v| k.to_s.length < 3 }.to_hash.to_s.should eq('{123=>"abc", 234=>"bcd", 345=>"cde"}')
30
- end
31
- it 'has #find' do
32
- # the already defined method is called
33
- #hash.find {|k,v| k.to_s.length == 2 }.get[1].should eq('ef')
34
- hash.find {|k,v| k.to_s.length == 2 }[1].should eq('ef')
35
- end
36
- it 'has #forall' do
37
- hash.forall {|k,v| k.to_s.length <= 3 }.should eq(true)
38
- hash.forall {|k,v| k.to_s.length >= 2 }.should eq(false)
39
- end
40
- it 'has #foreach' do
41
- hash.foreach do |k,v|
42
- hash.include?(k).should eq(true)
43
- end
44
- end
45
- it 'has #get_or_else' do
46
- hash.get_or_else(123, 'xxx').should eq('abc')
47
- hash.get_or_else(999, 'xxx').should eq('xxx')
48
- end
49
- it 'has #is_empty' do
50
- hash.is_empty.should eq(false)
51
- {}.is_empty.should eq(true)
52
- end
53
- it 'has #key_set' do
54
- hash.key_set.should eq(hash.keys)
55
- end
56
- it 'has #lift' do
57
- lifted = hash.lift
58
- lifted.apply(123).get.should eq('abc')
59
- lifted.apply(999).is_defined.should eq(false)
60
- lifted.call(123).get.should eq('abc')
61
- lifted.call(999).is_defined.should eq(false)
62
- end
63
- it 'has #map' do
64
- # the already defined method is called
65
- #new_map = hash.map {|k,v| [k+k,v] }.to_hash
66
- #new_map.include?(246).should eq(true)
67
- seq = hash.map {|k,v| [k+k,v] }
68
- seq.include?([246,'abc']).should eq(true)
69
- end
70
- it 'has #minus' do
71
- hash.minus(123,234,345).to_hash.should eq({4=>'d',56=>'ef',7=>'g',89=>'hi'})
72
- end
73
- it 'has #mk_string' do
74
- hash.mk_string().should eq('{123=>abc, 234=>bcd, 345=>cde, 4=>d, 56=>ef, 7=>g, 89=>hi}')
75
- end
76
- it 'has #non_empty' do
77
- hash.non_empty.should eq(true)
78
- {}.non_empty.should eq(false)
79
- end
80
- it 'has #plus' do
81
- {123=>'abc',234=>'bcd'}.plus([[345,'cde']]).to_hash.should eq({123=>'abc',234=>'bcd',345=>'cde'})
82
- end
83
- it 'has #updated' do
84
- {123=>'abc',234=>'bcd'}.updated(345,'cde').to_hash.should eq({123=>'abc',234=>'bcd',345=>'cde'})
85
- end
86
- it 'has #unzip' do
87
- unzipped = {123=>'abc',234=>'bcd'}.unzip.to_a
88
- unzipped[0].should eq([123,234])
89
- unzipped[1].should eq(['abc','bcd'])
90
- end
91
- end
92
-
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'scaruby/core_ext'
4
+
5
+ describe Hash do
6
+
7
+ hash = {123 => 'abc', 234 => 'bcd', 345 => 'cde', 4 => 'd', 56 => 'ef', 7 => 'g', 89 => 'hi'}
8
+
9
+ it 'has #contains' do
10
+ hash.contains(123).should eq(true)
11
+ hash.contains(999).should eq(false)
12
+ end
13
+ it 'has #count' do
14
+ hash.count { |k, v| k.to_s.length >= 2 }.should eq(5)
15
+ end
16
+ it 'hash Map.empty' do
17
+ Map.empty.should eq({})
18
+ end
19
+ it 'has #exists' do
20
+ hash.exists { |k, v| k.to_s.length == 1 }.should eq(true)
21
+ end
22
+ it 'has #filter' do
23
+ hash.filter { |k, v| k.to_s.length < 3 }.to_hash.size.should eq(4)
24
+ end
25
+ it 'has #filter_keys' do
26
+ hash.filter_keys { |k| k.to_s.length < 3 }.to_hash.size.should eq(4)
27
+ end
28
+ it 'has #filter_not' do
29
+ hash.filter_not { |k, v| k.to_s.length < 3 }.to_hash.to_s.should eq('{123=>"abc", 234=>"bcd", 345=>"cde"}')
30
+ end
31
+ it 'has #find' do
32
+ # the already defined method is called
33
+ #hash.find {|k,v| k.to_s.length == 2 }.get[1].should eq('ef')
34
+ hash.find { |k, v| k.to_s.length == 2 }[1].should eq('ef')
35
+ end
36
+ it 'has #forall' do
37
+ hash.forall { |k, v| k.to_s.length <= 3 }.should eq(true)
38
+ hash.forall { |k, v| k.to_s.length >= 2 }.should eq(false)
39
+ end
40
+ it 'has #foreach' do
41
+ hash.foreach do |k, v|
42
+ hash.include?(k).should eq(true)
43
+ end
44
+ end
45
+ it 'has #get_or_else' do
46
+ hash.get_or_else(123, 'xxx').should eq('abc')
47
+ hash.get_or_else(999, 'xxx').should eq('xxx')
48
+ end
49
+ it 'has #is_empty' do
50
+ hash.is_empty.should eq(false)
51
+ {}.is_empty.should eq(true)
52
+ end
53
+ it 'has #key_set' do
54
+ hash.key_set.should eq(hash.keys)
55
+ end
56
+ it 'has #lift' do
57
+ lifted = hash.lift
58
+ lifted.apply(123).get.should eq('abc')
59
+ lifted.apply(999).is_defined.should eq(false)
60
+ lifted.call(123).get.should eq('abc')
61
+ lifted.call(999).is_defined.should eq(false)
62
+ end
63
+ it 'has #map' do
64
+ # the already defined method is called
65
+ #new_map = hash.map {|k,v| [k+k,v] }.to_hash
66
+ #new_map.include?(246).should eq(true)
67
+ seq = hash.map { |k, v| [k+k, v] }
68
+ seq.include?([246, 'abc']).should eq(true)
69
+ end
70
+ it 'has #minus' do
71
+ hash.minus(123, 234, 345).to_hash.should eq({4 => 'd', 56 => 'ef', 7 => 'g', 89 => 'hi'})
72
+ end
73
+ it 'has #mk_string' do
74
+ hash.mk_string().should eq('{123=>abc, 234=>bcd, 345=>cde, 4=>d, 56=>ef, 7=>g, 89=>hi}')
75
+ end
76
+ it 'has #non_empty' do
77
+ hash.non_empty.should eq(true)
78
+ {}.non_empty.should eq(false)
79
+ end
80
+ it 'has #plus' do
81
+ {123 => 'abc', 234 => 'bcd'}.plus([[345, 'cde']]).to_hash.should eq({123 => 'abc', 234 => 'bcd', 345 => 'cde'})
82
+ end
83
+ it 'has #updated' do
84
+ {123 => 'abc', 234 => 'bcd'}.updated(345, 'cde').to_hash.should eq({123 => 'abc', 234 => 'bcd', 345 => 'cde'})
85
+ end
86
+ it 'has #unzip' do
87
+ unzipped = {123 => 'abc', 234 => 'bcd'}.unzip.to_a
88
+ unzipped[0].should eq([123, 234])
89
+ unzipped[1].should eq(['abc', 'bcd'])
90
+ end
91
+ end
92
+
@@ -1,56 +1,56 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'scaruby'
4
-
5
- describe Scaruby::IO::Source do
6
-
7
- http_url = 'http://seratch.github.com/'
8
- https_url = 'https://github.com/seratch/scaruby'
9
-
10
- it 'has from_file' do
11
- file = 'spec/scaruby_spec.rb'
12
- source = Source.from_file(file)
13
- source.to_seq.foreach do |c|
14
- line.is_a?(String).should eq(true)
15
- end
16
- lines = source.get_lines
17
- lines.is_a?(Enumerable).should eq(true)
18
- lines.foreach do |line|
19
- line.is_a?(String).should eq(true)
20
- end
21
- end
22
- it 'has from_bytes' do
23
- str = 'zzz 日本語を含む文字列 999'
24
- bytes = str.bytes.to_a
25
- source = Source.from_bytes(bytes)
26
- source.to_seq.foreach do |c|
27
- c.is_a?(String).should eq(true)
28
- end
29
- source.get_lines.mk_string.should eq(str)
30
- end
31
- it 'has from_url with a http url' do
32
- source = Source.from_url(http_url)
33
- source.to_seq.foreach do |c|
34
- c.is_a?(String).should eq(true)
35
- end
36
- end
37
- it 'has from_url with a https url' do
38
- source = Source.from_url(https_url)
39
- source.to_seq.foreach do |c|
40
- c.is_a?(String).should eq(true)
41
- end
42
- end
43
- it 'has #get_lines' do
44
- source = Source.from_url(http_url,'Shift_JIS')
45
- source.get_lines.foreach do |line|
46
- line.is_a?(String).should eq(true)
47
- end
48
- end
49
- it 'has #to_seq' do
50
- source = Source.from_url(http_url)
51
- source.to_seq.foreach do |c|
52
- c.is_a?(String).should eq(true)
53
- end
54
- end
55
-
56
- end
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'scaruby'
4
+
5
+ describe Scaruby::IO::Source do
6
+
7
+ http_url = 'http://seratch.github.com/'
8
+ https_url = 'https://github.com/seratch/scaruby'
9
+
10
+ it 'has from_file' do
11
+ file = 'spec/scaruby_spec.rb'
12
+ source = Source.from_file(file)
13
+ source.to_seq.foreach do |c|
14
+ line.is_a?(String).should eq(true)
15
+ end
16
+ lines = source.get_lines
17
+ lines.is_a?(Enumerable).should eq(true)
18
+ lines.foreach do |line|
19
+ line.is_a?(String).should eq(true)
20
+ end
21
+ end
22
+ it 'has from_bytes' do
23
+ str = 'zzz 日本語を含む文字列 999'
24
+ bytes = str.bytes.to_a
25
+ source = Source.from_bytes(bytes)
26
+ source.to_seq.foreach do |c|
27
+ c.is_a?(String).should eq(true)
28
+ end
29
+ source.get_lines.mk_string.should eq(str)
30
+ end
31
+ it 'has from_url with a http url' do
32
+ source = Source.from_url(http_url)
33
+ source.to_seq.foreach do |c|
34
+ c.is_a?(String).should eq(true)
35
+ end
36
+ end
37
+ it 'has from_url with a https url' do
38
+ source = Source.from_url(https_url)
39
+ source.to_seq.foreach do |c|
40
+ c.is_a?(String).should eq(true)
41
+ end
42
+ end
43
+ it 'has #get_lines' do
44
+ source = Source.from_url(http_url, 'UTF-8')
45
+ source.get_lines.foreach do |line|
46
+ line.is_a?(String).should eq(true)
47
+ end
48
+ end
49
+ it 'has #to_seq' do
50
+ source = Source.from_url(http_url)
51
+ source.to_seq.foreach do |c|
52
+ c.is_a?(String).should eq(true)
53
+ end
54
+ end
55
+
56
+ end
@@ -1,117 +1,117 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'scaruby'
4
-
5
- describe Map do
6
-
7
- hash = {123 => 'abc', 234 => 'bcd', 345 => 'cde', 4 => 'd', 56 => 'ef', 7 => 'g', 89 => 'hi' }
8
-
9
- it 'does not accept invalid args' do
10
- begin
11
- map = Map.new(1234)
12
- raise 'Expected exception did not be raised!'
13
- rescue AssertionError
14
- end
15
- end
16
-
17
- it 'has self.new' do
18
- map = Map.new({1 => 'a', 2 => 'b'})
19
- map.should_not eq(nil)
20
- end
21
-
22
- # as a sub type of Hash
23
- it 'has #each' do
24
- expected_key = 1
25
- expected_value = 10
26
- returned = Map.new({1=>10,2=>20}).each do |k,v|
27
- k.should eq(expected_key)
28
- v.should eq(expected_value)
29
- expected_key += 1
30
- expected_value += 10
31
- end
32
- returned.should eq(nil)
33
- end
34
-
35
- # defined
36
- it 'has #contains' do
37
- Map.new(hash).contains(123).should eq(true)
38
- Map.new(hash).contains(999).should eq(false)
39
- end
40
- it 'has #count' do
41
- Map.new(hash).count {|k,v| k.to_s.length >= 2 }.should eq(5)
42
- end
43
- it 'hash Map.empty' do
44
- Map.empty.should eq({})
45
- end
46
- it 'has #exists' do
47
- Map.new(hash).exists {|k,v| k.to_s.length == 1 }.should eq(true)
48
- end
49
- it 'has #filter' do
50
- Map.new(hash).filter {|k,v| k.to_s.length < 3 }.to_hash.size.should eq(4)
51
- end
52
- it 'has #filter_keys' do
53
- Map.new(hash).filter_keys {|k| k.to_s.length < 3 }.to_hash.size.should eq(4)
54
- end
55
- it 'has #filter_not' do
56
- Map.new(hash).filter_not {|k,v| k.to_s.length < 3 }.to_hash.to_s.should eq('{123=>"abc", 234=>"bcd", 345=>"cde"}')
57
- end
58
- it 'has #find' do
59
- Map.new(hash).find {|k,v| k.to_s.length == 2 }.get[1].should eq('ef')
60
- end
61
- it 'has #forall' do
62
- Map.new(hash).forall {|k,v| k.to_s.length <= 3 }.should eq(true)
63
- Map.new(hash).forall {|k,v| k.to_s.length >= 2 }.should eq(false)
64
- end
65
- it 'has #foreach' do
66
- returned = Map.new(hash).foreach do |k,v|
67
- hash.include?(k).should eq(true)
68
- end
69
- returned.should eq(nil)
70
- end
71
- it 'has #get_or_else' do
72
- Map.new(hash).get_or_else(123, 'xxx').should eq('abc')
73
- Map.new(hash).get_or_else(999, 'xxx').should eq('xxx')
74
- end
75
- it 'has #is_empty' do
76
- Map.new(hash).is_empty.should eq(false)
77
- Map.new({}).is_empty.should eq(true)
78
- Map.new(nil).is_empty.should eq(true)
79
- end
80
- it 'has #key_set' do
81
- Map.new(hash).key_set.should eq(hash.keys)
82
- end
83
- it 'has #lift' do
84
- lifted = Map.new(hash).lift
85
- lifted.apply(123).get.should eq('abc')
86
- lifted.apply(999).is_defined.should eq(false)
87
- lifted.call(123).get.should eq('abc')
88
- lifted.call(999).is_defined.should eq(false)
89
- end
90
- it 'has #map' do
91
- new_map = Map.new(hash).map {|k,v| [k+k,v] }.to_hash
92
- new_map.include?(246).should eq(true)
93
- end
94
- it 'has #minus' do
95
- Map.new(hash).minus(123,234,345).to_hash.should eq({4=>'d',56=>'ef',7=>'g',89=>'hi'})
96
- end
97
- it 'has #mk_string' do
98
- Map.new(hash).mk_string().should eq('{123=>abc, 234=>bcd, 345=>cde, 4=>d, 56=>ef, 7=>g, 89=>hi}')
99
- end
100
- it 'has #non_empty' do
101
- Map.new(hash).non_empty.should eq(true)
102
- Map.new({}).non_empty.should eq(false)
103
- Map.new(nil).non_empty.should eq(false)
104
- end
105
- it 'has #plus' do
106
- Map.new({123=>'abc',234=>'bcd'}).plus([[345,'cde']]).to_hash.should eq({123=>'abc',234=>'bcd',345=>'cde'})
107
- end
108
- it 'has #updated' do
109
- Map.new({123=>'abc',234=>'bcd'}).updated(345,'cde').to_hash.should eq({123=>'abc',234=>'bcd',345=>'cde'})
110
- end
111
- it 'has #unzip' do
112
- unzipped = Map.new({123=>'abc',234=>'bcd'}).unzip.to_a
113
- unzipped[0].should eq([123,234])
114
- unzipped[1].should eq(['abc','bcd'])
115
- end
116
- end
117
-
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'scaruby'
4
+
5
+ describe Map do
6
+
7
+ hash = {123 => 'abc', 234 => 'bcd', 345 => 'cde', 4 => 'd', 56 => 'ef', 7 => 'g', 89 => 'hi'}
8
+
9
+ it 'does not accept invalid args' do
10
+ begin
11
+ map = Map.new(1234)
12
+ raise 'Expected exception did not be raised!'
13
+ rescue AssertionError
14
+ end
15
+ end
16
+
17
+ it 'has self.new' do
18
+ map = Map.new({1 => 'a', 2 => 'b'})
19
+ map.should_not eq(nil)
20
+ end
21
+
22
+ # as a sub type of Hash
23
+ it 'has #each' do
24
+ expected_key = 1
25
+ expected_value = 10
26
+ returned = Map.new({1 => 10, 2 => 20}).each do |k, v|
27
+ k.should eq(expected_key)
28
+ v.should eq(expected_value)
29
+ expected_key += 1
30
+ expected_value += 10
31
+ end
32
+ returned.should eq(nil)
33
+ end
34
+
35
+ # defined
36
+ it 'has #contains' do
37
+ Map.new(hash).contains(123).should eq(true)
38
+ Map.new(hash).contains(999).should eq(false)
39
+ end
40
+ it 'has #count' do
41
+ Map.new(hash).count { |k, v| k.to_s.length >= 2 }.should eq(5)
42
+ end
43
+ it 'hash Map.empty' do
44
+ Map.empty.should eq({})
45
+ end
46
+ it 'has #exists' do
47
+ Map.new(hash).exists { |k, v| k.to_s.length == 1 }.should eq(true)
48
+ end
49
+ it 'has #filter' do
50
+ Map.new(hash).filter { |k, v| k.to_s.length < 3 }.to_hash.size.should eq(4)
51
+ end
52
+ it 'has #filter_keys' do
53
+ Map.new(hash).filter_keys { |k| k.to_s.length < 3 }.to_hash.size.should eq(4)
54
+ end
55
+ it 'has #filter_not' do
56
+ Map.new(hash).filter_not { |k, v| k.to_s.length < 3 }.to_hash.to_s.should eq('{123=>"abc", 234=>"bcd", 345=>"cde"}')
57
+ end
58
+ it 'has #find' do
59
+ Map.new(hash).find { |k, v| k.to_s.length == 2 }.get[1].should eq('ef')
60
+ end
61
+ it 'has #forall' do
62
+ Map.new(hash).forall { |k, v| k.to_s.length <= 3 }.should eq(true)
63
+ Map.new(hash).forall { |k, v| k.to_s.length >= 2 }.should eq(false)
64
+ end
65
+ it 'has #foreach' do
66
+ returned = Map.new(hash).foreach do |k, v|
67
+ hash.include?(k).should eq(true)
68
+ end
69
+ returned.should eq(nil)
70
+ end
71
+ it 'has #get_or_else' do
72
+ Map.new(hash).get_or_else(123, 'xxx').should eq('abc')
73
+ Map.new(hash).get_or_else(999, 'xxx').should eq('xxx')
74
+ end
75
+ it 'has #is_empty' do
76
+ Map.new(hash).is_empty.should eq(false)
77
+ Map.new({}).is_empty.should eq(true)
78
+ Map.new(nil).is_empty.should eq(true)
79
+ end
80
+ it 'has #key_set' do
81
+ Map.new(hash).key_set.should eq(hash.keys)
82
+ end
83
+ it 'has #lift' do
84
+ lifted = Map.new(hash).lift
85
+ lifted.apply(123).get.should eq('abc')
86
+ lifted.apply(999).is_defined.should eq(false)
87
+ lifted.call(123).get.should eq('abc')
88
+ lifted.call(999).is_defined.should eq(false)
89
+ end
90
+ it 'has #map' do
91
+ new_map = Map.new(hash).map { |k, v| [k+k, v] }.to_hash
92
+ new_map.include?(246).should eq(true)
93
+ end
94
+ it 'has #minus' do
95
+ Map.new(hash).minus(123, 234, 345).to_hash.should eq({4 => 'd', 56 => 'ef', 7 => 'g', 89 => 'hi'})
96
+ end
97
+ it 'has #mk_string' do
98
+ Map.new(hash).mk_string().should eq('{123=>abc, 234=>bcd, 345=>cde, 4=>d, 56=>ef, 7=>g, 89=>hi}')
99
+ end
100
+ it 'has #non_empty' do
101
+ Map.new(hash).non_empty.should eq(true)
102
+ Map.new({}).non_empty.should eq(false)
103
+ Map.new(nil).non_empty.should eq(false)
104
+ end
105
+ it 'has #plus' do
106
+ Map.new({123 => 'abc', 234 => 'bcd'}).plus([[345, 'cde']]).to_hash.should eq({123 => 'abc', 234 => 'bcd', 345 => 'cde'})
107
+ end
108
+ it 'has #updated' do
109
+ Map.new({123 => 'abc', 234 => 'bcd'}).updated(345, 'cde').to_hash.should eq({123 => 'abc', 234 => 'bcd', 345 => 'cde'})
110
+ end
111
+ it 'has #unzip' do
112
+ unzipped = Map.new({123 => 'abc', 234 => 'bcd'}).unzip.to_a
113
+ unzipped[0].should eq([123, 234])
114
+ unzipped[1].should eq(['abc', 'bcd'])
115
+ end
116
+ end
117
+
@@ -1,43 +1,50 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'scaruby'
4
-
5
- describe Option do
6
- it 'has self.new' do
7
- some = Option.new(123)
8
- some.is_defined.should eq(true)
9
- end
10
- it 'has #get and it works with Some' do
11
- some = Option.new(123)
12
- some.get.should eq(123)
13
- end
14
- it 'has #get and it works with None' do
15
- none = Option.new(nil)
16
- begin
17
- none.get
18
- violated "NoSuchElementException should be thorwn!"
19
- rescue Scaruby::NoSuchElementException => e
20
- end
21
- end
22
- it 'has #get_or_else and it works with Some' do
23
- some = Option.new(123)
24
- some.get_or_else(999).should eq(123)
25
- end
26
- it 'has #get_or_else and it works with None' do
27
- none = Option.new(nil)
28
- none.get_or_else(999).should eq(999)
29
- end
30
- it 'has #map and it works with Some' do
31
- some = Option.new(123)
32
- some_result = some.map {|v| v + v }
33
- some_result.get_or_else(999).should eq(246)
34
- end
35
- it 'has #map and it works with None' do
36
- none = Option.new(nil)
37
- none_result = none.map {|v| v + v }
38
- none_result.get_or_else(999).should eq(999)
39
- end
40
- end
41
-
42
-
43
-
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'scaruby'
4
+
5
+ describe Option do
6
+ it 'has self.new' do
7
+ some = Option.new(123)
8
+ some.is_defined.should eq(true)
9
+ some.is_empty.should eq(false)
10
+ end
11
+ it 'has #get and the method works with Some' do
12
+ some = Option.new(123)
13
+ some.get.should eq(123)
14
+ end
15
+ it 'has #get and the method works with None' do
16
+ none = Option.new(nil)
17
+ begin
18
+ none.get
19
+ violated "NoSuchElementException should be thorwn!"
20
+ rescue Scaruby::NoSuchElementException => e
21
+ end
22
+ end
23
+ it 'has #get_or_else and the method works with Some' do
24
+ some = Option.new(123)
25
+ some.get_or_else(999).should eq(123)
26
+ end
27
+ it 'has #get_or_else and the method works with None' do
28
+ none = Option.new(nil)
29
+ none.get_or_else(999).should eq(999)
30
+ end
31
+ it 'has #map and the method works with Some' do
32
+ some = Option.new(123)
33
+ some_result = some.map { |v| v + v }
34
+ some_result.get_or_else(999).should eq(246)
35
+ end
36
+ it 'has #map and the method works with None' do
37
+ none = Option.new(nil)
38
+ none_result = none.map { |v| v + v }
39
+ none_result.get_or_else(999).should eq(999)
40
+ end
41
+ it 'has #fold and the method works with Some' do
42
+ some = Option.new(123)
43
+ some.fold(999){ |v| v +v }.should eq(246)
44
+ end
45
+ it 'has #fold and the method works with None' do
46
+ none = Option.new(nil)
47
+ none.fold(999){ |v| v +v }.should eq(999)
48
+ end
49
+ end
50
+