mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-10 09:20:28 +00:00
Add bounds check to cc.strings.wrap
Fixes #1905, closes #1906. Co-authored-by: Lupus590 <lupussolitarius590@gmail.com>
This commit is contained in:
parent
63185629b7
commit
f80373e7a2
@ -8,7 +8,8 @@
|
|||||||
-- @since 1.95.0
|
-- @since 1.95.0
|
||||||
-- @see textutils For additional string related utilities.
|
-- @see textutils For additional string related utilities.
|
||||||
|
|
||||||
local expect = require("cc.expect").expect
|
local expect = require("cc.expect")
|
||||||
|
local expect, range = expect.expect, expect.range
|
||||||
|
|
||||||
--[[- Wraps a block of text, so that each line fits within the given width.
|
--[[- Wraps a block of text, so that each line fits within the given width.
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ local function wrap(text, width)
|
|||||||
expect(1, text, "string")
|
expect(1, text, "string")
|
||||||
expect(2, width, "number", "nil")
|
expect(2, width, "number", "nil")
|
||||||
width = width or term.getSize()
|
width = width or term.getSize()
|
||||||
|
range(width, 1)
|
||||||
|
|
||||||
local lines, lines_n, current_line = {}, 0, ""
|
local lines, lines_n, current_line = {}, 0, ""
|
||||||
local function push_line()
|
local function push_line()
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
--
|
--
|
||||||
-- SPDX-License-Identifier: MPL-2.0
|
-- SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
describe("cc.pretty", function()
|
describe("cc.strings", function()
|
||||||
local str = require("cc.strings")
|
local str = require("cc.strings")
|
||||||
|
|
||||||
describe("wrap", function()
|
describe("wrap", function()
|
||||||
@ -11,6 +11,8 @@ describe("cc.pretty", function()
|
|||||||
str.wrap("test string is long", 11)
|
str.wrap("test string is long", 11)
|
||||||
expect.error(str.wrap, nil):eq("bad argument #1 (string expected, got nil)")
|
expect.error(str.wrap, nil):eq("bad argument #1 (string expected, got nil)")
|
||||||
expect.error(str.wrap, "", false):eq("bad argument #2 (number expected, got boolean)")
|
expect.error(str.wrap, "", false):eq("bad argument #2 (number expected, got boolean)")
|
||||||
|
|
||||||
|
expect.error(str.wrap, "", 0):eq("number outside of range (expected 0 to be within 1 and inf)")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("wraps lines", function()
|
it("wraps lines", function()
|
||||||
|
Loading…
Reference in New Issue
Block a user