From 16521b47590e8372364f20548b79408a5b86ecf9 Mon Sep 17 00:00:00 2001 From: Michael Toy <66150587+mtoy-googly-moogly@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:57:02 -0800 Subject: [PATCH] add tests for arrays/records in field names that need quoting --- .../src/databases/all/compound-atomic.spec.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/src/databases/all/compound-atomic.spec.ts b/test/src/databases/all/compound-atomic.spec.ts index 710bc0b01..3ccf69e26 100644 --- a/test/src/databases/all/compound-atomic.spec.ts +++ b/test/src/databases/all/compound-atomic.spec.ts @@ -183,6 +183,22 @@ describe.each(runtimes.runtimeList)( {roll: 8, rolls: 1}, ]); }); + test('array stored field with special chars in name', async () => { + const special_chars = ["'", '"', '.', '`']; + for (const c of special_chars) { + const qname = '`_\\' + c + '_`'; + const malloySrc = ` + run: ${empty} + ->{ select: ${qname} is [1]} + -> { select: num is ${qname}.each }`; + const result = await runtime.loadQuery(malloySrc).run(); + const ok = + result.data.path(0, 'num').value === 1 + ? 'ok' + : `Array containing ${c} character is not ok`; + expect(ok).toEqual('ok'); + } + }); test.when(supportsNestedArrays)('bare array of array', async () => { await expect(` run: ${empty} -> { select: aoa is [[1,2]] } @@ -226,6 +242,22 @@ describe.each(runtimes.runtimeList)( expect(p).toEqual('ok'); } }); + test('record stored in field with special chars in name', async () => { + const special_chars = ["'", '"', '.', '`']; + for (const c of special_chars) { + const qname = '`_\\' + c + '_`'; + const malloySrc = ` + run: ${empty} + ->{ select: ${qname} is {rnum is 1}} + -> { select: num is ${qname}.rnum }`; + const result = await runtime.loadQuery(malloySrc).run(); + const ok = + result.data.path(0, 'num').value === 1 + ? 'ok' + : `Array containing ${c} character is not ok`; + expect(ok).toEqual('ok'); + } + }); test.when(canReadCompoundSchema)( 'can read schema of record object', async () => {