mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 22:02:27 +00:00
Do some work on redbean
- Rewrite Slurp() API to be like string.sub() - Introduce a new Barf() API for creating files - Update Redbean `-S` sandbox flag to do unveiling
This commit is contained in:
parent
742251dd92
commit
48ce3ad7cc
9 changed files with 296 additions and 33 deletions
50
test/tool/net/slurp_test.lua
Normal file
50
test/tool/net/slurp_test.lua
Normal file
|
@ -0,0 +1,50 @@
|
|||
-- Copyright 2022 Justine Alexandra Roberts Tunney
|
||||
--
|
||||
-- Permission to use, copy, modify, and/or distribute this software for
|
||||
-- any purpose with or without fee is hereby granted, provided that the
|
||||
-- above copyright notice and this permission notice appear in all copies.
|
||||
--
|
||||
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
-- WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
-- WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||
-- AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
-- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
-- PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
-- TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
-- PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
tmpdir = "o/tmp/lunix_test.%d" % {unix.getpid()}
|
||||
|
||||
local function Path(name)
|
||||
return tmpdir .. '/' .. name
|
||||
end
|
||||
|
||||
local function SlurpTest()
|
||||
|
||||
data = 'abc123' * 5000
|
||||
assert(Barf(Path('foo'), data))
|
||||
assert(assert(Slurp(Path('foo'))) == data)
|
||||
assert(assert(Slurp(Path('foo'), 2, 3)) == 'bc')
|
||||
assert(assert(Slurp(Path('foo'), 2)) == data:sub(2))
|
||||
assert(assert(Slurp(Path('foo'), 2, 1)) == data:sub(2, 1))
|
||||
assert(assert(Slurp(Path('foo'), 2, 2)) == data:sub(2, 2))
|
||||
assert(assert(Slurp(Path('foo'), 1, 2)) == data:sub(1, 2))
|
||||
assert(assert(Slurp(Path('foo'), -3, -1)) == data:sub(-3, -1))
|
||||
|
||||
assert(Barf(Path('foo'), 'XX', 0, 0, 3))
|
||||
assert(assert(Slurp(Path('foo'), 1, 6)) == 'abXX23')
|
||||
|
||||
end
|
||||
|
||||
local function main()
|
||||
assert(unix.makedirs(tmpdir))
|
||||
ok, err = pcall(SlurpTest)
|
||||
if ok then
|
||||
assert(unix.rmrf(tmpdir))
|
||||
else
|
||||
print(err)
|
||||
error('SlurpTest failed (%s)' % {tmpdir})
|
||||
end
|
||||
end
|
||||
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue