Skip to content

Commit 51f2bb4

Browse files
committed
test: Test formatting
1 parent a0711e7 commit 51f2bb4

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/schema/expressionLanguage.test.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { assert } from '@std/assert'
2-
import { contextFunction, expressionFunctions } from './expressionLanguage.ts'
1+
import { assert, assertEquals } from '@std/assert'
2+
import { contextFunction, expressionFunctions, formatter, prepareContext } from './expressionLanguage.ts'
33
import { dataFile, rootFileTree } from './fixtures.test.ts'
44
import { BIDSContext } from './context.ts'
55
import type { DatasetIssues } from '../issues/datasetIssues.ts'
@@ -282,3 +282,35 @@ Deno.test('contextFunction test', async (t) => {
282282
}
283283
})
284284
})
285+
286+
Deno.test('formatter test', async (t) => {
287+
await t.step('simple strings', () => {
288+
const context = {} as BIDSContext
289+
for (
290+
const str of [
291+
'simple string',
292+
'string with `backticks` and \\back\\slashes',
293+
]
294+
) {
295+
assertEquals(formatter(str)(context), str)
296+
}
297+
})
298+
await t.step('format strings', () => {
299+
const context = prepareContext(
300+
{a: 'stringa', b: 'stringb', c: 3, d: {e: 4}, f: [0, 1, 2], g: [1, 2, 3]} as unknown as BIDSContext
301+
)
302+
for (const [str, expected] of [
303+
['{a}', 'stringa'],
304+
['`{a}`', '`stringa`'], // Backticks are preserved
305+
['`````{a}`````', '`````stringa`````'],
306+
['{a} and {b} and {c}', 'stringa and stringb and 3'],
307+
['{a}\\n{d.e}', 'stringa\\n4'], // Backslashes are preserved
308+
['{intersects(f, g)}', '1,2'], // expressions are evaluated
309+
['{z}', 'undefined'],
310+
// Unsupported Pythonisms
311+
// ['{{a}}', '{a}'],
312+
]) {
313+
assertEquals(formatter(str)(context), expected)
314+
}
315+
})
316+
})

0 commit comments

Comments
 (0)