Browse code

Rename acceptance test

John Hawthorn authored on 31/12/2016 02:13:06
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,177 +0,0 @@
1
-require 'minitest'
2
-require 'minitest/autorun'
3
-require 'ttytest'
4
-
5
-class FzyTest < Minitest::Test
6
-  FZY_PATH = File.expand_path('../../../fzy', __FILE__)
7
-
8
-  def setup
9
-    # fzy is fast.
10
-    # This is never hit in a (passing) test suite, but helps speed up development
11
-    TTYtest.default_max_wait_time = 0.2
12
-  end
13
-
14
-  def test_empty_list
15
-    @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "" | #{FZY_PATH}})
16
-    @tty.assert_cursor_position(y: 1, x: 2)
17
-    @tty.assert_matches <<~TTY
18
-      placeholder
19
-      >
20
-    TTY
21
-
22
-    @tty.send_keys('t')
23
-    @tty.assert_cursor_position(y: 1, x: 3)
24
-    @tty.assert_matches <<~TTY
25
-      placeholder
26
-      > t
27
-    TTY
28
-
29
-    @tty.send_keys('z')
30
-    @tty.assert_cursor_position(y: 1, x: 4)
31
-    @tty.assert_matches <<~TTY
32
-      placeholder
33
-      > tz
34
-    TTY
35
-
36
-    @tty.send_keys("\r")
37
-    @tty.assert_cursor_position(y: 2, x: 0)
38
-    @tty.assert_matches <<~TTY
39
-      placeholder
40
-      tz
41
-    TTY
42
-  end
43
-
44
-  def test_one_item
45
-    @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test" | #{FZY_PATH}})
46
-    @tty.assert_matches <<~TTY
47
-      placeholder
48
-      >
49
-      test
50
-    TTY
51
-    @tty.assert_cursor_position(y: 1, x: 2)
52
-
53
-    @tty.send_keys('t')
54
-    @tty.assert_cursor_position(y: 1, x: 3)
55
-    @tty.assert_matches <<~TTY
56
-      placeholder
57
-      > t
58
-      test
59
-    TTY
60
-
61
-    @tty.send_keys('z')
62
-    @tty.assert_cursor_position(y: 1, x: 4)
63
-    @tty.assert_matches <<~TTY
64
-      placeholder
65
-      > tz
66
-    TTY
67
-
68
-    @tty.send_keys("\r")
69
-    @tty.assert_cursor_position(y: 2, x: 0)
70
-    @tty.assert_matches <<~TTY
71
-      placeholder
72
-      tz
73
-    TTY
74
-  end
75
-
76
-  def test_two_items
77
-    @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
78
-    @tty.assert_cursor_position(y: 1, x: 2)
79
-    @tty.assert_matches <<~TTY
80
-      placeholder
81
-      >
82
-      test
83
-      foo
84
-    TTY
85
-
86
-    @tty.send_keys('t')
87
-    @tty.assert_cursor_position(y: 1, x: 3)
88
-    @tty.assert_matches <<~TTY
89
-      placeholder
90
-      > t
91
-      test
92
-    TTY
93
-
94
-    @tty.send_keys('z')
95
-    @tty.assert_cursor_position(y: 1, x: 4)
96
-    @tty.assert_matches <<~TTY
97
-      placeholder
98
-      > tz
99
-    TTY
100
-
101
-    @tty.send_keys("\r")
102
-    @tty.assert_matches <<~TTY
103
-      placeholder
104
-      tz
105
-    TTY
106
-    @tty.assert_cursor_position(y: 2, x: 0)
107
-  end
108
-
109
-  def ctrl(key)
110
-    ((key.upcase.ord) - ('A'.ord) + 1).chr
111
-  end
112
-
113
-  def test_editing
114
-    @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
115
-    @tty.assert_cursor_position(y: 1, x: 2)
116
-    @tty.assert_matches <<~TTY
117
-      placeholder
118
-      >
119
-      test
120
-      foo
121
-    TTY
122
-
123
-    @tty.send_keys("foo bar baz")
124
-    @tty.assert_cursor_position(y: 1, x: 13)
125
-    @tty.assert_matches <<~TTY
126
-      placeholder
127
-      > foo bar baz
128
-    TTY
129
-
130
-    @tty.send_keys(ctrl('H'))
131
-    @tty.assert_cursor_position(y: 1, x: 12)
132
-    @tty.assert_matches <<~TTY
133
-      placeholder
134
-      > foo bar ba
135
-    TTY
136
-
137
-    @tty.send_keys(ctrl('W'))
138
-    @tty.assert_cursor_position(y: 1, x: 10)
139
-    @tty.assert_matches <<~TTY
140
-      placeholder
141
-      > foo bar
142
-    TTY
143
-
144
-    @tty.send_keys(ctrl('U'))
145
-    @tty.assert_cursor_position(y: 1, x: 2)
146
-    @tty.assert_matches <<~TTY
147
-      placeholder
148
-      >
149
-      test
150
-      foo
151
-    TTY
152
-  end
153
-
154
-  def test_ctrl_d
155
-    @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
156
-    @tty.assert_matches ">\nfoo\nbar"
157
-
158
-    @tty.send_keys('foo')
159
-    @tty.assert_matches "> foo\nfoo"
160
-
161
-    @tty.send_keys(ctrl('D'))
162
-    @tty.assert_matches ''
163
-    @tty.assert_cursor_position(y: 0, x: 0)
164
-  end
165
-
166
-  def test_ctrl_c
167
-    @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
168
-    @tty.assert_matches ">\nfoo\nbar"
169
-
170
-    @tty.send_keys('foo')
171
-    @tty.assert_matches "> foo\nfoo"
172
-
173
-    @tty.send_keys(ctrl('C'))
174
-    @tty.assert_matches ''
175
-    @tty.assert_cursor_position(y: 0, x: 0)
176
-  end
177
-end
Browse code

Upgrade to ttytest 0.4.0

John Hawthorn authored on 31/12/2016 00:25:54
Showing 1 changed files
... ...
@@ -13,83 +13,96 @@ class FzyTest < Minitest::Test
13 13
 
14 14
   def test_empty_list
15 15
     @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "" | #{FZY_PATH}})
16
-    @tty.assert_row(0, 'placeholder')
17
-    @tty.assert_row(1, '>')
18
-    @tty.assert_row(2, '')
19 16
     @tty.assert_cursor_position(y: 1, x: 2)
17
+    @tty.assert_matches <<~TTY
18
+      placeholder
19
+      >
20
+    TTY
20 21
 
21 22
     @tty.send_keys('t')
22
-    @tty.assert_row(0, 'placeholder')
23
-    @tty.assert_row(1, '> t')
24
-    @tty.assert_row(2, '')
25 23
     @tty.assert_cursor_position(y: 1, x: 3)
24
+    @tty.assert_matches <<~TTY
25
+      placeholder
26
+      > t
27
+    TTY
26 28
 
27 29
     @tty.send_keys('z')
28
-    @tty.assert_row(0, 'placeholder')
29
-    @tty.assert_row(1, '> tz')
30
-    @tty.assert_row(2, '')
31 30
     @tty.assert_cursor_position(y: 1, x: 4)
31
+    @tty.assert_matches <<~TTY
32
+      placeholder
33
+      > tz
34
+    TTY
32 35
 
33 36
     @tty.send_keys("\r")
34
-    @tty.assert_row(0, 'placeholder')
35
-    @tty.assert_row(1, 'tz')
36 37
     @tty.assert_cursor_position(y: 2, x: 0)
38
+    @tty.assert_matches <<~TTY
39
+      placeholder
40
+      tz
41
+    TTY
37 42
   end
38 43
 
39 44
   def test_one_item
40 45
     @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test" | #{FZY_PATH}})
41
-    @tty.assert_row(0, 'placeholder')
42
-    @tty.assert_row(1, '>')
43
-    @tty.assert_row(2, 'test')
44
-    @tty.assert_row(3, '')
46
+    @tty.assert_matches <<~TTY
47
+      placeholder
48
+      >
49
+      test
50
+    TTY
45 51
     @tty.assert_cursor_position(y: 1, x: 2)
46 52
 
47 53
     @tty.send_keys('t')
48
-    @tty.assert_row(0, 'placeholder')
49
-    @tty.assert_row(1, '> t')
50
-    @tty.assert_row(2, 'test')
51
-    @tty.assert_row(3, '')
52 54
     @tty.assert_cursor_position(y: 1, x: 3)
55
+    @tty.assert_matches <<~TTY
56
+      placeholder
57
+      > t
58
+      test
59
+    TTY
53 60
 
54 61
     @tty.send_keys('z')
55
-    @tty.assert_row(0, 'placeholder')
56
-    @tty.assert_row(1, '> tz')
57
-    @tty.assert_row(2, '')
58
-    @tty.assert_row(3, '')
59 62
     @tty.assert_cursor_position(y: 1, x: 4)
63
+    @tty.assert_matches <<~TTY
64
+      placeholder
65
+      > tz
66
+    TTY
60 67
 
61 68
     @tty.send_keys("\r")
62
-    @tty.assert_row(0, 'placeholder')
63
-    @tty.assert_row(1, 'tz')
64 69
     @tty.assert_cursor_position(y: 2, x: 0)
70
+    @tty.assert_matches <<~TTY
71
+      placeholder
72
+      tz
73
+    TTY
65 74
   end
66 75
 
67 76
   def test_two_items
68 77
     @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
69
-    @tty.assert_row(0, 'placeholder')
70
-    @tty.assert_row(1, '>')
71
-    @tty.assert_row(2, 'test')
72
-    @tty.assert_row(3, 'foo')
73
-    @tty.assert_row(4, '')
74 78
     @tty.assert_cursor_position(y: 1, x: 2)
79
+    @tty.assert_matches <<~TTY
80
+      placeholder
81
+      >
82
+      test
83
+      foo
84
+    TTY
75 85
 
76 86
     @tty.send_keys('t')
77
-    @tty.assert_row(0, 'placeholder')
78
-    @tty.assert_row(1, '> t')
79
-    @tty.assert_row(2, 'test')
80
-    @tty.assert_row(3, '')
81 87
     @tty.assert_cursor_position(y: 1, x: 3)
88
+    @tty.assert_matches <<~TTY
89
+      placeholder
90
+      > t
91
+      test
92
+    TTY
82 93
 
83 94
     @tty.send_keys('z')
84
-    @tty.assert_row(0, 'placeholder')
85
-    @tty.assert_row(1, '> tz')
86
-    @tty.assert_row(2, '')
87
-    @tty.assert_row(3, '')
88 95
     @tty.assert_cursor_position(y: 1, x: 4)
96
+    @tty.assert_matches <<~TTY
97
+      placeholder
98
+      > tz
99
+    TTY
89 100
 
90 101
     @tty.send_keys("\r")
91
-    @tty.assert_row(0, 'placeholder')
92
-    @tty.assert_row(1, 'tz')
102
+    @tty.assert_matches <<~TTY
103
+      placeholder
104
+      tz
105
+    TTY
93 106
     @tty.assert_cursor_position(y: 2, x: 0)
94 107
   end
95 108
 
... ...
@@ -99,56 +112,66 @@ class FzyTest < Minitest::Test
99 112
 
100 113
   def test_editing
101 114
     @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
102
-    @tty.assert_row(0, 'placeholder')
103
-    @tty.assert_row(1, '>')
104 115
     @tty.assert_cursor_position(y: 1, x: 2)
116
+    @tty.assert_matches <<~TTY
117
+      placeholder
118
+      >
119
+      test
120
+      foo
121
+    TTY
105 122
 
106 123
     @tty.send_keys("foo bar baz")
107
-    @tty.assert_row(0, 'placeholder')
108
-    @tty.assert_row(1, '> foo bar baz')
109 124
     @tty.assert_cursor_position(y: 1, x: 13)
125
+    @tty.assert_matches <<~TTY
126
+      placeholder
127
+      > foo bar baz
128
+    TTY
110 129
 
111 130
     @tty.send_keys(ctrl('H'))
112
-    @tty.assert_row(0, 'placeholder')
113
-    @tty.assert_row(1, '> foo bar ba')
114 131
     @tty.assert_cursor_position(y: 1, x: 12)
132
+    @tty.assert_matches <<~TTY
133
+      placeholder
134
+      > foo bar ba
135
+    TTY
115 136
 
116 137
     @tty.send_keys(ctrl('W'))
117
-    @tty.assert_row(0, 'placeholder')
118
-    @tty.assert_row(1, '> foo bar')
119 138
     @tty.assert_cursor_position(y: 1, x: 10)
139
+    @tty.assert_matches <<~TTY
140
+      placeholder
141
+      > foo bar
142
+    TTY
120 143
 
