"use strict";
var import__ = require(".");
var import_vitest = require("vitest");
class _FakeStream {
  _lines = [];
  _y = 0;
  _x = 0;
  static create() {
    return new _FakeStream();
  }
  get _currentLine() {
    return this._lines[this._y] || "";
  }
  set _currentLine(line) {
    this._lines[this._y] = line;
  }
  get isTTY() {
    return true;
  }
  write(str) {
    const tokens = str.toString().split(/(\n)/).filter(Boolean);
    for (const token of tokens) {
      if (token === "\n") {
        this._y++;
        this._currentLine = "";
        continue;
      }
      this._currentLine = this._currentLine + token;
    }
    return true;
  }
  clearLine(dir) {
    if (dir === 0) {
      this._currentLine = "";
    } else if (dir === -1) {
      const right = this._currentLine.slice(this._x);
      this._currentLine = right;
    } else {
      const left = this._currentLine.slice(0, this._x);
      this._currentLine = left;
    }
    return true;
  }
  cursorTo(x, y) {
    this._x = x;
    this._y = typeof y === "number" ? y : this._y;
    return true;
  }
  get data() {
    return this._lines.join("\n");
  }
}
(0, import_vitest.test)("logging with a prefix should write the prefix", () => {
  const stream = _FakeStream.create();
  const logger = new import__.Logger({ outStream: stream, errStream: stream });
  logger.log("lol1", { prefix: "###" });
  (0, import_vitest.expect)(stream.data).toEqual("### lol1\n");
});
(0, import_vitest.test)("logging a certain sequence of messages should write message in order", () => {
  const stream = _FakeStream.create();
  const logger = new import__.Logger({ outStream: stream, errStream: stream });
  logger.log("lol1");
  logger.log("lol2");
  logger.log("lol3");
  logger.log("lol4");
  (0, import_vitest.expect)(stream.data).toEqual(`lol1
lol2
lol3
lol4
`);
});
(0, import_vitest.test)("logging on a single line should write message on a single line", () => {
  const stream = _FakeStream.create();
  const logger = new import__.Logger({ outStream: stream, errStream: stream }).line();
  logger.log("lol1");
  logger.log("lol2");
  logger.log("lol3");
  logger.log("lol4");
  (0, import_vitest.expect)(stream.data).toEqual("lol4");
});
(0, import_vitest.test)("logging on a single line, then logging on multiple line should keep logging on next line", () => {
  const stream = _FakeStream.create();
  const logger = new import__.Logger({ outStream: stream, errStream: stream });
  logger.log("lol1");
  const line = logger.line();
  line.log("lol2");
  line.log("lol3");
  logger.log("lol4");
  line.log("lol5");
  (0, import_vitest.expect)(stream.data).toEqual(`lol1
lol3
lol4
lol5
`);
});
//# sourceMappingURL=logger.test.js.map
