|
| 1 | +// Import Node.js Dependencies |
| 2 | +import { describe, it } from "node:test"; |
| 3 | +import assert from "node:assert"; |
| 4 | + |
| 5 | +// Import Internal Dependencies |
| 6 | +import { SourceFile, SourceFilePath } from "../src/SourceFile.js"; |
| 7 | + |
| 8 | +describe("SourceFile", () => { |
| 9 | + describe("constructor() with sourceLocation", () => { |
| 10 | + it("should set the path location", () => { |
| 11 | + const sourceFile = new SourceFile("/path/to/file.js"); |
| 12 | + assert.ok(sourceFile.path instanceof SourceFilePath); |
| 13 | + assert.strictEqual(sourceFile.path.location, "/path/to/file.js"); |
| 14 | + }); |
| 15 | + }); |
| 16 | +}); |
| 17 | + |
| 18 | +describe("SourceFilePath", () => { |
| 19 | + describe("constructor", () => { |
| 20 | + it("should have location set to null by default", () => { |
| 21 | + const sfp = new SourceFilePath(); |
| 22 | + assert.strictEqual(sfp.location, null); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + describe("use()", () => { |
| 27 | + it("should set location when provided", () => { |
| 28 | + const sfp = new SourceFilePath(); |
| 29 | + sfp.use("/foo/bar"); |
| 30 | + assert.strictEqual(sfp.location, "/foo/bar"); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should set location to null when undefined", () => { |
| 34 | + const sfp = new SourceFilePath(); |
| 35 | + sfp.use("/foo"); |
| 36 | + sfp.use(undefined); |
| 37 | + assert.strictEqual(sfp.location, null); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe("resolve()", () => { |
| 42 | + it("should join parts without base location", () => { |
| 43 | + const sfp = new SourceFilePath(); |
| 44 | + assert.strictEqual(sfp.resolve("foo", "bar.js"), "foo/bar.js"); |
| 45 | + }); |
| 46 | + |
| 47 | + it("should join parts with base location", () => { |
| 48 | + const sfp = new SourceFilePath(); |
| 49 | + sfp.use("/base"); |
| 50 | + assert.strictEqual(sfp.resolve("foo", "bar.js"), "/base/foo/bar.js"); |
| 51 | + }); |
| 52 | + }); |
| 53 | +}); |
0 commit comments