|
1 | | -import { assert, assertEquals, assertFalse, assertThrows } from "@std/assert" |
| 1 | +import { assert, assertEquals, assertFalse, assertThrows, fail } from "@std/assert" |
2 | 2 | import { SEPARATOR as SEP } from "jsr:@std/path@1" |
3 | 3 | import Path from "./Path.ts" |
4 | 4 |
|
@@ -199,6 +199,42 @@ Deno.test("Path.prettyLocalString()", () => { |
199 | 199 | assertEquals(new Path("/a/b").prettyLocalString(), `${root}a${SEP}b`) |
200 | 200 | }) |
201 | 201 |
|
| 202 | +Deno.test("Path.readYAMLAll()", async () => { |
| 203 | + const path = Path.cwd().join("./fixtures/pathtests/readYAMLAll.yaml"); |
| 204 | + |
| 205 | + try { |
| 206 | + const yamlData = await path.readYAMLAll(); // ✅ Use await |
| 207 | + |
| 208 | + assertEquals(Array.isArray(yamlData), true, "Expected yamlData to be an array"); |
| 209 | + |
| 210 | + if (!Array.isArray(yamlData)) { |
| 211 | + fail("Expected an array"); |
| 212 | + return; |
| 213 | + } |
| 214 | + |
| 215 | + assertEquals(yamlData.length, 2, "Expected exactly 2 YAML documents"); |
| 216 | + assertEquals(yamlData, [{ abc: "xyz" }, { ijk: "lmn" }], "YAML content mismatch"); |
| 217 | + |
| 218 | + } catch (err) { |
| 219 | + console.error("Error reading YAML:", err); |
| 220 | + fail("Error reading YAML"); |
| 221 | + } |
| 222 | +}); |
| 223 | + |
| 224 | +Deno.test("Path.readYAMLAllErr()", async () => { |
| 225 | + const path = Path.cwd().join("./fixtures/pathtests/invalid.yaml"); |
| 226 | + try { |
| 227 | + await path.readYAMLAll(); |
| 228 | + fail("invalid file should not reach here") |
| 229 | + } catch (err) { |
| 230 | + if (err instanceof Error) { |
| 231 | + assertEquals(err.name, "NotFound") |
| 232 | + } else{ |
| 233 | + throw err; |
| 234 | + } |
| 235 | + } |
| 236 | +}); |
| 237 | + |
202 | 238 | Deno.test("Path.chuzzle()", () => { |
203 | 239 | const path = Path.mktemp().join("file.txt").touch() |
204 | 240 | assertEquals(path.chuzzle(), path) |
|
0 commit comments