forked from luckyframework/avram
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with blank strings and type extensions (luckyframework#381)
* Fix issue with blank strings and type extensions Closes luckyframework#377 * Missed a spec to match all of the others * removing commented code * Adding this Nil now allows specs to compile and pass * removed duplicate method Co-authored-by: Jeremy Woertink <jeremywoertink@gmail.com>
- Loading branch information
1 parent
8d84271
commit 2788dff
Showing
16 changed files
with
136 additions
and
38 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
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 was deleted.
Oops, something went wrong.
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,67 @@ | ||
require "../spec_helper" | ||
|
||
describe "Int16" do | ||
it "parses Int16 from String" do | ||
result = Int16::Lucky.parse("10") | ||
result.value.should eq(10_i16) | ||
end | ||
|
||
it "parses Int16 from Int32" do | ||
result = Int16::Lucky.parse(400) | ||
result.value.should eq(400_i16) | ||
end | ||
|
||
it "returns FailedCast when overflow from Int16 to Int32/64" do | ||
result = Int16::Lucky.parse(1234556) | ||
result.value.should eq(nil) | ||
result.should be_a(Avram::Type::FailedCast) | ||
end | ||
|
||
it "returns nil if String is blank" do | ||
result = Int16::Lucky.parse("") | ||
result.value.should be_nil | ||
result.should be_a(Avram::Type::SuccessfulCast(Nil)) | ||
end | ||
end | ||
|
||
describe "Int32" do | ||
it "parses Int32 from String" do | ||
result = Int32::Lucky.parse("10") | ||
result.value.should eq(10) | ||
end | ||
|
||
it "parses Int32 from Int64" do | ||
result = Int32::Lucky.parse(400_i64) | ||
result.value.should eq(400) | ||
end | ||
|
||
it "returns FailedCast when overflow from Int64 to Int32" do | ||
result = Int32::Lucky.parse(2147483648) | ||
result.value.should eq(nil) | ||
result.should be_a(Avram::Type::FailedCast) | ||
end | ||
|
||
it "returns nil if String is blank" do | ||
result = Int32::Lucky.parse("") | ||
result.value.should be_nil | ||
result.should be_a(Avram::Type::SuccessfulCast(Nil)) | ||
end | ||
end | ||
|
||
describe "Int64" do | ||
it "parses Int64 from String" do | ||
result = Int64::Lucky.parse("10") | ||
result.value.should eq(10_i64) | ||
end | ||
|
||
it "parses Int64 from Int32" do | ||
result = Int64::Lucky.parse(400) | ||
result.value.should eq(400_i64) | ||
end | ||
|
||
it "returns nil if String is blank" do | ||
result = Int64::Lucky.parse("") | ||
result.value.should be_nil | ||
result.should be_a(Avram::Type::SuccessfulCast(Nil)) | ||
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
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
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
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
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
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