diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-05-23 19:54:08 +0200 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-05-23 19:54:08 +0200 |
commit | 8f8d34f03428dbaa6cac229bbe36efc6d80d186d (patch) | |
tree | c4c171ebf641d3aadc2ad2f3f741307040222a53 | |
parent | 399837108104b453b76603b9649d02987beb9090 (diff) | |
download | luasystem-8f8d34f03428dbaa6cac229bbe36efc6d80d186d.tar.gz luasystem-8f8d34f03428dbaa6cac229bbe36efc6d80d186d.tar.bz2 luasystem-8f8d34f03428dbaa6cac229bbe36efc6d80d186d.zip |
fix the final tests
-rw-r--r-- | spec/04-term_spec.lua | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua index e72a5ad..84b4731 100644 --- a/spec/04-term_spec.lua +++ b/spec/04-term_spec.lua | |||
@@ -177,7 +177,18 @@ describe("Terminal:", function() | |||
177 | describe("tcgetattr()", function() | 177 | describe("tcgetattr()", function() |
178 | 178 | ||
179 | nix_it("gets the terminal flags #manual", function() | 179 | nix_it("gets the terminal flags #manual", function() |
180 | assert.equal(true, false) -- implement this test still | 180 | local flags, err = system.tcgetattr(io.stdin) |
181 | assert.is_nil(err) | ||
182 | assert.is_table(flags) | ||
183 | assert.equals("bitflags:", tostring(flags.iflag):sub(1,9)) | ||
184 | assert.equals("bitflags:", tostring(flags.oflag):sub(1,9)) | ||
185 | assert.equals("bitflags:", tostring(flags.lflag):sub(1,9)) | ||
186 | assert.equals("bitflags:", tostring(flags.cflag):sub(1,9)) | ||
187 | assert.not_equal(0, flags.iflag:value()) | ||
188 | assert.not_equal(0, flags.oflag:value()) | ||
189 | assert.not_equal(0, flags.lflag:value()) | ||
190 | assert.not_equal(0, flags.cflag:value()) | ||
191 | assert.is.table(flags.cc) | ||
181 | end) | 192 | end) |
182 | 193 | ||
183 | 194 | ||
@@ -210,7 +221,43 @@ describe("Terminal:", function() | |||
210 | describe("tcsetattr()", function() | 221 | describe("tcsetattr()", function() |
211 | 222 | ||
212 | nix_it("sets the terminal flags, if called with flags #manual", function() | 223 | nix_it("sets the terminal flags, if called with flags #manual", function() |
213 | assert.equal(true, false) -- implement this test still | 224 | system.listtermflags(io.stdin) |
225 | local old_flags = assert(system.tcgetattr(io.stdin)) | ||
226 | finally(function() | ||
227 | system.tcsetattr(io.stdin, system.TCSANOW, old_flags) -- ensure we restore the original ones | ||
228 | end) | ||
229 | |||
230 | local new_flags = assert(system.tcgetattr(io.stdin)) -- just get them again, and then update | ||
231 | -- change iflags | ||
232 | local flag_to_change = system.I_IGNCR | ||
233 | if new_flags.iflag:has_all_of(flag_to_change) then | ||
234 | new_flags.iflag = new_flags.iflag - flag_to_change | ||
235 | else | ||
236 | new_flags.iflag = new_flags.iflag + flag_to_change | ||
237 | end | ||
238 | |||
239 | -- change oflags | ||
240 | flag_to_change = system.O_OPOST | ||
241 | if new_flags.oflag:has_all_of(flag_to_change) then | ||
242 | new_flags.oflag = new_flags.oflag - flag_to_change | ||
243 | else | ||
244 | new_flags.oflag = new_flags.oflag + flag_to_change | ||
245 | end | ||
246 | |||
247 | -- change lflags | ||
248 | flag_to_change = system.L_ECHO | ||
249 | if new_flags.lflag:has_all_of(flag_to_change) then | ||
250 | new_flags.lflag = new_flags.lflag - flag_to_change | ||
251 | else | ||
252 | new_flags.lflag = new_flags.lflag + flag_to_change | ||
253 | end | ||
254 | |||
255 | assert(system.tcsetattr(io.stdin, system.TCSANOW, new_flags)) | ||
256 | |||
257 | local updated_flags = assert(system.tcgetattr(io.stdin)) | ||
258 | assert.equals(new_flags.iflag:value(), updated_flags.iflag:value()) | ||
259 | assert.equals(new_flags.oflag:value(), updated_flags.oflag:value()) | ||
260 | assert.equals(new_flags.lflag:value(), updated_flags.lflag:value()) | ||
214 | end) | 261 | end) |
215 | 262 | ||
216 | 263 | ||