44 # https://doc.rust-lang.org/std/option/enum.Option.html
55
66 it "new" do
7- expect { Some . new ( nil ) } . to raise_error Rs ::Option ::ArgumentError , "Some value cannot be nil"
7+ expect { Some [ nil ] { } } . to raise_error Rs ::Option ::TypeError
8+ expect { Some [ NilClass ] { nil } } . to raise_error Rs ::Option ::TypeNilClass
9+ expect { Some [ Integer ] { nil } } . to raise_error Rs ::Option ::TypeMismatch
10+ expect { Some . new ( nil ) } . to raise_error Rs ::Option ::WrapNil
11+
12+ expect { None [ nil ] } . to raise_error Rs ::Option ::TypeError
13+ expect { None [ NilClass ] } . to raise_error Rs ::Option ::TypeNilClass
14+ expect { None . new ( nil ) } . to raise_error Rs ::Option ::TypeError
15+ expect { None . new ( NilClass ) } . to raise_error Rs ::Option ::TypeNilClass
16+
17+ x = Some . new ( 2 )
18+ y = Some [ Integer ] { 2 }
19+ expect ( x ) . to eq y
20+
21+ x = None . new ( Integer )
22+ y = None [ Integer ]
23+ expect ( x ) . to eq y
24+
25+ x = None . new
26+ y = None [ Class ]
27+ expect ( x ) . to eq y
828 end
929
10- it "some? " do
30+ it "is_some " do
1131 x = Some . new ( 2 )
12- expect ( x . some? ) . to be true
32+ expect ( x . is_some ) . to be true
1333
1434 x = None . new
15- expect ( x . some? ) . to be false
35+ expect ( x . is_some ) . to be false
1636 end
1737
18- it "some_and proc" do
38+ it "is_some_and proc" do
1939 x = Some . new ( 2 )
20- expect ( x . some_and ) . to be true
21- expect ( x . some_and { |x | x > 1 } ) . to be true
40+ expect ( x . is_some_and { |x | x > 1 } ) . to be true
2241
2342 x = Some . new ( 0 )
24- expect ( x . some_and { |x | x > 1 } ) . to be false
43+ expect ( x . is_some_and { |x | x > 1 } ) . to be false
2544
2645 x = None . new
27- expect ( x . some_and { |x | x . to_i > 1 } ) . to be false
46+ expect ( x . is_some_and { |x | x . to_i > 1 } ) . to be false
2847
2948 x = Some . new ( "str" )
30- expect ( x . some_and { |x | x . size > 1 } ) . to be true
49+ expect ( x . is_some_and { |x | x . size > 1 } ) . to be true
3150 end
3251
33- it "none? " do
52+ it "is_none " do
3453 x = Some . new ( 2 )
35- expect ( x . none? ) . to be false
54+ expect ( x . is_none ) . to be false
3655
3756 x = None . new
38- expect ( x . none? ) . to be true
57+ expect ( x . is_none ) . to be true
3958 end
4059
41- it "none_or proc" do
60+ it "is_none_or proc" do
4261 x = Some . new ( 2 )
43- expect ( x . none_or ) . to be false
44- expect ( x . none_or { |x | x > 1 } ) . to be true
62+ expect ( x . is_none_or { |x | x > 1 } ) . to be true
4563
4664 x = Some . new ( 0 )
47- expect ( x . none_or { |x | x > 1 } ) . to be false
65+ expect ( x . is_none_or { |x | x > 1 } ) . to be false
4866
4967 x = None . new
50- expect ( x . none_or { |x | x . to_i > 1 } ) . to be true
68+ expect ( x . is_none_or { |x | x . to_i > 1 } ) . to be true
5169
5270 x = Some . new ( "str" )
53- expect ( x . none_or { |x | x . size > 1 } ) . to be true
71+ expect ( x . is_none_or { |x | x . size > 1 } ) . to be true
5472 end
5573
5674 it "unwrap" do
6684 expect ( None . new . unwrap_or ( "bike" ) ) . to eq "bike"
6785 end
6886
69- it "unwrap_or proc" do
70- k = 10
71- expect ( Some . new ( 4 ) . unwrap_or { 2 * k } ) . to eq 4
72- expect ( None . new . unwrap_or { 2 * k } ) . to eq 20
73- end
74-
7587 it "unwrap_or_else proc" do
7688 k = 10
7789 expect ( Some . new ( 4 ) . unwrap_or_else { 2 * k } ) . to eq 4
8294 x = None . new
8395 y = Some . new ( 12 )
8496
85- expect ( x . unwrap_or ) . to be_nil
86- expect ( y . unwrap_or ) . to eq 12
97+ expect ( x . unwrap_or ( 0 ) ) . to eq 0
98+ expect ( y . unwrap_or ( 0 ) ) . to eq 12
8799 end
88100
89101 it "pattern_matching" do
@@ -108,7 +120,7 @@ def divide(numerator, denominator)
108120 it "type ==" do
109121 a = Some . new ( 1 )
110122 b = Some . new ( 1.0 )
111- c = Some . new ( 1.0 , type : Float )
123+ c = Some [ Float ] { 1.0 }
112124 d = Some . new ( "a" )
113125 e = None . new
114126
0 commit comments