fix property parser

jh-changes
Shin'ya Ueoka 7 years ago
parent dda4e7475c
commit befcff973a
  1. 2
      src/shared/commands/parsers.js
  2. 7
      test/shared/commands/parsers.test.js

@ -30,7 +30,7 @@ const mustNumber = (v) => {
const parseSetOption = (word, types) => {
let [key, value] = word.split('=');
if (!value) {
if (value === undefined) {
value = !key.startsWith('no');
key = value ? key : key.slice(2);
}

@ -9,6 +9,12 @@ describe("shared/commands/parsers", () => {
expect(value).to.equal('utf-8');
});
it('parse set empty string', () => {
let [key, value] = parsers.parseSetOption('encoding=', { encoding: 'string' });
expect(key).to.equal('encoding');
expect(value).to.equal('');
});
it('parse set string', () => {
let [key, value] = parsers.parseSetOption('history=50', { history: 'number' });
expect(key).to.equal('history');
@ -34,6 +40,7 @@ describe("shared/commands/parsers", () => {
it('throws error on invalid property', () => {
expect(() => parsers.parseSetOption('charset=utf-8', { charset: 'number' })).to.throw(Error, 'Not number');
expect(() => parsers.parseSetOption('charset=utf-8', { charset: 'boolean' })).to.throw(Error, 'Invalid');
expect(() => parsers.parseSetOption('charset=', { charset: 'boolean' })).to.throw(Error, 'Invalid');
expect(() => parsers.parseSetOption('smoothscroll', { smoothscroll: 'string' })).to.throw(Error, 'Invalid');
expect(() => parsers.parseSetOption('smoothscroll', { smoothscroll: 'number' })).to.throw(Error, 'Invalid');
})