-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test surrogate pair filenames on windows
- Loading branch information
Mert Can Altin
committed
Feb 18, 2024
1 parent
fe22990
commit 4e0eaf3
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |