Class: VmaTest
- Inherits:
-
Object
- Object
- VmaTest
- Defined in:
- lib/vimamsa/test_framework.rb
Instance Attribute Summary collapse
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#passes ⇒ Object
readonly
Returns the value of attribute passes.
Instance Method Summary collapse
-
#act(action) ⇒ Object
Execute one action (symbol, string, or proc).
- #assert(cond, msg = "assertion failed") ⇒ Object
-
#assert_buf(expected, msg = nil) ⇒ Object
── Assertions ───────────────────────────────────────────────────────────.
- #assert_eq(expected, actual, msg = nil) ⇒ Object
- #assert_mode(expected_mode, msg = nil) ⇒ Object
- #assert_pos(lpos, cpos, msg = nil) ⇒ Object
-
#keys(seq) ⇒ Object
Simulate a space-separated key sequence in the current mode.
-
#run_all ⇒ Object
Subclasses define test_* methods.
Instance Attribute Details
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
20 21 22 |
# File 'lib/vimamsa/test_framework.rb', line 20 def failures @failures end |
#passes ⇒ Object (readonly)
Returns the value of attribute passes.
20 21 22 |
# File 'lib/vimamsa/test_framework.rb', line 20 def passes @passes end |
Instance Method Details
#act(action) ⇒ Object
Execute one action (symbol, string, or proc)
51 52 53 54 |
# File 'lib/vimamsa/test_framework.rb', line 51 def act(action) exec_action(action) drain_idle end |
#assert(cond, msg = "assertion failed") ⇒ Object
94 95 96 |
# File 'lib/vimamsa/test_framework.rb', line 94 def assert(cond, msg = "assertion failed") raise VmaTestFailure, msg unless cond end |
#assert_buf(expected, msg = nil) ⇒ Object
── Assertions ───────────────────────────────────────────────────────────
70 71 72 73 74 |
# File 'lib/vimamsa/test_framework.rb', line 70 def assert_buf(expected, msg = nil) actual = vma.buf.to_s return if actual == expected raise VmaTestFailure, (msg || "buffer mismatch\n expected: #{expected.inspect}\n actual: #{actual.inspect}") end |
#assert_eq(expected, actual, msg = nil) ⇒ Object
89 90 91 92 |
# File 'lib/vimamsa/test_framework.rb', line 89 def assert_eq(expected, actual, msg = nil) return if expected == actual raise VmaTestFailure, (msg || "expected #{expected.inspect}, got #{actual.inspect}") end |
#assert_mode(expected_mode, msg = nil) ⇒ Object
83 84 85 86 87 |
# File 'lib/vimamsa/test_framework.rb', line 83 def assert_mode(expected_mode, msg = nil) actual = vma.kbd.get_mode return if actual == expected_mode raise VmaTestFailure, (msg || "mode mismatch: expected #{expected_mode.inspect}, got #{actual.inspect}") end |
#assert_pos(lpos, cpos, msg = nil) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/vimamsa/test_framework.rb', line 76 def assert_pos(lpos, cpos, msg = nil) al = vma.buf.lpos ac = vma.buf.cpos return if al == lpos && ac == cpos raise VmaTestFailure, (msg || "position mismatch: expected line #{lpos} col #{cpos}, got line #{al} col #{ac}") end |
#keys(seq) ⇒ Object
Simulate a space-separated key sequence in the current mode. E.g.: keys(“i h e l l o esc”) Special tokens: ctrl-x, alt-x, shift-X, esc, enter, backspace, tab, space
59 60 61 62 63 64 65 66 |
# File 'lib/vimamsa/test_framework.rb', line 59 def keys(seq) seq.split.each do |k| vma.kbd.match_key_conf(k, nil, :key_press) # Emit a key_release for modifier-only keys so state resets correctly vma.kbd.match_key_conf(k + "!", nil, :key_release) if %w[ctrl alt shift].include?(k) end drain_idle end |
#run_all ⇒ Object
Subclasses define test_* methods. Each receives a fresh buffer and the kbd in :command mode.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vimamsa/test_framework.rb', line 24 def run_all @passes = 0 @failures = [] test_methods = self.class.instance_methods(false) .select { |m| m.to_s.start_with?("test_") } .sort test_methods.each do |m| _setup_test begin send(m) @passes += 1 puts " PASS #{self.class}##{m}" rescue VmaTestFailure => e @failures << "#{self.class}##{m}: #{e.}" puts " FAIL #{self.class}##{m}: #{e.}" rescue => e @failures << "#{self.class}##{m}: #{e.class}: #{e.}" puts " ERROR #{self.class}##{m}: #{e.class}: #{e.}" puts e.backtrace.first(5).join("\n") end end end |