diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-03-20 21:20:42 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-03-20 21:20:42 +0900 |
| commit | 8ea45e27306d0369f2b2d624a174bd95e7f17395 (patch) | |
| tree | 3eb6707863ba9bb8a80590208fb58e932d489633 /nuldoc-src | |
| parent | b0cb51367d8c68eabafaa57c2967587007aa79bd (diff) | |
| download | blog.nsfisis.dev-8ea45e27306d0369f2b2d624a174bd95e7f17395.tar.gz blog.nsfisis.dev-8ea45e27306d0369f2b2d624a174bd95e7f17395.tar.zst blog.nsfisis.dev-8ea45e27306d0369f2b2d624a174bd95e7f17395.zip | |
feat(nuldoc): add small test to xml.ts
Diffstat (limited to 'nuldoc-src')
| -rw-r--r-- | nuldoc-src/xml.ts | 7 | ||||
| -rw-r--r-- | nuldoc-src/xml_test.ts | 17 |
2 files changed, 22 insertions, 2 deletions
diff --git a/nuldoc-src/xml.ts b/nuldoc-src/xml.ts index 13ec5d6..87c2b71 100644 --- a/nuldoc-src/xml.ts +++ b/nuldoc-src/xml.ts @@ -2,7 +2,10 @@ import { Element, Node, Text } from "./dom.ts"; import { XmlParseError } from "./errors.ts"; export async function parseXmlFile(filePath: string): Promise<Element> { - const source = await Deno.readTextFile(filePath); + return parseXmlString(await Deno.readTextFile(filePath)); +} + +export function parseXmlString(source: string): Element { return parse({ source: source, index: 0 }); } @@ -200,7 +203,7 @@ function expect(p: Parser, expected: string) { } if (actual !== expected) { throw new XmlParseError( - `[parse.expect] expected ${expected}, but actually got ${actual}`, + `[parse.expect] expected ${expected}, but actually got ${actual} (pos: ${p.index})`, ); } } diff --git a/nuldoc-src/xml_test.ts b/nuldoc-src/xml_test.ts new file mode 100644 index 0000000..28e1597 --- /dev/null +++ b/nuldoc-src/xml_test.ts @@ -0,0 +1,17 @@ +import { assertEquals } from "std/testing/asserts.ts"; +import { parseXmlString } from "./xml.ts"; + +Deno.test("Parse XML", () => { + assertEquals( + "__root__", + parseXmlString( + `<?xml version="1.0" encoding="UTF-8"?> +<hoge> + <piyo> + <!-- comment --> + </piyo> +</hoge> +`, + ).name, + ); +}); |
