Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
83
Frontend-Learner/node_modules/copy-paste/test/copypaste.js
generated
vendored
Normal file
83
Frontend-Learner/node_modules/copy-paste/test/copypaste.js
generated
vendored
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
const assert = require("node:assert");
|
||||
const { describe, it } = require("node:test");
|
||||
const clipboard = require("../index.js");
|
||||
const clipboardPromises = require("../promises.js");
|
||||
|
||||
const tests = [
|
||||
{
|
||||
text: "123456789abcdefghijklmnopqrstuvwxyz+-=&_[]<^=>=/{:})-{(`)}",
|
||||
description: "ascii chars (<128)",
|
||||
},
|
||||
{ text: "ÉæÆôöòûùÿÖÜ¢£¥₧ƒ", description: "cp437 chars (<256)" },
|
||||
{ text: "ĀāĂ㥹ĆćĈĉĊċČčĎ ፰፱፲፳፴፵፶፷፸፹፺፻፼", description: "unicode chars (<2^16)" },
|
||||
{ text: "±", description: "special chars" },
|
||||
{ text: "你好,我是中文", description: "chinese chars" },
|
||||
];
|
||||
|
||||
function copyAndPasteAsync(content) {
|
||||
return new Promise((resolve, reject) => {
|
||||
clipboard.copy(content, (errorWhenCopy) => {
|
||||
if (errorWhenCopy) return reject(errorWhenCopy);
|
||||
|
||||
clipboard.paste((errorWhenPaste, p) => {
|
||||
if (errorWhenPaste) return reject(errorWhenPaste);
|
||||
|
||||
resolve(p);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe("copy and paste", () => {
|
||||
for (const { text, description } of tests) {
|
||||
it(`should work correctly with ${description}`, async () => {
|
||||
const result = await copyAndPasteAsync(text);
|
||||
assert.ok(result);
|
||||
assert.strictEqual(result, text);
|
||||
});
|
||||
}
|
||||
|
||||
it("should work correctly with JSON", async () => {
|
||||
const obj = { name: "John", age: 30 };
|
||||
const expectedText = `{\n\t"name": "John",\n\t"age": 30\n}`;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
clipboard.copy.json(obj, (err, text) => {
|
||||
if (err) return reject(err);
|
||||
|
||||
assert.ok(text);
|
||||
assert.strictEqual(text, expectedText);
|
||||
|
||||
clipboard.paste((err, text) => {
|
||||
if (err) return reject(err);
|
||||
|
||||
assert.ok(text);
|
||||
assert.strictEqual(text, expectedText);
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("promise-based copy and paste", () => {
|
||||
for (const { text, description } of tests) {
|
||||
it(`should work correctly with ${description}`, async () => {
|
||||
await clipboardPromises.copy(text);
|
||||
const result = await clipboardPromises.paste();
|
||||
assert.ok(result);
|
||||
assert.strictEqual(result, text);
|
||||
});
|
||||
}
|
||||
|
||||
it("should work correctly with JSON", async () => {
|
||||
const obj = { name: "John", age: 30 };
|
||||
const expectedText = `{\n\t"name": "John",\n\t"age": 30\n}`;
|
||||
|
||||
await clipboardPromises.copy.json(obj);
|
||||
const result = await clipboardPromises.paste();
|
||||
assert.ok(result);
|
||||
assert.strictEqual(result, expectedText);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue