diff --git a/test/fixtures/mdxFlowExpression/input.mdx b/test/fixtures/mdxFlowExpression/input.mdx new file mode 100644 index 0000000..78ea788 --- /dev/null +++ b/test/fixtures/mdxFlowExpression/input.mdx @@ -0,0 +1,3 @@ +{ +a + 1 +} diff --git a/test/fixtures/mdxFlowExpression/output.json b/test/fixtures/mdxFlowExpression/output.json new file mode 100644 index 0000000..bae895f --- /dev/null +++ b/test/fixtures/mdxFlowExpression/output.json @@ -0,0 +1,33 @@ +{ + "type": "Document", + "children": [ + { + "type": "CodeBlock", + "value": "\na + 1\n", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "range": [0, 9], + "raw": "{\na + 1\n}" + } + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "range": [0, 10], + "raw": "{\na + 1\n}\n" +} diff --git a/test/fixtures/mdxJsxFlowElement/input.mdx b/test/fixtures/mdxJsxFlowElement/input.mdx new file mode 100644 index 0000000..ec0403a --- /dev/null +++ b/test/fixtures/mdxJsxFlowElement/input.mdx @@ -0,0 +1 @@ + diff --git a/test/fixtures/mdxJsxFlowElement/output.json b/test/fixtures/mdxJsxFlowElement/output.json new file mode 100644 index 0000000..3ff070b --- /dev/null +++ b/test/fixtures/mdxJsxFlowElement/output.json @@ -0,0 +1,33 @@ +{ + "type": "Document", + "children": [ + { + "type": "Html", + "children": [], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "range": [0, 23], + "raw": "" + } + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "range": [0, 24], + "raw": "\n" +} diff --git a/test/fixtures/mdxJsxTextElement/input.mdx b/test/fixtures/mdxJsxTextElement/input.mdx new file mode 100644 index 0000000..3414365 --- /dev/null +++ b/test/fixtures/mdxJsxTextElement/input.mdx @@ -0,0 +1 @@ +abc diff --git a/test/fixtures/mdxJsxTextElement/output.json b/test/fixtures/mdxJsxTextElement/output.json new file mode 100644 index 0000000..b901ab0 --- /dev/null +++ b/test/fixtures/mdxJsxTextElement/output.json @@ -0,0 +1,99 @@ +{ + "type": "Document", + "children": [ + { + "type": "Paragraph", + "children": [ + { + "type": "Str", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [0, 1], + "raw": "a" + }, + { + "type": "Paragraph", + "children": [ + { + "type": "Str", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [12, 13], + "raw": "b" + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [1, 25], + "raw": "b" + }, + { + "type": "Str", + "value": "c", + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "range": [25, 26], + "raw": "c" + } + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "range": [0, 26], + "raw": "abc" + } + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "range": [0, 27], + "raw": "abc\n" +} diff --git a/test/fixtures/mdxTextExpression/input.mdx b/test/fixtures/mdxTextExpression/input.mdx new file mode 100644 index 0000000..369b97d --- /dev/null +++ b/test/fixtures/mdxTextExpression/input.mdx @@ -0,0 +1 @@ +b {true}. diff --git a/test/fixtures/mdxTextExpression/output.json b/test/fixtures/mdxTextExpression/output.json new file mode 100644 index 0000000..5d90d2d --- /dev/null +++ b/test/fixtures/mdxTextExpression/output.json @@ -0,0 +1,82 @@ +{ + "type": "Document", + "children": [ + { + "type": "Paragraph", + "children": [ + { + "type": "Str", + "value": "b ", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "range": [0, 2], + "raw": "b " + }, + { + "type": "Code", + "value": "true", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [2, 8], + "raw": "{true}" + }, + { + "type": "Str", + "value": ".", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [8, 9], + "raw": "." + } + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [0, 9], + "raw": "b {true}." + } + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "range": [0, 10], + "raw": "b {true}.\n" +} diff --git a/test/fixtures/mdxjsEsm/input.mdx b/test/fixtures/mdxjsEsm/input.mdx new file mode 100644 index 0000000..4252eb4 --- /dev/null +++ b/test/fixtures/mdxjsEsm/input.mdx @@ -0,0 +1,2 @@ +import a from 'b' +export var c = '' diff --git a/test/fixtures/mdxjsEsm/output.json b/test/fixtures/mdxjsEsm/output.json new file mode 100644 index 0000000..31edb88 --- /dev/null +++ b/test/fixtures/mdxjsEsm/output.json @@ -0,0 +1,33 @@ +{ + "type": "Document", + "children": [ + { + "type": "CodeBlock", + "value": "import a from 'b'\nexport var c = ''", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "range": [0, 35], + "raw": "import a from 'b'\nexport var c = ''" + } + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "range": [0, 36], + "raw": "import a from 'b'\nexport var c = ''\n" +} diff --git a/test/parsing.test.ts b/test/parsing.test.ts new file mode 100644 index 0000000..499dc98 --- /dev/null +++ b/test/parsing.test.ts @@ -0,0 +1,28 @@ +// parse all fixture and should has +import { test } from "@textlint/ast-tester"; +import fs from "node:fs"; +import path from "node:path"; +import { describe, expect, it } from "vitest"; +import { parse } from "../src/parse"; + +describe("parsing", () => { + const fixtureDir = path.join(__dirname, "fixtures"); + for (const filePath of fs.readdirSync(fixtureDir)) { + const dirName = path.basename(filePath); + it(`${dirName} match AST`, () => { + const input = fs.readFileSync( + path.join(fixtureDir, filePath, "input.mdx"), + "utf-8", + ); + const AST = parse(input); + test(AST); + const output = JSON.parse( + fs.readFileSync( + path.join(fixtureDir, filePath, "output.json"), + "utf-8", + ), + ); + expect(AST).toEqual(output); + }); + } +});