Skip to content

Commit

Permalink
test(engine): syntax autodetection
Browse files Browse the repository at this point in the history
  • Loading branch information
stdword committed Jul 28, 2023
1 parent 1b730e9 commit a718df6
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions tests/logic/command_template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function testRender(syntax: string, expected: string | null = null) {
return block.content
}

describe.only('template syntax', () => {
describe('template syntax', () => {
test('no syntax', async () => {
await testRender('text', 'text') })
test('js expression', async () => {
Expand All @@ -42,20 +42,42 @@ describe.only('template syntax', () => {
expect(console._checkMe).toBe(13)
})

test('back ticks inside expression', async () => {
await testRender('`` `1` + `2` ``', '12') })

test('save spaces to the right', async () => {
await testRender('``{ }`` text', ' text') })
await testRender('``{ var x = 1 }`` text', ' text') })
test('save spaces to the left', async () => {
await testRender('text ``{ }``', 'text ') })
await testRender('text ``{ var x = 1 }``', 'text ') })
test('strip one new line to the right', async () => {
await testRender('``{ }``\n\ntext', '\ntext') })
await testRender('``{ var x = 1 }``\n\ntext', '\ntext') })
test('strip no one new lines to the left', async () => {
await testRender('text\n\n``{ }``', 'text\n\n') })
await testRender('text\n\n``{ var x = 1 }``', 'text\n\n') })

test('ref shortcut', async () => {
await testRender('``["page"]``', '[[page]]') })
})

describe.only('template context', () => {
describe('backwards compatibility', () => {
test('old syntax: exclamation mark', async () => {
await testRender('``{ ! var x = c.page.name }`` ``{ x }``', ' PAGE') })
test('new syntax: no exclamation mark', async () => {
await testRender('``{ var x = c.page.name }`` ``x``', ' PAGE') })

test('don\'t mix old & new syntax', async () => {
await testRender('``{ ! var x = c.page.name }`` ``x``', ' ``x``') })
test('don\'t mix new & old syntax', async () => {
await testRender('``{ var x = c.page.name }`` ``{ x }``', ' ') })

test('statement signs: var', async () => {
await testRender('``{ var x = c.page.name }``', '') })
test('statement signs: =', async () => {
await testRender('``{ c.page.name = "new" }``', '') })
test('statement signs: absent', async () => {
await testRender('``{ c.page.name }``', 'PAGE') })
})

describe('template context', () => {
test('page name', async () => {
await testRender('``c.page.name``', 'PAGE') })
test('template name', async () => {
Expand Down

0 comments on commit a718df6

Please sign in to comment.