[ruby/optparse] Add test for enum arguments

https://github.com/ruby/optparse/commit/0a0e977b7c
This commit is contained in:
Nobuyoshi Nakada 2025-03-09 22:54:21 +09:00 committed by git
parent 0c73328aff
commit 213c27825a

View File

@ -7,6 +7,7 @@ class TestOptionParserPlaceArg < TestOptionParser
@opt.def_option("-x [VAL]") {|x| @flag = x}
@opt.def_option("--option [VAL]") {|x| @flag = x}
@opt.def_option("-T [level]", /^[0-4]$/, Integer) {|x| @topt = x}
@opt.def_option("--enum [VAL]", [:Alpha, :Bravo, :Charlie]) {|x| @enum = x}
@topt = nil
@opt.def_option("-n") {}
@opt.def_option("--regexp [REGEXP]", Regexp) {|x| @reopt = x}
@ -93,4 +94,9 @@ class TestOptionParserPlaceArg < TestOptionParser
assert_equal(%w"", no_error {@opt.parse!(%w"--lambda")})
assert_equal(nil, @flag)
end
def test_enum
assert_equal([], no_error {@opt.parse!(%w"--enum=A")})
assert_equal(:Alpha, @enum)
end
end