1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-10 01:10:30 +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:
Jonathan Coates 2024-07-24 19:34:34 +01:00
parent 63185629b7
commit f80373e7a2
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 6 additions and 3 deletions

View File

@ -8,7 +8,8 @@
-- @since 1.95.0
-- @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.
@ -32,7 +33,7 @@ local function wrap(text, width)
expect(1, text, "string")
expect(2, width, "number", "nil")
width = width or term.getSize()
range(width, 1)
local lines, lines_n, current_line = {}, 0, ""
local function push_line()

View File

@ -2,7 +2,7 @@
--
-- SPDX-License-Identifier: MPL-2.0
describe("cc.pretty", function()
describe("cc.strings", function()
local str = require("cc.strings")
describe("wrap", function()
@ -11,6 +11,8 @@ describe("cc.pretty", function()
str.wrap("test string is long", 11)
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, "", 0):eq("number outside of range (expected 0 to be within 1 and inf)")
end)
it("wraps lines", function()