Created
March 4, 2012 05:27
-
-
Save ddk50/1970810 to your computer and use it in GitHub Desktop.
test
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
require 'getoptlong' | |
require 'bayesdebug' | |
class AAA | |
def self.test | |
opts = GetoptLong.new( | |
[ '--help', '-h', GetoptLong::NO_ARGUMENT ], | |
[ '--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT ], | |
[ '--name', GetoptLong::OPTIONAL_ARGUMENT ] | |
) | |
dir = nil | |
name = nil | |
repetitions = 1 | |
opts.each do |opt, arg| | |
case opt | |
when '--help' | |
puts <<-EOF | |
hello [OPTION] ... DIR | |
-h, --help: | |
show help | |
--repeat x, -n x: | |
repeat x times | |
--name [name]: | |
greet user by name, if name not supplied default is John | |
DIR: The directory in which to issue the greeting. | |
EOF | |
when '--repeat' | |
repetitions = arg.to_i | |
when '--name' | |
if arg == '' | |
name = 'John' | |
else | |
name = arg | |
end | |
end | |
end | |
if ARGV.length != 1 | |
puts "Missing dir argument (try --help)" | |
return | |
end | |
dir = ARGV.shift | |
Dir.chdir(dir) | |
for i in (1..repetitions) | |
print "Hello" | |
if name | |
print ", #{name}" | |
end | |
puts | |
end | |
end | |
end | |
Bayse.passing_case {|x| | |
ARGV = [] | |
ARGV[0] = "." | |
AAA.test | |
} | |
Bayse.failing_case {|x| | |
ARGV = [] | |
ARGV[0] = "." | |
ARGV[1] = "-n" | |
ARGV[2] = "5" | |
ARGV[3] = "--name" | |
ARGV[4] = "kazushi" | |
AAA.test | |
} | |
Bayse.guess |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment