jest-allure2-reporter
Version:
Idiomatic Jest reporter for Allure Framework
108 lines • 2.96 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileNavigator = void 0;
class FileNavigator {
#content;
#cursor = 0;
#line = 1;
#lines = null;
#countOfLines = Number.NaN;
constructor(content) {
this.#content = content;
}
getContent() {
return this.#content;
}
getPosition() {
return [this.#line, 1, this.#cursor];
}
getLines() {
if (this.#lines === null) {
this.#lines = this.#content.split('\n');
}
return this.#lines;
}
getLineCount() {
if (Number.isNaN(this.#countOfLines)) {
if (this.#lines === null) {
let count = 1;
let index = 0;
while ((index = this.#content.indexOf('\n', index)) !== -1) {
count++;
index++;
}
this.#countOfLines = count;
}
else {
this.#countOfLines = this.#lines.length;
}
}
return this.#countOfLines;
}
getCurrentLine() {
return this.#line;
}
moveUp(count = 1) {
for (let index = 0; index < count; index++) {
if (!this.#prev())
return false;
}
return true;
}
moveDown(count = 1) {
for (let index = 0; index < count; index++) {
if (!this.#next())
return false;
}
return true;
}
jump(lineIndex) {
while (this.#line > lineIndex) {
if (!this.#prev())
return false;
}
while (this.#line < lineIndex) {
if (!this.#next())
return false;
}
return true;
}
jumpToPosition(position) {
while (this.#cursor < position) {
if (!this.#next())
break;
}
while (this.#cursor > position) {
if (!this.#prev())
break;
}
return position >= 0 && position < this.#content.length && this.#cursor <= position;
}
readLine(lineNumber = this.#line) {
if (!this.jump(lineNumber))
return '';
const nextIndex = this.#content.indexOf('\n', this.#cursor);
if (nextIndex === -1) {
return this.#content.slice(this.#cursor);
}
return this.#content.slice(this.#cursor, nextIndex);
}
#next() {
const next = this.#content.indexOf('\n', this.#cursor);
if (next === -1) {
return false;
}
this.#cursor = next + 1;
this.#line++;
return true;
}
#prev() {
if (this.#cursor === 0)
return false;
this.#cursor = this.#content.lastIndexOf('\n', this.#cursor - 2) + 1;
this.#line--;
return true;
}
}
exports.FileNavigator = FileNavigator;
//# sourceMappingURL=FileNavigator.js.map