summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEugene Otto <eotto@plaid.com>2022-09-30 02:24:13 -0700
committerEugene Otto <eotto@plaid.com>2022-09-30 04:35:46 -0700
commit1bcf46b7907d4fc566a1382ad4eda4d0e9354e63 (patch)
treeee0f92886f2d46d1f4f6b0a63c93e068e8814dd2 /test
parent41af0db78bba76cc7faccbf6adb400e65274f3a3 (diff)
downloadslop-1bcf46b7907d4fc566a1382ad4eda4d0e9354e63.tar.gz
Fix explicitly false booleans
When a boolean option is explicitly set to `false`, e.g.: ```bash --option=false ``` it enters slop as the string value `'false'`. This commit updates the `BoolOption` option handler to interpret `'false'` and various other falsey values (`false`, `'false'`, `'no'`, `'off'`, `'0'`) as logically false.
Diffstat (limited to 'test')
-rw-r--r--test/types_test.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/test/types_test.rb b/test/types_test.rb
index a45302a..ea2ba8d 100644
--- a/test/types_test.rb
+++ b/test/types_test.rb
@@ -34,9 +34,11 @@ describe Slop::BoolOption do
@verbose = @options.bool "--verbose"
@quiet = @options.bool "--quiet"
@inversed = @options.bool "--inversed", default: true
+ @explicit = @options.bool "--explicit"
@bloc = @options.bool("--bloc"){|val| (@bloc_val ||= []) << val}
@result = @options.parse %w(--verbose --no-inversed
- --bloc --no-bloc)
+ --bloc --no-bloc
+ --explicit=false)
end
it "returns true if used" do
@@ -54,6 +56,10 @@ describe Slop::BoolOption do
it "will invert the value passed to &block via --no- prefix" do
assert_equal [true, false], @bloc_val
end
+
+ it "returns false when explicitly false" do
+ assert_equal false, @result[:explicit]
+ end
end
describe Slop::IntegerOption do