-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- v0.24.1
- 1.15.1
- 1.15.0
- 1.14.1
- 1.14.0
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.0
- 0.36.1
- 0.36.0
- 0.35.1
- 0.35.0
- 0.34.0
- 0.33.0
- 0.32.1
- 0.32.0
- 0.31.1
- 0.31.0
- 0.30.1
- 0.30.0
- 0.29.0
- 0.28.0
- 0.27.2
- 0.27.1
- 0.27.0
- 0.26.1
- 0.26.0
- 0.25.1
- 0.25.0
- 0.24.2
- 0.24.1
- 0.24.0
- 0.23.1
- 0.23.0
- 0.22.0
- 0.21.1
- 0.21.0
- 0.20.5
- 0.20.4
- 0.20.3
- 0.20.2
- 0.20.1
- 0.20.0
- 0.19.4
- 0.19.3
- 0.19.2
- 0.19.1
- 0.19.0
- 0.18.7
- 0.18.6
- 0.18.5
- 0.18.4
- 0.18.3
- 0.18.2
- 0.18.1
- 0.18.0
Showing
12 changed files
with
720 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,294 @@ | ||
require "spec" | ||
|
||
class StringWrapper | ||
delegate downcase, @string | ||
delegate upcase, capitalize, @string | ||
module ObjectSpec | ||
class StringWrapper | ||
delegate downcase, @string | ||
delegate upcase, capitalize, @string | ||
|
||
@string : String | ||
@string : String | ||
|
||
def initialize(@string) | ||
def initialize(@string) | ||
end | ||
end | ||
|
||
class TestObject | ||
getter getter1 | ||
getter getter2 : Int32 | ||
getter getter3 : Int32 = 3 | ||
getter getter4 = 4 | ||
|
||
getter! getter5 | ||
@getter5 : Int32? | ||
|
||
getter! getter6 : Int32 | ||
|
||
getter? getter7 | ||
getter? getter8 : Bool | ||
getter? getter9 : Bool = true | ||
getter? getter10 = true | ||
|
||
setter setter1 | ||
setter setter2 : Int32 | ||
setter setter3 : Int32 = 3 | ||
setter setter4 = 4 | ||
|
||
property property1 | ||
property property2 : Int32 | ||
property property3 : Int32 = 3 | ||
property property4 = 4 | ||
|
||
property! property5 | ||
@property5 : Int32? | ||
|
||
property! property6 : Int32 | ||
|
||
property? property7 | ||
property? property8 : Bool | ||
property? property9 : Bool = true | ||
property? property10 = true | ||
|
||
def initialize | ||
@getter1 = 1 | ||
@getter2 = 2 | ||
|
||
@getter7 = true | ||
@getter8 = true | ||
|
||
@setter1 = 1 | ||
@setter2 = 2 | ||
|
||
@property1 = 1 | ||
@property2 = 2 | ||
|
||
@property7 = true | ||
@property8 = true | ||
end | ||
|
||
def getter5=(@getter5) | ||
end | ||
|
||
def getter6=(@getter6) | ||
end | ||
|
||
def setter1 | ||
@setter1 | ||
end | ||
|
||
def setter2 | ||
@setter2 | ||
end | ||
|
||
def setter3 | ||
@setter3 | ||
end | ||
|
||
def setter4 | ||
@setter4 | ||
end | ||
end | ||
end | ||
|
||
describe "Object" do | ||
describe Object do | ||
describe "delegate" do | ||
wrapper = StringWrapper.new("HellO") | ||
wrapper.downcase.should eq("hello") | ||
wrapper.upcase.should eq("HELLO") | ||
wrapper.capitalize.should eq("Hello") | ||
it "delegates" do | ||
wrapper = ObjectSpec::StringWrapper.new("HellO") | ||
wrapper.downcase.should eq("hello") | ||
wrapper.upcase.should eq("HELLO") | ||
wrapper.capitalize.should eq("Hello") | ||
end | ||
end | ||
|
||
describe "getter" do | ||
it "uses simple getter" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.getter1.should eq(1) | ||
typeof(obj.@getter1).should eq(Int32) | ||
typeof(obj.getter1).should eq(Int32) | ||
end | ||
|
||
it "uses getter with type declaration" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.getter2.should eq(2) | ||
typeof(obj.@getter2).should eq(Int32) | ||
typeof(obj.getter2).should eq(Int32) | ||
end | ||
|
||
it "uses getter with type declaration and default value" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.getter3.should eq(3) | ||
typeof(obj.@getter3).should eq(Int32) | ||
typeof(obj.getter3).should eq(Int32) | ||
end | ||
|
||
it "uses getter with assignment" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.getter4.should eq(4) | ||
typeof(obj.@getter4).should eq(Int32) | ||
typeof(obj.getter4).should eq(Int32) | ||
end | ||
end | ||
|
||
describe "getter!" do | ||
it "uses getter!" do | ||
obj = ObjectSpec::TestObject.new | ||
expect_raises do | ||
obj.getter5 | ||
end | ||
obj.getter5 = 5 | ||
obj.getter5.should eq(5) | ||
typeof(obj.@getter5).should eq(Int32 | Nil) | ||
typeof(obj.getter5).should eq(Int32) | ||
end | ||
|
||
it "uses getter! with type declaration" do | ||
obj = ObjectSpec::TestObject.new | ||
expect_raises do | ||
obj.getter6 | ||
end | ||
obj.getter6 = 6 | ||
obj.getter6.should eq(6) | ||
typeof(obj.@getter6).should eq(Int32 | Nil) | ||
typeof(obj.getter6).should eq(Int32) | ||
end | ||
end | ||
|
||
describe "getter?" do | ||
it "uses getter?" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.getter7?.should be_true | ||
typeof(obj.@getter7).should eq(Bool) | ||
typeof(obj.getter7?).should eq(Bool) | ||
end | ||
|
||
it "uses getter? with type declaration" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.getter8?.should be_true | ||
typeof(obj.@getter8).should eq(Bool) | ||
typeof(obj.getter8?).should eq(Bool) | ||
end | ||
|
||
it "uses getter? with type declaration and default value" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.getter9?.should be_true | ||
typeof(obj.@getter9).should eq(Bool) | ||
typeof(obj.getter9?).should eq(Bool) | ||
end | ||
|
||
it "uses getter? with default value" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.getter10?.should be_true | ||
typeof(obj.@getter10).should eq(Bool) | ||
typeof(obj.getter10?).should eq(Bool) | ||
end | ||
end | ||
|
||
describe "setter" do | ||
it "uses setter" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.setter1.should eq(1) | ||
obj.setter1 = 2 | ||
obj.setter1.should eq(2) | ||
end | ||
|
||
it "uses setter with type declaration" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.setter2.should eq(2) | ||
obj.setter2 = 3 | ||
obj.setter2.should eq(3) | ||
end | ||
|
||
it "uses setter with type declaration and default value" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.setter3.should eq(3) | ||
obj.setter3 = 4 | ||
obj.setter3.should eq(4) | ||
end | ||
|
||
it "uses setter with default value" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.setter4.should eq(4) | ||
obj.setter4 = 5 | ||
obj.setter4.should eq(5) | ||
end | ||
end | ||
|
||
describe "property" do | ||
it "uses property" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.property1.should eq(1) | ||
obj.property1 = 2 | ||
obj.property1.should eq(2) | ||
end | ||
|
||
it "uses property with type declaration" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.property2.should eq(2) | ||
obj.property2 = 3 | ||
obj.property2.should eq(3) | ||
end | ||
|
||
it "uses property with type declaration and default value" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.property3.should eq(3) | ||
obj.property3 = 4 | ||
obj.property3.should eq(4) | ||
end | ||
|
||
it "uses property with default value" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.property4.should eq(4) | ||
obj.property4 = 5 | ||
obj.property4.should eq(5) | ||
end | ||
end | ||
|
||
describe "property!" do | ||
it "uses property!" do | ||
obj = ObjectSpec::TestObject.new | ||
expect_raises do | ||
obj.property5 | ||
end | ||
obj.property5 = 5 | ||
obj.property5.should eq(5) | ||
end | ||
|
||
it "uses property! with type declaration" do | ||
obj = ObjectSpec::TestObject.new | ||
expect_raises do | ||
obj.property6 | ||
end | ||
obj.property6 = 6 | ||
obj.property6.should eq(6) | ||
end | ||
end | ||
|
||
describe "property?" do | ||
it "uses property?" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.property7?.should be_true | ||
obj.property7 = false | ||
obj.property7?.should be_false | ||
end | ||
|
||
it "uses property? with type declaration" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.property8?.should be_true | ||
obj.property8 = false | ||
obj.property8?.should be_false | ||
end | ||
|
||
it "uses property? with type declaration and default value" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.property9?.should be_true | ||
obj.property9 = false | ||
obj.property9?.should be_false | ||
end | ||
|
||
it "uses property? with default value" do | ||
obj = ObjectSpec::TestObject.new | ||
obj.property10?.should be_true | ||
obj.property10 = false | ||
obj.property10?.should be_false | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require "spec" | ||
|
||
module RecordSpec | ||
record Record1, | ||
x : Int32, | ||
y : Array(Int32) | ||
|
||
record Record2, | ||
x : Int32 = 0, | ||
y : Array(Int32) = [2, 3] | ||
|
||
record Record3, | ||
x = 0, | ||
y = [2, 3] | ||
end | ||
|
||
describe "record" do | ||
it "defines record with type declarations" do | ||
ary = [2, 3] | ||
rec = RecordSpec::Record1.new(1, ary) | ||
rec.x.should eq(1) | ||
rec.y.should be(ary) | ||
|
||
cloned = rec.clone | ||
cloned.x.should eq(1) | ||
cloned.y.should eq(ary) | ||
cloned.y.should_not be(ary) | ||
end | ||
|
||
it "defines record with type declaration and initialization" do | ||
rec = RecordSpec::Record2.new | ||
rec.x.should eq(0) | ||
rec.y.should eq([2, 3]) | ||
|
||
cloned = rec.clone | ||
cloned.x.should eq(0) | ||
cloned.y.should eq(rec.y) | ||
cloned.y.should_not be(rec.y) | ||
end | ||
|
||
it "defines record with assignments" do | ||
rec = RecordSpec::Record3.new | ||
rec.x.should eq(0) | ||
rec.y.should eq([2, 3]) | ||
|
||
cloned = rec.clone | ||
cloned.x.should eq(0) | ||
cloned.y.should eq(rec.y) | ||
cloned.y.should_not be(rec.y) | ||
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
Oops, something went wrong.