121 144
     @tty.send_keys(ctrl('U'))
122
-    @tty.assert_row(0, 'placeholder')
123
-    @tty.assert_row(1, '>')
124 145
     @tty.assert_cursor_position(y: 1, x: 2)
146
+    @tty.assert_matches <<~TTY
147
+      placeholder
148
+      >
149
+      test
150
+      foo
151
+    TTY
125 152
   end
126 153
 
127 154
   def test_ctrl_d
128 155
     @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
129
-    @tty.assert_row(0, '>')
156
+    @tty.assert_matches ">\nfoo\nbar"
130 157
 
131 158
     @tty.send_keys('foo')
132
-    @tty.assert_row(0, '> foo')
159
+    @tty.assert_matches "> foo\nfoo"
133 160
 
134 161
     @tty.send_keys(ctrl('D'))
135
-    @tty.assert_row(0, '')
136
-    @tty.assert_row(1, '')
137
-    @tty.assert_row(2, '')
162
+    @tty.assert_matches ''
138 163
     @tty.assert_cursor_position(y: 0, x: 0)
139 164
   end
140 165
 
141 166
   def test_ctrl_c
142 167
     @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
143
-    @tty.assert_row(0, '>')
168
+    @tty.assert_matches ">\nfoo\nbar"
144 169
 
145 170
     @tty.send_keys('foo')
146
-    @tty.assert_row(0, '> foo')
171
+    @tty.assert_matches "> foo\nfoo"
147 172
 
148 173
     @tty.send_keys(ctrl('C'))
149
-    @tty.assert_row(0, '')
150
-    @tty.assert_row(1, '')
151
-    @tty.assert_row(2, '')
174
+    @tty.assert_matches ''
152 175
     @tty.assert_cursor_position(y: 0, x: 0)
153 176
   end
154 177
 end
Browse code

Upgrade to ttytest 0.3.0

John Hawthorn authored on 29/12/2016 10:27:18
Showing 1 changed files
... ...
@@ -12,7 +12,7 @@ class FzyTest < Minitest::Test
12 12
   end
13 13
 
14 14
   def test_empty_list
15
-    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "" | #{FZY_PATH}})
15
+    @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "" | #{FZY_PATH}})
16 16
     @tty.assert_row(0, 'placeholder')
17 17
     @tty.assert_row(1, '>')
18 18
     @tty.assert_row(2, '')
... ...
@@ -37,7 +37,7 @@ class FzyTest < Minitest::Test
37 37
   end
38 38
 
39 39
   def test_one_item
40
-    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test" | #{FZY_PATH}})
40
+    @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test" | #{FZY_PATH}})
41 41
     @tty.assert_row(0, 'placeholder')
42 42
     @tty.assert_row(1, '>')
43 43
     @tty.assert_row(2, 'test')
... ...
@@ -65,7 +65,7 @@ class FzyTest < Minitest::Test
65 65
   end
66 66
 
67 67
   def test_two_items
68
-    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
68
+    @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
69 69
     @tty.assert_row(0, 'placeholder')
70 70
     @tty.assert_row(1, '>')
71 71
     @tty.assert_row(2, 'test')
... ...
@@ -98,7 +98,7 @@ class FzyTest < Minitest::Test
98 98
   end
99 99
 
100 100
   def test_editing
101
-    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
101
+    @tty = TTYtest.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
102 102
     @tty.assert_row(0, 'placeholder')
103 103
     @tty.assert_row(1, '>')
104 104
     @tty.assert_cursor_position(y: 1, x: 2)
... ...
@@ -125,7 +125,7 @@ class FzyTest < Minitest::Test
125 125
   end
126 126
 
127 127
   def test_ctrl_d
128
-    @tty = TTYtest.driver.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
128
+    @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
129 129
     @tty.assert_row(0, '>')
130 130
 
131 131
     @tty.send_keys('foo')
... ...
@@ -139,7 +139,7 @@ class FzyTest < Minitest::Test
139 139
   end
140 140
 
141 141
   def test_ctrl_c
142
-    @tty = TTYtest.driver.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
142
+    @tty = TTYtest.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
143 143
     @tty.assert_row(0, '>')
144 144
 
145 145
     @tty.send_keys('foo')
Browse code

Use correct path to fzy in integration test

Whoops. On my computer fzy is a symlink to the fzy built in the project
directory, so I didn't notice this.

John Hawthorn authored on 28/12/2016 10:12:57
Showing 1 changed files
... ...
@@ -12,7 +12,7 @@ class FzyTest < Minitest::Test
12 12
   end
13 13
 
14 14
   def test_empty_list
15
-    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "" | fzy})
15
+    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "" | #{FZY_PATH}})
16 16
     @tty.assert_row(0, 'placeholder')
17 17
     @tty.assert_row(1, '>')
18 18
     @tty.assert_row(2, '')
... ...
@@ -37,7 +37,7 @@ class FzyTest < Minitest::Test
37 37
   end
38 38
 
39 39
   def test_one_item
40
-    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test" | fzy})
40
+    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test" | #{FZY_PATH}})
41 41
     @tty.assert_row(0, 'placeholder')
42 42
     @tty.assert_row(1, '>')
43 43
     @tty.assert_row(2, 'test')
... ...
@@ -65,7 +65,7 @@ class FzyTest < Minitest::Test
65 65
   end
66 66
 
67 67
   def test_two_items
68
-    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test\nfoo" | fzy})
68
+    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
69 69
     @tty.assert_row(0, 'placeholder')
70 70
     @tty.assert_row(1, '>')
71 71
     @tty.assert_row(2, 'test')
... ...
@@ -98,7 +98,7 @@ class FzyTest < Minitest::Test
98 98
   end
99 99
 
100 100
   def test_editing
101
-    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test\nfoo" | fzy})
101
+    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test\nfoo" | #{FZY_PATH}})
102 102
     @tty.assert_row(0, 'placeholder')
103 103
     @tty.assert_row(1, '>')
104 104
     @tty.assert_cursor_position(y: 1, x: 2)
... ...
@@ -125,7 +125,7 @@ class FzyTest < Minitest::Test
125 125
   end
126 126
 
127 127
   def test_ctrl_d
128
-    @tty = TTYtest.driver.new_terminal(%{echo -n "foo\nbar" | fzy})
128
+    @tty = TTYtest.driver.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
129 129
     @tty.assert_row(0, '>')
130 130
 
131 131
     @tty.send_keys('foo')
... ...
@@ -139,7 +139,7 @@ class FzyTest < Minitest::Test
139 139
   end
140 140
 
141 141
   def test_ctrl_c
