aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/04-term_spec.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua
index 813947a..907f903 100644
--- a/spec/04-term_spec.lua
+++ b/spec/04-term_spec.lua
@@ -511,11 +511,18 @@ describe("Terminal:", function()
511 511
512 describe("utf8cwidth()", function() 512 describe("utf8cwidth()", function()
513 513
514 -- utf-8 strings
514 local ch1 = string.char(226, 130, 172) -- "€" single 515 local ch1 = string.char(226, 130, 172) -- "€" single
515 local ch2 = string.char(240, 159, 154, 128) -- "🚀" double 516 local ch2 = string.char(240, 159, 154, 128) -- "🚀" double
516 local ch3 = string.char(228, 189, 160) -- "你" double 517 local ch3 = string.char(228, 189, 160) -- "你" double
517 local ch4 = string.char(229, 165, 189) -- "好" double 518 local ch4 = string.char(229, 165, 189) -- "好" double
518 519
520 -- unicode codepoints
521 local cp1 = 8364 -- "€" single
522 local cp2 = 128640 -- "🚀" double
523 local cp3 = 20320 -- "你" double
524 local cp4 = 22909 -- "好" double
525
519 it("handles zero width characters", function() 526 it("handles zero width characters", function()
520 assert.same({0}, {system.utf8cwidth("")}) -- empty string returns 0-size 527 assert.same({0}, {system.utf8cwidth("")}) -- empty string returns 0-size
521 assert.same({nil, 'Character width determination failed'}, {system.utf8cwidth("\a")}) -- bell character 528 assert.same({nil, 'Character width determination failed'}, {system.utf8cwidth("\a")}) -- bell character
@@ -539,6 +546,24 @@ describe("Terminal:", function()
539 assert.same({2}, {system.utf8cwidth(ch2 .. ch3 .. ch4)}) 546 assert.same({2}, {system.utf8cwidth(ch2 .. ch3 .. ch4)})
540 end) 547 end)
541 548
549 it("handles integer codepoints", function()
550 assert.same({1}, {system.utf8cwidth(cp1)})
551 assert.same({2}, {system.utf8cwidth(cp2)})
552 assert.same({2}, {system.utf8cwidth(cp3)})
553 assert.same({2}, {system.utf8cwidth(cp4)})
554 end)
555
556 it("returns an error on bad argument", function()
557 assert.has.error(function()
558 system.utf8cwidth(true)
559 end, "bad argument #1 to 'utf8cwidth' (Expected UTF-8-string or codepoint-integer as first argument)")
560 end)
561
562 it("returns an error on bad unicode values", function()
563 assert.same({nil, "Invalid Unicode codepoint"}, {system.utf8cwidth(-10)})
564 assert.same({nil, "Invalid Unicode codepoint"}, {system.utf8cwidth(999999999999)})
565 end)
566
542 end) 567 end)
543 568
544 569