summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHansuk <flavono123@gmail.com>2020-01-16 00:38:27 +0900
committerHansuk <flavono123@gmail.com>2020-01-16 00:38:27 +0900
commit6995484ee3a4a505c1c8705709f8dc00899013b3 (patch)
tree036e2c926399171f36a0131f83ca82a1b4616b8b /test
parent909403b32065e467487e7810bf2d535504182df5 (diff)
downloadslop-6995484ee3a4a505c1c8705709f8dc00899013b3.tar.gz
support scientific nations for float options
- reference: https://stackoverflow.com/questions/638565/parsing-scientific-notation-sensibly - remove the todo comment(no idea for etc) Signed-off-by: Hansuk <flavono123@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/types_test.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/types_test.rb b/test/types_test.rb
index 171c4d9..728b969 100644
--- a/test/types_test.rb
+++ b/test/types_test.rb
@@ -56,7 +56,9 @@ describe Slop::FloatOption do
@apr_value = 2.9
@minus = @options.float "--minus"
@plus = @options.float "--plus"
- @result = @options.parse %W(--apr #{@apr_value} --minus -6.1 --plus +9.4)
+ @scientific_notation = @options.float "--scientific-notation"
+ @scientific_notation_value = 4e21
+ @result = @options.parse %W(--apr #{@apr_value} --minus -6.1 --plus +9.4 --scientific-notation #{@scientific_notation_value})
end
it "returns the value as a float" do
@@ -65,6 +67,22 @@ describe Slop::FloatOption do
assert_equal 9.4, @result[:plus]
end
+ it "parses scientific notations" do
+ assert_equal @scientific_notation_value, @result[:scientific_notation]
+ @scientific_notation_value = 4E21
+ @result = @options.parse %W(--scientific-notation #{@scientific_notation_value})
+ assert_equal @scientific_notation_value, @result[:scientific_notation]
+ @scientific_notation_value = 4.0e21
+ @result = @options.parse %W(--scientific-notation #{@scientific_notation_value})
+ assert_equal @scientific_notation_value, @result[:scientific_notation]
+ @scientific_notation_value = -4e21
+ @result = @options.parse %W(--scientific-notation #{@scientific_notation_value})
+ assert_equal @scientific_notation_value, @result[:scientific_notation]
+ @scientific_notation_value = 4e-21
+ @result = @options.parse %W(--scientific-notation #{@scientific_notation_value})
+ assert_equal @scientific_notation_value, @result[:scientific_notation]
+ end
+
it "returns nil for non-numbers by default" do
@result.parser.parse %w(--apr hello)
assert_nil @result[:apr]