142
-    @tty = TTYtest.driver.new_terminal(%{echo -n "foo\nbar" | fzy})
142
+    @tty = TTYtest.driver.new_terminal(%{echo -n "foo\nbar" | #{FZY_PATH}})
143 143
     @tty.assert_row(0, '>')
144 144
 
145 145
     @tty.send_keys('foo')
Browse code

Add integration test for ctrl-d and ctrl-d

John Hawthorn authored on 28/12/2016 09:38:20
Showing 1 changed files
... ...
@@ -123,4 +123,32 @@ class FzyTest < Minitest::Test
123 123
     @tty.assert_row(1, '>')
124 124
     @tty.assert_cursor_position(y: 1, x: 2)
125 125
   end
126
+
127
+  def test_ctrl_d
128
+    @tty = TTYtest.driver.new_terminal(%{echo -n "foo\nbar" | fzy})
129
+    @tty.assert_row(0, '>')
130
+
131
+    @tty.send_keys('foo')
132
+    @tty.assert_row(0, '> foo')
133
+
134
+    @tty.send_keys(ctrl('D'))
135
+    @tty.assert_row(0, '')
136
+    @tty.assert_row(1, '')
137
+    @tty.assert_row(2, '')
138
+    @tty.assert_cursor_position(y: 0, x: 0)
139
+  end
140
+
141
+  def test_ctrl_c
142
+    @tty = TTYtest.driver.new_terminal(%{echo -n "foo\nbar" | fzy})
143
+    @tty.assert_row(0, '>')
144
+
145
+    @tty.send_keys('foo')
146
+    @tty.assert_row(0, '> foo')
147
+
148
+    @tty.send_keys(ctrl('C'))
149
+    @tty.assert_row(0, '')
150
+    @tty.assert_row(1, '')
151
+    @tty.assert_row(2, '')
152
+    @tty.assert_cursor_position(y: 0, x: 0)
153
+  end
126 154
 end
Browse code

Add integration test for query editing

John Hawthorn authored on 28/12/2016 09:27:17
Showing 1 changed files
... ...
@@ -92,4 +92,35 @@ class FzyTest < Minitest::Test
92 92
     @tty.assert_row(1, 'tz')
93 93
     @tty.assert_cursor_position(y: 2, x: 0)
94 94
   end
95
+
96
+  def ctrl(key)
97
+    ((key.upcase.ord) - ('A'.ord) + 1).chr
98
+  end
99
+
100
+  def test_editing
101
+    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test\nfoo" | fzy})
102
+    @tty.assert_row(0, 'placeholder')
103
+    @tty.assert_row(1, '>')
104
+    @tty.assert_cursor_position(y: 1, x: 2)
105
+
106
+    @tty.send_keys("foo bar baz")
107
+    @tty.assert_row(0, 'placeholder')
108
+    @tty.assert_row(1, '> foo bar baz')
109
+    @tty.assert_cursor_position(y: 1, x: 13)
110
+
111
+    @tty.send_keys(ctrl('H'))
112
+    @tty.assert_row(0, 'placeholder')
113
+    @tty.assert_row(1, '> foo bar ba')
114
+    @tty.assert_cursor_position(y: 1, x: 12)
115
+
116
+    @tty.send_keys(ctrl('W'))
117
+    @tty.assert_row(0, 'placeholder')
118
+    @tty.assert_row(1, '> foo bar')
119
+    @tty.assert_cursor_position(y: 1, x: 10)
120
+
121
+    @tty.send_keys(ctrl('U'))
122
+    @tty.assert_row(0, 'placeholder')
123
+    @tty.assert_row(1, '>')
124
+    @tty.assert_cursor_position(y: 1, x: 2)
125
+  end
95 126
 end
Browse code

Expand on integration test

John Hawthorn authored on 28/12/2016 09:10:42
Showing 1 changed files
... ...
@@ -5,21 +5,35 @@ require 'ttytest'
5 5
 class FzyTest < Minitest::Test
6 6
   FZY_PATH = File.expand_path('../../../fzy', __FILE__)
7 7
 
8
+  def setup
9
+    # fzy is fast.
10
+    # This is never hit in a (passing) test suite, but helps speed up development
11
+    TTYtest.default_max_wait_time = 0.2
12
+  end
13
+
8 14
   def test_empty_list
9 15
     @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "" | fzy})
10 16
     @tty.assert_row(0, 'placeholder')
11 17
     @tty.assert_row(1, '>')
12 18
     @tty.assert_row(2, '')
19
+    @tty.assert_cursor_position(y: 1, x: 2)
13 20
 
14 21
     @tty.send_keys('t')
15 22
     @tty.assert_row(0, 'placeholder')
16 23
     @tty.assert_row(1, '> t')
17 24
     @tty.assert_row(2, '')
25
+    @tty.assert_cursor_position(y: 1, x: 3)
18 26
 
19 27
     @tty.send_keys('z')
20 28
     @tty.assert_row(0, 'placeholder')
21 29
     @tty.assert_row(1, '> tz')
22 30
     @tty.assert_row(2, '')
31
+    @tty.assert_cursor_position(y: 1, x: 4)
32
+
33
+    @tty.send_keys("\r")
34
+    @tty.assert_row(0, 'placeholder')
35
+    @tty.assert_row(1, 'tz')
36
+    @tty.assert_cursor_position(y: 2, x: 0)
23 37
   end
24 38
 
25 39
   def test_one_item
... ...
@@ -28,18 +42,26 @@ class FzyTest < Minitest::Test
28 42
     @tty.assert_row(1, '>')
29 43
     @tty.assert_row(2, 'test')
30 44
     @tty.assert_row(3, '')
45
+    @tty.assert_cursor_position(y: 1, x: 2)
31 46
 
32 47
     @tty.send_keys('t')
33 48
     @tty.assert_row(0, 'placeholder')
34 49
     @tty.assert_row(1, '> t')
35 50
     @tty.assert_row(2, 'test')
36 51
     @tty.assert_row(3, '')
52
+    @tty.assert_cursor_position(y: 1, x: 3)
37 53
 
38 54
     @tty.send_keys('z')
39 55
     @tty.assert_row(0, 'placeholder')
40 56
     @tty.assert_row(1, '> tz')
41 57
     @tty.assert_row(2, '')
42 58
     @tty.assert_row(3, '')
59
+    @tty.assert_cursor_position(y: 1, x: 4)
60
+
61
+    @tty.send_keys("\r")
62
+    @tty.assert_row(0, 'placeholder')
63
+    @tty.assert_row(1, 'tz')
64
+    @tty.assert_cursor_position(y: 2, x: 0)
43 65
   end
44 66
 
45 67
   def test_two_items
... ...
@@ -49,17 +71,25 @@ class FzyTest < Minitest::Test
49 71
     @tty.assert_row(2, 'test')
50 72
     @tty.assert_row(3, 'foo')
51 73
     @tty.assert_row(4, '')
74
+    @tty.assert_cursor_position(y: 1, x: 2)
52 75
 
53 76
     @tty.send_keys('t')
54 77
     @tty.assert_row(0, 'placeholder')
55 78
     @tty.assert_row(1, '> t')
56 79
     @tty.assert_row(2, 'test')
57 80
     @tty.assert_row(3, '')
81
+    @tty.assert_cursor_position(y: 1, x: 3)
58 82
 
59 83
     @tty.send_keys('z')
60 84
     @tty.assert_row(0, 'placeholder')
61 85
     @tty.assert_row(1, '> tz')
62 86
     @tty.assert_row(2, '')
63 87
     @tty.assert_row(3, '')
88
+    @tty.assert_cursor_position(y: 1, x: 4)
89
+
90
+    @tty.send_keys("\r")
91
+    @tty.assert_row(0, 'placeholder')
92
+    @tty.assert_row(1, 'tz')
93
+    @tty.assert_cursor_position(y: 2, x: 0)
64 94
   end
65 95
 end
Browse code

Add ruby based integration test

John Hawthorn authored on 28/12/2016 07:38:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,65 @@
1
+require 'minitest'
2
+require 'minitest/autorun'
3
+require 'ttytest'
4
+
5
+class FzyTest < Minitest::Test
6
+  FZY_PATH = File.expand_path('../../../fzy', __FILE__)
7
+
8
+  def test_empty_list
9
+    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "" | fzy})
10
+    @tty.assert_row(0, 'placeholder')
11
+    @tty.assert_row(1, '>')
12
+    @tty.assert_row(2, '')
13
+
14
+    @tty.send_keys('t')
15
+    @tty.assert_row(0, 'placeholder')
16
+    @tty.assert_row(1, '> t')
17
+    @tty.assert_row(2, '')
18
+
19
+    @tty.send_keys('z')
20
+    @tty.assert_row(0, 'placeholder')
21
+    @tty.assert_row(1, '> tz')
22
+    @tty.assert_row(2, '')
23
+  end
24
+
25
+  def test_one_item
26
+    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test" | fzy})
27
+    @tty.assert_row(0, 'placeholder')
28
+    @tty.assert_row(1, '>')
29
+    @tty.assert_row(2, 'test')
30
+    @tty.assert_row(3, '')
31
+
32
+    @tty.send_keys('t')
33
+    @tty.assert_row(0, 'placeholder')
34
+    @tty.assert_row(1, '> t')
35
+    @tty.assert_row(2, 'test')
36
+    @tty.assert_row(3, '')
37
+
38
+    @tty.send_keys('z')
39
+    @tty.assert_row(0, 'placeholder')
40
+    @tty.assert_row(1, '> tz')
41
+    @tty.assert_row(2, '')
42
+    @tty.assert_row(3, '')
43
+  end
44
+
45
+  def test_two_items
46
+    @tty = TTYtest.driver.new_terminal(%{echo placeholder;echo -n "test\nfoo" | fzy})
47
+    @tty.assert_row(0, 'placeholder')
48
+    @tty.assert_row(1, '>')
49
+    @tty.assert_row(2, 'test')
50
+    @tty.assert_row(3, 'foo')
51
+    @tty.assert_row(4, '')
52
+
53
+    @tty.send_keys('t')
54
+    @tty.assert_row(0, 'placeholder')
55
+    @tty.assert_row(1, '> t')
56
+    @tty.assert_row(2, 'test')
57
+    @tty.assert_row(3, '')
58
+
59
+    @tty.send_keys('z')
60
+    @tty.assert_row(0, 'placeholder')
61
+    @tty.assert_row(1, '> tz')
62
+    @tty.assert_row(2, '')
63
+    @tty.assert_row(3, '')
64
+  end
65
+end