diff --git a/tests/fs/copy.luau b/tests/fs/copy.luau index c7ed6dd..1b52320 100644 --- a/tests/fs/copy.luau +++ b/tests/fs/copy.luau @@ -50,15 +50,15 @@ assert(fs.isFile(TEMP_ROOT_PATH_2 .. "/foo/buzz"), "Missing copied file - root/f -- Make sure the copied files are correct assert( - fs.readFile(TEMP_ROOT_PATH_2 .. "/foo/bar/baz") == utils.binaryBlob, + fs.readFile(TEMP_ROOT_PATH_2 .. "/foo/bar/baz") == buffer.tostring(utils.binaryBlob), "Invalid copied file - root/foo/bar/baz" ) assert( - fs.readFile(TEMP_ROOT_PATH_2 .. "/foo/fizz") == utils.binaryBlob, + fs.readFile(TEMP_ROOT_PATH_2 .. "/foo/fizz") == buffer.tostring(utils.binaryBlob), "Invalid copied file - root/foo/fizz" ) assert( - fs.readFile(TEMP_ROOT_PATH_2 .. "/foo/buzz") == utils.binaryBlob, + fs.readFile(TEMP_ROOT_PATH_2 .. "/foo/buzz") == buffer.tostring(utils.binaryBlob), "Invalid copied file - root/foo/buzz" ) diff --git a/tests/fs/files.luau b/tests/fs/files.luau index a49412e..38b7485 100644 --- a/tests/fs/files.luau +++ b/tests/fs/files.luau @@ -11,6 +11,8 @@ fs.writeDir(TEMP_ROOT_PATH) -- Write both of our files +-- binaryBlob is of type buffer to make sure fs.writeFile +-- works with both strings and buffers fs.writeFile(TEMP_ROOT_PATH .. "/test_binary", utils.binaryBlob) fs.writeFile(TEMP_ROOT_PATH .. "/test_json.json", utils.jsonBlob) @@ -18,7 +20,7 @@ fs.writeFile(TEMP_ROOT_PATH .. "/test_json.json", utils.jsonBlob) -- wrote gets us back the original strings assert( - fs.readFile(TEMP_ROOT_PATH .. "/test_binary") == utils.binaryBlob, + fs.readFile(TEMP_ROOT_PATH .. "/test_binary") == buffer.tostring(utils.binaryBlob), "Binary file round-trip resulted in different strings" ) diff --git a/tests/fs/metadata.luau b/tests/fs/metadata.luau index e926a2c..8a5a795 100644 --- a/tests/fs/metadata.luau +++ b/tests/fs/metadata.luau @@ -45,7 +45,7 @@ assert(metaFile.kind == "file", "File metadata kind was invalid") local metaBefore = fs.metadata(TEMP_FILE_PATH) task.wait(1) -fs.writeFile(TEMP_FILE_PATH, utils.binaryBlob .. "\n") +fs.writeFile(TEMP_FILE_PATH, buffer.tostring(utils.binaryBlob) .. "\n") local metaAfter = fs.metadata(TEMP_FILE_PATH) assert( diff --git a/tests/fs/move.luau b/tests/fs/move.luau index 868a095..749c8cb 100644 --- a/tests/fs/move.luau +++ b/tests/fs/move.luau @@ -20,7 +20,7 @@ fs.move("bin/move_test_json.json", "bin/moved_test_json.json") -- wrote gets us back the original strings assert( - fs.readFile("bin/moved_test_binary") == utils.binaryBlob, + fs.readFile("bin/moved_test_binary") == buffer.tostring(utils.binaryBlob), "Binary file round-trip resulted in different strings" ) diff --git a/tests/fs/utils.luau b/tests/fs/utils.luau index a5a947e..89a6964 100644 --- a/tests/fs/utils.luau +++ b/tests/fs/utils.luau @@ -16,6 +16,6 @@ local jsonBlob = serde.encode("json", { -- Return testing data and utils return { - binaryBlob = binaryBlob, + binaryBlob = buffer.fromstring(binaryBlob), jsonBlob = jsonBlob, } diff --git a/tests/net/socket/wss_rw.luau b/tests/net/socket/wss_rw.luau index 8ae6066..fefb244 100644 --- a/tests/net/socket/wss_rw.luau +++ b/tests/net/socket/wss_rw.luau @@ -22,7 +22,9 @@ end) task.wait(1) -socket.send('{"op":1,"d":null}') +local payload = '{"op":1,"d":null}' +socket.send(payload) +socket.send(buffer.fromstring(payload)) socket.close(1000) task.cancel(delayedThread) diff --git a/tests/serde/compression/files.luau b/tests/serde/compression/files.luau index 8d41492..44bdc50 100644 --- a/tests/serde/compression/files.luau +++ b/tests/serde/compression/files.luau @@ -33,69 +33,60 @@ local TESTS: { Test } = { } local failed = false -for _, test in TESTS do - local source = fs.readFile(test.Source) - local target = fs.readFile(test.Target) - - local success, compressed = pcall(serde.compress, test.Format, source) +local function testOperation( + operationName: string, + operation: ( + format: serde.CompressDecompressFormat, + s: buffer | string + ) -> string, + format: serde.CompressDecompressFormat, + source: string | buffer, + target: string +) + local success, res = pcall(operation, format, source) if not success then stdio.ewrite( string.format( - "Compressing source using '%s' format threw an error!\n%s", - tostring(test.Format), - tostring(compressed) + "%sing source using '%s' format threw an error!\n%s", + operationName, + tostring(format), + tostring(res) ) ) failed = true - continue - elseif compressed ~= target then + elseif res ~= target then stdio.ewrite( string.format( - "Compressing source using '%s' format did not produce target!\n", - tostring(test.Format) + "%sing source using '%s' format did not produce target!\n", + operationName, + tostring(format) ) ) stdio.ewrite( string.format( - "Compressed (%d chars long):\n%s\nTarget (%d chars long):\n%s\n\n", - #compressed, - tostring(compressed), + "%sed (%d chars long):\n%s\nTarget (%d chars long):\n%s\n\n", + operationName, + #res, + tostring(res), #target, tostring(target) ) ) failed = true - continue end +end - local success2, decompressed = pcall(serde.decompress, test.Format, target) - if not success2 then - stdio.ewrite( - string.format( - "Decompressing source using '%s' format threw an error!\n%s", - tostring(test.Format), - tostring(decompressed) - ) - ) - failed = true - continue - elseif decompressed ~= source then - stdio.ewrite( - string.format( - "Decompressing target using '%s' format did not produce source!\n", - tostring(test.Format) - ) - ) - stdio.ewrite( - string.format( - "Decompressed (%d chars long):\n%s\n\n", - #decompressed, - tostring(decompressed) - ) - ) - failed = true - continue - end +for _, test in TESTS do + local source = fs.readFile(test.Source) + local target = fs.readFile(test.Target) + + -- Compression + testOperation("Compress", serde.compress, test.Format, source, target) + testOperation("Compress", serde.compress, test.Format, buffer.fromstring(source), target) + + -- Decompression + testOperation("Decompress", serde.decompress, test.Format, target, source) + testOperation("Decompress", serde.decompress, test.Format, buffer.fromstring(target), source) end if failed then