mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
97c29def52
We previously used a text that appears to be an excerpt of https://zh.wikipedia.org/wiki/%E5%8D%97%E8%B6%8A%E5%9B%BD and can have copyright/license complications. It may also include some geopolitical nuances. The text has been repeated through out the code base without much reuse. This patch consolidates the fixtures by adding a common helper string as `fixtures.utf8TestText` which is identical to a copy in test/fixtures/utf8_test_text.txt. It also updates the text to a copy of 蘭亭集序, It was chosen because: 1. It's a well-known Chinese classical piece written in 353 CE and therefore in public domain. The string is copied from https://zh.wikisource.org/zh-hant/%E8%98%AD%E4%BA%AD%E9%9B%86%E5%BA%8F which contains a disclaimer of copyright for this reason. 2. The text is in suitable length for general UTF8 string read/write tests (including punctuations, 389 code points and 1167 bytes). 3. This is also commonly used as reference text for Chinese text layout tests. 4. It's a timeless and harmless preface for a collection of poems, written by a uncontroversial figure who passed away >1600 years ago and contains no geopolitical nuances. Background and an English translation of this text can be found at https://en.wikipedia.org/wiki/Lantingji_Xu PR-URL: https://github.com/nodejs/node/pull/50732 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
tmpdir.refresh();
|
|
|
|
const filename = tmpdir.resolve('test.txt');
|
|
const fixtures = require('../common/fixtures');
|
|
const s = fixtures.utf8TestText;
|
|
|
|
// The length of the buffer should be a multiple of 8
|
|
// as required by common.getArrayBufferViews()
|
|
const inputBuffer = Buffer.from(s.repeat(8), 'utf8');
|
|
|
|
for (const expectView of common.getArrayBufferViews(inputBuffer)) {
|
|
console.log('Sync test for ', expectView[Symbol.toStringTag]);
|
|
fs.writeFileSync(filename, expectView);
|
|
assert.strictEqual(
|
|
fs.readFileSync(filename, 'utf8'),
|
|
inputBuffer.toString('utf8')
|
|
);
|
|
}
|
|
|
|
for (const expectView of common.getArrayBufferViews(inputBuffer)) {
|
|
console.log('Async test for ', expectView[Symbol.toStringTag]);
|
|
const file = `${filename}-${expectView[Symbol.toStringTag]}`;
|
|
fs.writeFile(file, expectView, common.mustSucceed(() => {
|
|
fs.readFile(file, 'utf8', common.mustSucceed((data) => {
|
|
assert.strictEqual(data, inputBuffer.toString('utf8'));
|
|
}));
|
|
}));
|
|
}
|