| 1 |
assert("slop - parse - option - nothing") do |
| 2 |
argv = ["path"] |
| 3 |
options = Slop.parse(argv) do |parser| |
| 4 |
end |
| 5 |
assert_equal(["path"], options.arguments) |
| 6 |
end |
| 7 |
|
| 8 |
assert("slop - parse - option - processed") do |
| 9 |
argv = ["--log", "/tmp/log", "path"] |
| 10 |
options = Slop.parse(argv) do |parser| |
| 11 |
parser.string("--log", "Log to PATH") |
| 12 |
end |
| 13 |
assert_equal([ |
| 14 |
{ |
| 15 |
:log => "/tmp/log", |
| 16 |
}, |
| 17 |
["path"], |
| 18 |
], |
| 19 |
[ |
| 20 |
options.to_hash, |
| 21 |
options.arguments, |
| 22 |
]) |
| 23 |
end |
| 24 |
|
| 25 |
assert("slop - parse - option - short") do |
| 26 |
argv = ["-l", "/tmp/log", "path"] |
| 27 |
options = Slop.parse(argv) do |parser| |
| 28 |
parser.string("-l", "Log to PATH") |
| 29 |
end |
| 30 |
assert_equal([ |
| 31 |
{ |
| 32 |
:l => "/tmp/log", |
| 33 |
}, |
| 34 |
["path"], |
| 35 |
], |
| 36 |
[ |
| 37 |
options.to_hash, |
| 38 |
options.arguments, |
| 39 |
]) |
| 40 |
end |
| 41 |
|
| 42 |
assert("slop - to_s") do |
| 43 |
$0 = "test/mrb.rb" |
| 44 |
options = Slop::Options.new do |
| 45 |
end |
| 46 |
options.string("-l", "--log", "Log to PATH") |
| 47 |
assert_equal(<<-HELP, options.to_s) |
| 48 |
usage: test/mrb.rb [options] |
| 49 |
-l, --log Log to PATH |
| 50 |
HELP |
| 51 |
end |