Migrate from Jest to node:test (#115)
This commit is contained in:
parent
d33f80cca6
commit
0ff3bb5967
24 changed files with 759 additions and 6421 deletions
|
|
@ -1,42 +1,44 @@
|
|||
import { describe, it } from "node:test";
|
||||
import assert from "node:assert";
|
||||
import { lineAndColumnToPosition } from "./line-and-column-to-position";
|
||||
|
||||
describe("lineAndColumnToPosition", () => {
|
||||
it("should return the correct position for the first line", () => {
|
||||
const text = "Hello\nWorld";
|
||||
const position = lineAndColumnToPosition(text, 0, 3);
|
||||
expect(position).toBe(3);
|
||||
assert.strictEqual(position, 3);
|
||||
});
|
||||
|
||||
it("should return the correct position for the second line", () => {
|
||||
const text = "Hello\nWorld";
|
||||
const position = lineAndColumnToPosition(text, 1, 2);
|
||||
expect(position).toBe(8);
|
||||
assert.strictEqual(position, 8);
|
||||
});
|
||||
|
||||
it("should return the correct position for an empty string", () => {
|
||||
const text = "";
|
||||
const position = lineAndColumnToPosition(text, 0, 0);
|
||||
expect(position).toBe(0);
|
||||
assert.strictEqual(position, 0);
|
||||
});
|
||||
|
||||
it("with carrige return", () => {
|
||||
expect(lineAndColumnToPosition("a\nb", 1, 1)).toBe(3);
|
||||
expect(lineAndColumnToPosition("a\r\nb", 1, 1)).toBe(3);
|
||||
assert.strictEqual(lineAndColumnToPosition("a\nb", 1, 1), 3);
|
||||
assert.strictEqual(lineAndColumnToPosition("a\r\nb", 1, 1), 3);
|
||||
});
|
||||
|
||||
it("should handle multi-line strings with varying lengths", () => {
|
||||
const text = "Line1\nLongerLine2\nShort3";
|
||||
const position = lineAndColumnToPosition(text, 2, 4);
|
||||
expect(position).toBe(22);
|
||||
assert.strictEqual(position, 22);
|
||||
});
|
||||
|
||||
it("should throw an error if the line number is out of range", () => {
|
||||
const text = "Line1\nLine2";
|
||||
expect(() => lineAndColumnToPosition(text, 3, 0)).toThrow();
|
||||
assert.throws(() => lineAndColumnToPosition(text, 3, 0));
|
||||
});
|
||||
|
||||
it("should throw an error if the column number is out of range", () => {
|
||||
const text = "Line1\nLine2";
|
||||
expect(() => lineAndColumnToPosition(text, 1, 10)).toThrow();
|
||||
assert.throws(() => lineAndColumnToPosition(text, 1, 10));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,53 +1,58 @@
|
|||
import { describe, test } from "node:test";
|
||||
import assert from "node:assert";
|
||||
import { positionToLineAndColumn } from "./position-to-line-and-column";
|
||||
|
||||
describe("positionToLineAndColumn", () => {
|
||||
test("converts position to line and column in multi-line text", () => {
|
||||
const text = "ab\ncd\n";
|
||||
expect(positionToLineAndColumn(text, 0)).toEqual({
|
||||
assert.deepStrictEqual(positionToLineAndColumn(text, 0), {
|
||||
line: 0,
|
||||
column: 0
|
||||
});
|
||||
expect(positionToLineAndColumn(text, 1)).toEqual({
|
||||
assert.deepStrictEqual(positionToLineAndColumn(text, 1), {
|
||||
line: 0,
|
||||
column: 1
|
||||
});
|
||||
expect(positionToLineAndColumn(text, 2)).toEqual({
|
||||
assert.deepStrictEqual(positionToLineAndColumn(text, 2), {
|
||||
line: 0,
|
||||
column: 2
|
||||
});
|
||||
expect(positionToLineAndColumn(text, 3)).toEqual({
|
||||
assert.deepStrictEqual(positionToLineAndColumn(text, 3), {
|
||||
line: 1,
|
||||
column: 0
|
||||
});
|
||||
expect(positionToLineAndColumn(text, 4)).toEqual({
|
||||
assert.deepStrictEqual(positionToLineAndColumn(text, 4), {
|
||||
line: 1,
|
||||
column: 1
|
||||
});
|
||||
expect(positionToLineAndColumn(text, 6)).toEqual({
|
||||
assert.deepStrictEqual(positionToLineAndColumn(text, 6), {
|
||||
line: 2,
|
||||
column: 0
|
||||
});
|
||||
});
|
||||
|
||||
test("with carrige returns", () => {
|
||||
expect(positionToLineAndColumn("a\nb", 3)).toEqual({
|
||||
assert.deepStrictEqual(positionToLineAndColumn("a\nb", 3), {
|
||||
line: 1,
|
||||
column: 1
|
||||
});
|
||||
|
||||
expect(positionToLineAndColumn("a\r\nb", 3)).toEqual({
|
||||
assert.deepStrictEqual(positionToLineAndColumn("a\r\nb", 3), {
|
||||
line: 1,
|
||||
column: 1
|
||||
});
|
||||
});
|
||||
|
||||
test("handles empty input", () => {
|
||||
expect(positionToLineAndColumn("", 0)).toEqual({ line: 0, column: 0 });
|
||||
assert.deepStrictEqual(positionToLineAndColumn("", 0), {
|
||||
line: 0,
|
||||
column: 0
|
||||
});
|
||||
});
|
||||
|
||||
test("handles positions at the end of text", () => {
|
||||
const text = "End";
|
||||
expect(positionToLineAndColumn(text, 3)).toEqual({
|
||||
assert.deepStrictEqual(positionToLineAndColumn(text, 3), {
|
||||
line: 0,
|
||||
column: 3
|
||||
});
|
||||
|
|
@ -55,7 +60,7 @@ describe("positionToLineAndColumn", () => {
|
|||
|
||||
test("throws error for position out of range", () => {
|
||||
const text = "Short text";
|
||||
expect(() => positionToLineAndColumn(text, 15)).toThrow();
|
||||
expect(() => positionToLineAndColumn(text, -1)).toThrow();
|
||||
assert.throws(() => positionToLineAndColumn(text, 15));
|
||||
assert.throws(() => positionToLineAndColumn(text, -1));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue