From dc4c7150a4d1ab3536c24be8593267d34f721e38 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sun, 18 Feb 2024 18:46:43 +0300 Subject: [PATCH] test: Test surrogate pair filenames on windows --- ...ile-ops-with-surrogate-pairs-on-windows.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/common/file-ops-with-surrogate-pairs-on-windows.js diff --git a/test/common/file-ops-with-surrogate-pairs-on-windows.js b/test/common/file-ops-with-surrogate-pairs-on-windows.js new file mode 100644 index 00000000000000..31b596147c893c --- /dev/null +++ b/test/common/file-ops-with-surrogate-pairs-on-windows.js @@ -0,0 +1,49 @@ +'use strict'; + +const fs = require('fs'); +const { describe, it } = require('node:test'); +const assert = require('assert').strict; +const os = require('os'); +const path = require('path'); + +describe('File operations with filenames containing surrogate pairs on Windows', () => { + it('should write, read, and delete a file with surrogate pairs in the filename', () => { + // Create a temporary directory + const tempdir = fs.mkdtempSync(path.join(os.tmpdir(), 'emoji-fruit-🍇 🍈 🍉 🍊 🍋')); + assert.strictEqual(fs.existsSync(tempdir), true); + + const filename = '🚀🔥🛸.txt'; + const content = 'Test content'; + + // Write content to a file + fs.writeFileSync(path.join(tempdir, filename), content); + + // Read content from the file + const readContent = fs.readFileSync(path.join(tempdir, filename), 'utf8'); + + // Check if the content matches + assert.strictEqual(readContent, content); + + // Get directory contents + const dirs = fs.readdirSync(tempdir); + assert.strictEqual(dirs.length > 0, true); + + // Check if the file is in the directory contents + let match = false; + for (let i = 0; i < dirs.length; i++) { + if (dirs[i].endsWith(filename)) { + match = true; + break; + } + } + assert.strictEqual(match, true); + + // Delete the file + fs.unlinkSync(path.join(tempdir, filename)); + assert.strictEqual(fs.existsSync(path.join(tempdir, filename)), false); + + // Remove the temporary directory + fs.rmdirSync(tempdir); + assert.strictEqual(fs.existsSync(tempdir), false); + }); +});