diff --git a/deno.json b/deno.json index b61140f..cca59f8 100644 --- a/deno.json +++ b/deno.json @@ -1,5 +1,6 @@ { "imports": { + "@std/assert": "jsr:@std/assert@^1.0.15", "@std/cli": "jsr:@std/cli@^1.0.27", "@std/fs": "jsr:@std/fs@^1.0.22", "@std/path": "jsr:@std/path@^1.1.4", diff --git a/src/lib_test.ts b/src/lib_test.ts new file mode 100644 index 0000000..06040d4 --- /dev/null +++ b/src/lib_test.ts @@ -0,0 +1,84 @@ +import { assertEquals } from "jsr:@std/assert"; +import { getOutputPath } from "./lib.ts"; + +Deno.test("getOutputPath - default output without custom path", () => { + const result = getOutputPath({ + input: "Checker.png", + rationalAngle: { degrees: 45 }, + }); + assertEquals(result, "./Checker-tile-45.png"); +}); + +Deno.test("getOutputPath - with full path", () => { + const result = getOutputPath({ + input: "/path/to/Checker.png", + rationalAngle: { degrees: 45 }, + }); + assertEquals(result, "/path/to/Checker-tile-45.png"); +}); + +Deno.test("getOutputPath - with relative path", () => { + const result = getOutputPath({ + input: "./images/test.jpg", + rationalAngle: { degrees: 90 }, + }); + assertEquals(result, "./images/test-tile-90.jpg"); +}); + +Deno.test("getOutputPath - with custom output path", () => { + const result = getOutputPath({ + input: "Checker.png", + rationalAngle: { degrees: 45 }, + output: "custom-output.png", + }); + assertEquals(result, "custom-output.png"); +}); + +Deno.test("getOutputPath - with negative degrees", () => { + const result = getOutputPath({ + input: "test.png", + rationalAngle: { degrees: -45 }, + }); + assertEquals(result, "./test-tile--45.png"); +}); + +Deno.test("getOutputPath - with decimal degrees", () => { + const result = getOutputPath({ + input: "/home/user/image.png", + rationalAngle: { degrees: 26.565 }, + }); + assertEquals(result, "/home/user/image-tile-26.565.png"); +}); + +Deno.test("getOutputPath - with different file extension", () => { + const result = getOutputPath({ + input: "photo.jpeg", + rationalAngle: { degrees: 90 }, + }); + assertEquals(result, "./photo-tile-90.jpeg"); +}); + +Deno.test("getOutputPath - zero degrees", () => { + const result = getOutputPath({ + input: "./assets/background.png", + rationalAngle: { degrees: 0 }, + }); + assertEquals(result, "./assets/background-tile-0.png"); +}); + +Deno.test("getOutputPath - preserves directory structure", () => { + const result = getOutputPath({ + input: "../../parent/child/file.png", + rationalAngle: { degrees: 45 }, + }); + assertEquals(result, "../../parent/child/file-tile-45.png"); +}); + +Deno.test("getOutputPath - custom output ignores input path structure", () => { + const result = getOutputPath({ + input: "/some/long/path/to/image.png", + rationalAngle: { degrees: 63.435 }, + output: "./output.png", + }); + assertEquals(result, "./output.png"); +});