mirror of
https://github.com/thelounge/thelounge
synced 2024-11-22 12:03:11 +00:00
parent
257ce5d0a8
commit
295b3a4251
2 changed files with 13 additions and 0 deletions
|
@ -71,6 +71,8 @@ class Utils {
|
||||||
return undefined;
|
return undefined;
|
||||||
} else if (value === "null") {
|
} else if (value === "null") {
|
||||||
return null;
|
return null;
|
||||||
|
} else if (/^-?[0-9]+$/.test(value)) { // Numbers like port
|
||||||
|
value = parseInt(value, 10);
|
||||||
} else if (/^\[.*\]$/.test(value)) { // Arrays
|
} else if (/^\[.*\]$/.test(value)) { // Arrays
|
||||||
// Supporting arrays `[a,b]` and `[a, b]`
|
// Supporting arrays `[a,b]` and `[a, b]`
|
||||||
const array = value.slice(1, -1).split(/,\s*/);
|
const array = value.slice(1, -1).split(/,\s*/);
|
||||||
|
|
|
@ -53,6 +53,7 @@ describe("Utils", function() {
|
||||||
|
|
||||||
it("should correctly parse empty strings", function() {
|
it("should correctly parse empty strings", function() {
|
||||||
expect(Utils.parseConfigOptions("foo=")).to.deep.equal({foo: ""});
|
expect(Utils.parseConfigOptions("foo=")).to.deep.equal({foo: ""});
|
||||||
|
expect(Utils.parseConfigOptions("foo= ")).to.deep.equal({foo: " "});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should correctly parse null values", function() {
|
it("should correctly parse null values", function() {
|
||||||
|
@ -91,6 +92,16 @@ describe("Utils", function() {
|
||||||
expect(Utils.parseConfigOptions("foo[0]=value"))
|
expect(Utils.parseConfigOptions("foo[0]=value"))
|
||||||
.to.deep.equal({foo: ["value"]});
|
.to.deep.equal({foo: ["value"]});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should correctly change type to number", function() {
|
||||||
|
expect(Utils.parseConfigOptions("foo=1337")).to.deep.equal({foo: 1337});
|
||||||
|
expect(Utils.parseConfigOptions("foo=5")).to.deep.equal({foo: 5});
|
||||||
|
expect(Utils.parseConfigOptions("foo=0")).to.deep.equal({foo: 0});
|
||||||
|
expect(Utils.parseConfigOptions("foo=9876543210")).to.deep.equal({foo: 9876543210});
|
||||||
|
expect(Utils.parseConfigOptions("foo=0987654321")).to.deep.equal({foo: 987654321});
|
||||||
|
expect(Utils.parseConfigOptions("foo=-1")).to.deep.equal({foo: -1});
|
||||||
|
expect(Utils.parseConfigOptions("foo=-0")).to.deep.equal({foo: -0});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when some options have already been parsed", function() {
|
describe("when some options have already been parsed", function() {
|
||||||
|
|
Loading…
Reference in a new issue