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 | |
| 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
| -rw-r--r-- | deno.lock | 7 | ||||
| -rw-r--r-- | nuldoc-src/xml.ts | 7 | ||||
| -rw-r--r-- | nuldoc-src/xml_test.ts | 17 |
3 files changed, 28 insertions, 3 deletions
@@ -65,10 +65,15 @@ "https://deno.land/std@0.170.0/path/posix.ts": "b859684bc4d80edfd4cad0a82371b50c716330bed51143d6dcdbe59e6278b30c", "https://deno.land/std@0.170.0/path/separator.ts": "fe1816cb765a8068afb3e8f13ad272351c85cbc739af56dacfc7d93d710fe0f9", "https://deno.land/std@0.170.0/path/win32.ts": "7cebd2bda6657371adc00061a1d23fdd87bcdf64b4843bb148b0b24c11b40f69", + "https://deno.land/std@0.170.0/testing/_diff.ts": "a23e7fc2b4d8daa3e158fa06856bedf5334ce2a2831e8bf9e509717f455adb2c", + "https://deno.land/std@0.170.0/testing/_format.ts": "cd11136e1797791045e639e9f0f4640d5b4166148796cad37e6ef75f7d7f3832", + "https://deno.land/std@0.170.0/testing/asserts.ts": "51353e79437361d4b02d8e32f3fc83b22231bc8f8d4c841d86fd32b0b0afe940", "https://deno.land/std@0.170.0/version.ts": "eb6935c9beaac221b235d011ba5b127ceb5d3addf329cc01e05806af07ba93e1" }, "npm": { - "specifiers": { "highlight.js": "highlight.js@11.7.0" }, + "specifiers": { + "highlight.js": "highlight.js@11.7.0" + }, "packages": { "highlight.js@11.7.0": { "integrity": "sha512-1rRqesRFhMO/PRF+G86evnyJkCgaZFOI+Z6kdj15TA18funfoqJXvgPCLSf0SWq3SRfg1j3HlDs8o4s3EGq1oQ==", 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, + ); +}); |
