Files
factorio-clusterio/test/lib/lua_tools.js
T
Hornwitser 24397b75cc Prefix clusterio/lib imports with lib
Use lib* prefix for the modules impored from the lib package to help
distinguish them more from ordinary variables.  Fix up the naming
convention for files to be consistently lowercase_underscore for
JavaScript files.
2020-10-23 21:22:43 +02:00

32 lines
1.0 KiB
JavaScript

"use strict";
const assert = require("assert").strict;
const libLuaTools = require("@clusterio/lib/lua_tools");
describe("lib/lua_tools", function() {
describe("escapeString()", function() {
it("should escape backslashes", function() {
assert.equal(libLuaTools.escapeString("\\a"), "\\\\a");
});
it("should escape double quotes", function() {
assert.equal(libLuaTools.escapeString('"a"'), '\\"a\\"');
});
it("should escape single quotes", function() {
assert.equal(libLuaTools.escapeString("'a'"), "\\'a\\'");
});
it("should escape nul bytes", function() {
assert.equal(libLuaTools.escapeString("a\0b"), "a\\0b");
});
it("should escape newlines", function() {
assert.equal(libLuaTools.escapeString("a\nb"), "a\\nb");
});
it("should escape carriage return", function() {
assert.equal(libLuaTools.escapeString("a\rb"), "a\\rb");
});
it("should escape all combined", function() {
assert.equal(libLuaTools.escapeString("a\\b\"c'd\0e\nf\rg"), "a\\\\b\\\"c\\'d\\0e\\nf\\rg");
});
});
});