Browse code

Upgrade to ttytest 0.4.0

John Hawthorn authored on 31/12/2016 00:25:54
Showing 2 changed files

... ...
@@ -2,7 +2,7 @@ GEM
2 2
   remote: https://rubygems.org/
3 3
   specs:
4 4
     minitest (5.10.1)
5
-    ttytest (0.3.0)
5
+    ttytest (0.4.0)
6 6
 
7 7
 PLATFORMS
8 8
   ruby
... ...
@@ -12,4 +12,4 @@ DEPENDENCIES
12 12
   ttytest
13 13
 
14 14
 BUNDLED WITH
15
-   1.13.6
15
+   1.13.7
... ...
@@ -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