aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThijs <thijs@thijsschreijer.nl>2024-05-21 20:06:21 +0200
committerThijs <thijs@thijsschreijer.nl>2024-05-21 20:06:21 +0200
commit1ed4a7325932192da7ec98318a4841752d2a952a (patch)
tree30e69ad41b9d354b20ffd958de1b8e02db8207a5
parent52367bec91db06afaad8ed9c173e9fe0c50ec864 (diff)
downloadluasystem-1ed4a7325932192da7ec98318a4841752d2a952a.tar.gz
luasystem-1ed4a7325932192da7ec98318a4841752d2a952a.tar.bz2
luasystem-1ed4a7325932192da7ec98318a4841752d2a952a.zip
add tests get/setconsolecp, and get/setconsoleoutputcp
-rw-r--r--spec/04-term_spec.lua96
1 files changed, 87 insertions, 9 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua
index 77d2ce3..83750ec 100644
--- a/spec/04-term_spec.lua
+++ b/spec/04-term_spec.lua
@@ -140,7 +140,7 @@ describe("Terminal:", function()
140 win_it("sets the consoleflags #manual", function() 140 win_it("sets the consoleflags #manual", function()
141 local old_flags = assert(system.getconsoleflags(io.stdout)) 141 local old_flags = assert(system.getconsoleflags(io.stdout))
142 finally(function() 142 finally(function()
143 system.setconsoleflags(io.stdout, old_flags) 143 system.setconsoleflags(io.stdout, old_flags) -- ensure we restore the original ones
144 end) 144 end)
145 145
146 local new_flags 146 local new_flags
@@ -192,36 +192,114 @@ describe("Terminal:", function()
192 192
193 193
194 194
195 pending("getconsolecp()", function() 195 describe("getconsolecp()", function()
196 196
197 pending("sets the consoleflags, if called with flags", function() 197 win_it("gets the console codepage", function()
198 local cp, err = system.getconsolecp()
199 assert.is_nil(err)
200 assert.is_number(cp)
201 end)
202
203 nix_it("gets the console codepage, always 65001 (utf8)", function()
204 local cp, err = system.getconsolecp()
205 assert.is_nil(err)
206 assert.equals(65001, cp)
198 end) 207 end)
199 208
200 end) 209 end)
201 210
202 211
203 212
204 pending("setconsolecp()", function() 213 describe("setconsolecp()", function()
205 214
206 pending("sets the consoleflags, if called with flags", function() 215 win_it("sets the console codepage", function()
216 local old_cp = assert(system.getconsolecp())
217 finally(function()
218 system.setconsolecp(old_cp) -- ensure we restore the original one
219 end)
220
221 local new_cp
222 if old_cp ~= 65001 then
223 new_cp = 65001 -- set to UTF8
224 else
225 new_cp = 850 -- another common one
226 end
227
228 local success, err = system.setconsolecp(new_cp)
229 assert.is_nil(err)
230 assert.is_true(success)
231
232 local updated_cp = assert(system.getconsolecp())
233 assert.equals(new_cp, updated_cp)
234 end)
235
236
237 nix_it("sets the console codepage, always succeeds", function()
238 assert(system.setconsolecp(850))
239 end)
240
241
242 it("returns an error if called with an invalid argument", function()
243 assert.has.error(function()
244 system.setconsolecp("invalid")
245 end, "bad argument #1 to 'setconsolecp' (number expected, got string)")
207 end) 246 end)
208 247
209 end) 248 end)
210 249
211 250
212 251
213 pending("getconsoleoutputcp()", function() 252 describe("getconsoleoutputcp()", function()
214 253
215 pending("sets the consoleflags, if called with flags", function() 254 win_it("gets the console output codepage", function()
255 local cp, err = system.getconsoleoutputcp()
256 assert.is_nil(err)
257 assert.is_number(cp)
258 end)
259
260 nix_it("gets the console output codepage, always 65001 (utf8)", function()
261 local cp, err = system.getconsoleoutputcp()
262 assert.is_nil(err)
263 assert.equals(65001, cp)
216 end) 264 end)
217 265
218 end) 266 end)
219 267
220 268
221 269
222 pending("setconsoleoutputcp()", function() 270 describe("setconsoleoutputcp()", function()
223 271
224 pending("sets the consoleflags, if called with flags", function() 272 win_it("sets the console output codepage", function()
273 local old_cp = assert(system.getconsoleoutputcp())
274 finally(function()
275 system.setconsoleoutputcp(old_cp) -- ensure we restore the original one
276 end)
277
278 local new_cp
279 if old_cp ~= 65001 then
280 new_cp = 65001 -- set to UTF8
281 else
282 new_cp = 850 -- another common one
283 end
284
285 local success, err = system.setconsoleoutputcp(new_cp)
286 assert.is_nil(err)
287 assert.is_true(success)
288
289 local updated_cp = assert(system.getconsoleoutputcp())
290 assert.equals(new_cp, updated_cp)
291 end)
292
293
294 nix_it("sets the console output codepage, always succeeds", function()
295 assert(system.setconsoleoutputcp(850))
296 end)
297
298
299 it("returns an error if called with an invalid argument", function()
300 assert.has.error(function()
301 system.setconsoleoutputcp("invalid")
302 end, "bad argument #1 to 'setconsoleoutputcp' (number expected, got string)")
225 end) 303 end)
226 304
227 end) 305 end)