aboutsummaryrefslogtreecommitdiff
path: root/spec/04-term_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/04-term_spec.lua')
-rw-r--r--spec/04-term_spec.lua77
1 files changed, 74 insertions, 3 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua
index 907f903..5dea046 100644
--- a/spec/04-term_spec.lua
+++ b/spec/04-term_spec.lua
@@ -855,6 +855,32 @@ describe("Terminal:", function()
855 assert.is.near(1, timing, 0.5) -- this also works for MacOS in CI 855 assert.is.near(1, timing, 0.5) -- this also works for MacOS in CI
856 end) 856 end)
857 857
858
859 it("calls flseep to execute the sleep", function()
860 setbuffer("")
861
862 local sleep_called = false
863 local mysleep = function()
864 sleep_called = true
865 end
866
867 system.readkey(0.01, mysleep)
868 assert.is_true(sleep_called)
869 end)
870
871
872 it("returns errors by fsleep", function()
873 setbuffer("")
874
875 local mysleep = function()
876 return nil, "boom!"
877 end
878
879 local ok, err = system.readkey(1, mysleep)
880 assert.is.falsy(ok)
881 assert.equals("boom!", err)
882 end)
883
858 end) 884 end)
859 885
860 886
@@ -876,6 +902,14 @@ describe("Terminal:", function()
876 end) 902 end)
877 903
878 904
905 it("reads a control byte for single-byte control characters", function()
906 setbuffer("\000\031\127")
907 assert.are.same({"\000", "ctrl"}, {system.readansi(0)})
908 assert.are.same({"\031", "ctrl"}, {system.readansi(0)})
909 assert.are.same({"\127", "ctrl"}, {system.readansi(0)})
910 end)
911
912
879 it("reads a multi-byte characters one at a time", function() 913 it("reads a multi-byte characters one at a time", function()
880 setbuffer(string.char(226, 130, 172) .. -- "€" single 914 setbuffer(string.char(226, 130, 172) .. -- "€" single
881 string.char(240, 159, 154, 128)) -- "🚀" double 915 string.char(240, 159, 154, 128)) -- "🚀" double
@@ -902,10 +936,31 @@ describe("Terminal:", function()
902 end) 936 end)
903 937
904 938
939 it("reads ANSI escape sequences, just an '<esc>O' (<alt><O> key press)", function()
940 setbuffer("\27O")
941 assert.are.same({"\27O", "ansi"}, {system.readansi(0)})
942 end)
943
944
945 it("reads <alt>+key key presses; <esc>+<key>", function()
946 setbuffer("\27a\27b\27c\27d")
947 assert.are.same({"\27a", "ansi"}, {system.readansi(0)})
948 assert.are.same({"\27b", "ansi"}, {system.readansi(0)})
949 assert.are.same({"\27c", "ansi"}, {system.readansi(0)})
950 assert.are.same({"\27d", "ansi"}, {system.readansi(0)})
951 end)
952
953
954 it("reads <ctrl><alt>[ key press; <esc>+<esc>", function()
955 setbuffer("\27\27\27\27")
956 assert.are.same({"\27\27", "ansi"}, {system.readansi(0)})
957 assert.are.same({"\27\27", "ansi"}, {system.readansi(0)})
958 end)
959
960
905 it("returns a single <esc> character if no sequence is found", function() 961 it("returns a single <esc> character if no sequence is found", function()
906 setbuffer("\27\27[A") 962 setbuffer("\27")
907 assert.are.same({"\27", "char"}, {system.readansi(0)}) 963 assert.are.same({"\27", "ctrl"}, {system.readansi(0)})
908 assert.are.same({"\27[A", "ansi"}, {system.readansi(0)})
909 end) 964 end)
910 965
911 966
@@ -919,6 +974,22 @@ describe("Terminal:", function()
919 assert.is.near(1, timing, 0.5) -- this also works for MacOS in CI 974 assert.is.near(1, timing, 0.5) -- this also works for MacOS in CI
920 end) 975 end)
921 976
977
978 it("incomplete ANSI sequences will be completed on next call", function()
979 setbuffer("\27[")
980 assert.are.same({nil, "timeout", "\27["}, {system.readansi(0)})
981 setbuffer("A")
982 assert.are.same({"\27[A", "ansi"}, {system.readansi(0)})
983 end)
984
985
986 it("incomplete UTF8 sequences will be completed on next call", function()
987 setbuffer(string.char(240, 159))
988 assert.are.same({nil, "timeout", string.char(240, 159)}, {system.readansi(0)})
989 setbuffer(string.char(154, 128))
990 assert.are.same({"🚀", "char"}, {system.readansi(0)})
991 end)
992
922 end) 993 end)
923 994
924 end) 995 end)