Permalink
Browse files

Fixing commands and shorthand. Avoid false positive matches.

  • Loading branch information...
1 parent d7af4ed commit eab9d8375a1901c0188fe6e040bdf09a039adf97 @jdunphy committed Apr 21, 2011
Showing with 29 additions and 10 deletions.
  1. +1 −1 README.rdoc
  2. +16 −9 lib/qer/todo.rb
  3. +12 −0 test/test_qer.rb
View
@@ -70,7 +70,7 @@ Commands:
== INSTALL:
-sudo gem install qer
+gem install qer
== LICENSE:
View
@@ -166,25 +166,28 @@ def dump(queue, string, label = title)
end
def command(args)
- case(args.shift)
- when /^a(dd)?/
+ cmd = args.shift
+ case(cmd)
+ when "add", "a"
self.add(args.join(" ")) # qer add Some task 1
- when /^r(emove)?/
+ when "remove", "r"
self.remove(args.shift.to_i) # qer remove 0
- when /^pu(sh)?/
+ when "push", "pu"
self.push(args.join(" ")) # qer push Some task 2
- when /^po(p)?/
+ when "pop", "po"
self.pop # qer pop
- when /^b(ump)?/
+ when "bump", "b"
self.bump(*args.first(2)) # qer bump
- when /^clear/
+ when "clear"
self.clear(args.shift) # qer clear
when /.*help/
self.help # qer help
- when /^h(istory)?/
+ when "history", "h"
self.print_history # qer history
- else
+ when "", nil
self.print # qer
+ else
+ self.no_match cmd
end
end
@@ -220,5 +223,9 @@ def help
EOF
puts string unless self.class.quiet
end
+
+ def no_match cmd
+ puts "Did not recognize command: #{cmd}"
+ end
end
end
View
@@ -172,6 +172,18 @@ def setup
assert_output(/Adding: some stuff/)
end
+ should "add with shorthand cmd" do
+ @todo.command(%w(a some stuff))
+ assert_equal 2, @todo.queue.size
+ assert_output(/Adding: some stuff/)
+ end
+
+ should "not add" do
+ @todo.command(%w(asdf))
+ assert_equal 1, @todo.queue.size
+ assert_output(/did not recognize/i)
+ end
+
should "remove" do
assert_equal "Some Task", @todo.command(%w(remove 0)).last
assert_equal 0, @todo.queue.size

0 comments on commit eab9d83

Please sign in to comment.