Add test that ensures that getBlocksFromSyntaxTree() and getBlocksFromString() functions produces the same results

This commit is contained in:
Jonatan Heyman
2024-07-07 22:01:19 +02:00
parent 016422e7db
commit bc3a9b66a1
2 changed files with 31 additions and 3 deletions

View File

@ -0,0 +1,28 @@
import { expect, test } from "@playwright/test"
import { EditorState } from "@codemirror/state"
import { heynoteLang } from "../src/editor/lang-heynote/heynote.js"
import { getBlocksFromSyntaxTree, getBlocksFromString } from "../src/editor/block/block.js"
test("parse blocks from both syntax tree and string contents", async ({page}) => {
const contents = `
∞∞∞text
Text Block A
∞∞∞text-a
Text Block B
∞∞∞json-a
{
"key": "value"
}
∞∞∞python
print("Hello, World!")
`
const state = EditorState.create({
doc: contents,
extensions: heynoteLang(),
})
const treeBlocks = getBlocksFromSyntaxTree(state)
const stringBlocks = getBlocksFromString(state)
expect(treeBlocks).toEqual(stringBlocks)
})