Home Reference Source Test

src/get-eaw.test.js

/* eslint-env mocha */

import { expect } from "chai";

import { getEAW } from "./get-eaw.js";

/**
 * @test {getEAW}
 */
describe("getEAW(str, at)", () => {
  context("without at specified", () => {
    it("should return the EAW property of the first character", () => {
      // single characters
      // Neutral
      expect(getEAW("\x00")).to.equal("N");
      expect(getEAW("ℵ")).to.equal("N");
      // Narrow
      expect(getEAW("1")).to.equal("Na");
      expect(getEAW("A")).to.equal("Na");
      expect(getEAW("a")).to.equal("Na");
      expect(getEAW(".")).to.equal("Na");
      // Wide
      expect(getEAW("あ")).to.equal("W");
      expect(getEAW("ア")).to.equal("W");
      expect(getEAW("安")).to.equal("W");
      expect(getEAW("。")).to.equal("W");
      expect(getEAW("🍣")).to.equal("W");
      // Fullwidth
      expect(getEAW("1")).to.equal("F");
      expect(getEAW("A")).to.equal("F");
      expect(getEAW("a")).to.equal("F");
      // Halfwidth
      expect(getEAW("ア")).to.equal("H");
      // Ambiguous
      expect(getEAW("∀")).to.equal("A");
      expect(getEAW("→")).to.equal("A");
      expect(getEAW("Ω")).to.equal("A");
      expect(getEAW("Я")).to.equal("A");

      // string
      expect(getEAW("ℵAあAア∀")).to.equal("N");
    });

    it("should return undefined if the character is empty", () => {
      expect(getEAW("")).to.equal(undefined);
    });
  });

  context("with at specified", () => {
    it("should return the EAW property of the specified character", () => {
      expect(getEAW("ℵAあAア∀", 0)).to.equal("N");
      expect(getEAW("ℵAあAア∀", 1)).to.equal("Na");
      expect(getEAW("ℵAあAア∀", 2)).to.equal("W");
      expect(getEAW("ℵAあAア∀", 3)).to.equal("F");
      expect(getEAW("ℵAあAア∀", 4)).to.equal("H");
      expect(getEAW("ℵAあAア∀", 5)).to.equal("A");
    });

    it("should return undefined if the position is out of range", () => {
      expect(getEAW("", 0)).to.equal(undefined);
      expect(getEAW("ℵAあAア∀", -1)).to.equal(undefined);
      expect(getEAW("ℵAあAア∀", 6)).to.equal(undefined);
    });
  });
});