aboutsummaryrefslogtreecommitdiff
path: root/test/background/usecases/parsers.test.ts
blob: 019b56e411533d0c11e0c647be04dd706ddf07ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as parsers from "../../../src/background/usecases/parsers";
import { expect } from "chai";

describe("shared/commands/parsers", () => {
  describe("#parsers.parseSetOption", () => {
    it("parse set string", () => {
      const [key, value] = parsers.parseSetOption("hintchars=abcdefgh");
      expect(key).to.equal("hintchars");
      expect(value).to.equal("abcdefgh");
    });

    it("parse set empty string", () => {
      const [key, value] = parsers.parseSetOption("hintchars=");
      expect(key).to.equal("hintchars");
      expect(value).to.equal("");
    });

    it("parse set boolean", () => {
      let [key, value] = parsers.parseSetOption("smoothscroll");
      expect(key).to.equal("smoothscroll");
      expect(value).to.be.true;

      [key, value] = parsers.parseSetOption("nosmoothscroll");
      expect(key).to.equal("smoothscroll");
      expect(value).to.be.false;
    });

    it("throws error on unknown property", () => {
      expect(() => parsers.parseSetOption("encoding=utf-8")).to.throw(
        Error,
        "Unknown"
      );
      expect(() => parsers.parseSetOption("paste")).to.throw(Error, "Unknown");
      expect(() => parsers.parseSetOption("nopaste")).to.throw(
        Error,
        "Unknown"
      );
      expect(() => parsers.parseSetOption("smoothscroll=yes")).to.throw(
        Error,
        "Invalid argument"
      );
    });
  });
});