mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Migrate the usage of CommonJS specific code and imports to ESM. Roughly summarised this: - Changes all require() calls to import statement or expressions. - Changes usage of module.exports to export statements. - Replaces require.resolve with import.meta.resolve. - Replaces conditional imports with conditional subpath imports. - Replaces module === require.main with import.meta.main. - Adds the full filename with extention to all relative imports. - Changes all usage of __dirname and __filename to their import.meta equivalents. - Sets "type": "module" in package.json files. - Removes usage of "use strict". - Adds .ts an an alias of .js for the webpack build. Due to differences in how require and import resolves files the plugin entrypoints will have to include the filename and extension after this migration in order to work.
50 lines
2.1 KiB
JavaScript
50 lines
2.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
|
|
import * as lib from "@clusterio/lib";
|
|
|
|
|
|
describe("lib/lua_tools", function() {
|
|
describe("normalizeColor()", function() {
|
|
it("should normalise colours according to the documentation", function() {
|
|
const nc = lib.normalizeColor;
|
|
assert.deepEqual(nc({ r: 1, g: 0.2, b: 0.4, a: 0.8 }), { r: 1, g: 0.2, b: 0.4, a: 0.8 });
|
|
assert.deepEqual(nc({ r: 1, g: 0.2, b: 0.4 }), { r: 1, g: 0.2, b: 0.4, a: 1 });
|
|
assert.deepEqual(nc({ r: 1, b: 0.4 }), { r: 1, g: 0, b: 0.4, a: 1 });
|
|
assert.deepEqual(nc({ a: 0.4 }), { r: 0, g: 0, b: 0, a: 0.4 });
|
|
assert.deepEqual(nc({}), { r: 0, g: 0, b: 0, a: 1 });
|
|
assert.deepEqual(nc([1, 0.2, 0.4, 0.8]), { r: 1, g: 0.2, b: 0.4, a: 0.8 });
|
|
assert.deepEqual(nc([1, 0.2, 0.4]), { r: 1, g: 0.2, b: 0.4, a: 1 });
|
|
assert.deepEqual(nc({ r: 255, g: 51, b: 102, a: 204 }), { r: 1, g: 0.2, b: 0.4, a: 0.8 });
|
|
assert.deepEqual(nc({ r: 255, g: 51, b: 102 }), { r: 1, g: 0.2, b: 0.4, a: 1 });
|
|
assert.deepEqual(nc({ r: 255, b: 102 }), { r: 1, g: 0, b: 0.4, a: 1 });
|
|
assert.deepEqual(nc({ a: 102 }), { r: 0, g: 0, b: 0, a: 0.4 });
|
|
assert.deepEqual(nc({}), { r: 0, g: 0, b: 0, a: 1 });
|
|
assert.deepEqual(nc([255, 51, 102, 204]), { r: 1, g: 0.2, b: 0.4, a: 0.8 });
|
|
assert.deepEqual(nc([255, 51, 102]), { r: 1, g: 0.2, b: 0.4, a: 1 });
|
|
});
|
|
});
|
|
describe("escapeString()", function() {
|
|
it("should escape backslashes", function() {
|
|
assert.equal(lib.escapeString("\\a"), "\\\\a");
|
|
});
|
|
it("should escape double quotes", function() {
|
|
assert.equal(lib.escapeString('"a"'), '\\"a\\"');
|
|
});
|
|
it("should escape single quotes", function() {
|
|
assert.equal(lib.escapeString("'a'"), "\\'a\\'");
|
|
});
|
|
it("should escape nul bytes", function() {
|
|
assert.equal(lib.escapeString("a\0b"), "a\\0b");
|
|
});
|
|
it("should escape newlines", function() {
|
|
assert.equal(lib.escapeString("a\nb"), "a\\nb");
|
|
});
|
|
it("should escape carriage return", function() {
|
|
assert.equal(lib.escapeString("a\rb"), "a\\rb");
|
|
});
|
|
it("should escape all combined", function() {
|
|
assert.equal(lib.escapeString("a\\b\"c'd\0e\nf\rg"), "a\\\\b\\\"c\\'d\\0e\\nf\\rg");
|
|
});
|
|
});
|
|
});
|