"use strict";

const { expect } = require("chai");

const {
  SourcePos,
  ErrorMessageType,
  ErrorMessage,
  ParseError,
  StrictParseError,
  Config,
  State,
  Result,
} = $core;

const { anyToken } = $combinators;

describe("anyToken", () => {
  it("should be a parser that accepts any token", () => {
    expect(anyToken).to.be.a.parser;
    // empty input
    {
      const initState = new State(
        new Config(),
        "",
        new SourcePos("main", 1, 1),
        "none"
      );
      const res = anyToken.run(initState);
      expect(res).to.be.an.equalResultTo(Result.efail(
        new StrictParseError(
          new SourcePos("main", 1, 1),
          [ErrorMessage.create(ErrorMessageType.SYSTEM_UNEXPECT, "")]
        )
      ));
    }
    // non-empty input
    {
      const initState = new State(
        new Config(),
        "ABC",
        new SourcePos("main", 1, 1),
        "none"
      );
      const res = anyToken.run(initState);
      expect(res).to.be.an.equalResultTo(Result.csucc(
        ParseError.unknown(new SourcePos("main", 1, 1)),
        "A",
        new State(
          new Config(),
          "BC",
          new SourcePos("main", 1, 1),
          "none"
        )
      ));
    }
  });
});
