Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core): improve flux function tests #433

Merged
merged 2 commits into from
Apr 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore(core): improve flux function tests
  • Loading branch information
sranka committed Apr 9, 2022
commit a6f6b0788b071659ebb05fa58c0dec3e3e6dfddd
75 changes: 75 additions & 0 deletions packages/core/test/unit/query/flux.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,79 @@ describe('Flux Tagged Template', () => {
'from(bucket:"my-bucket")'
)
})
it('interpolates parameter with escaping', () => {
const pairs: Array<{value: any; flux: string}> = [
{value: flux`${null}`, flux: 'null'},
{value: flux`${false}`, flux: 'false'},
{value: flux`${1}`, flux: '1'},
{value: flux`${1.1}`, flux: '1.1'},
{value: flux`${-1.1}`, flux: '-1.1'},
{value: flux`${'a'}`, flux: '"a"'},
{
value: flux`${new Date(1589521447471)}`,
flux: '2020-05-15T05:44:07.471Z',
},
{value: flux`${/abc/}`, flux: 'regexp.compile(v: "/abc/")'},
{
value: flux`${{
toString: function(): string {
return 'whatever'
},
}}`,
flux: '"whatever"',
},
{value: flux`${fluxExpression('1ms')}`, flux: '1ms'},
{value: flux`${'abc\n\r\t\\"def'}`, flux: '"abc\\n\\r\\t\\\\\\"def"'},
{value: flux`${'abc${val}def'}`, flux: '"abc\\${val}def"'},
{value: flux`${'abc$'}`, flux: '"abc$"'},
{value: flux`${'a"$d'}`, flux: '"a\\"$d"'},
{value: flux`${[]}`, flux: '[]'},
{value: flux`${['a"$d']}`, flux: '["a\\"$d"]'},
{
value: flux`${Symbol('thisSym')}`,
flux: `"${Symbol('thisSym').toString()}"`,
},
]
pairs.forEach(pair => {
expect(pair.value.toString()).equals(pair.flux)
})
})
it('interpolates double quoted parameter with escaping', () => {
const pairs: Array<{value: any; flux: string}> = [
{value: flux`"${null}"`, flux: '""'},
{value: flux`"${undefined}"`, flux: '""'},
{value: flux`"${false}"`, flux: '"false"'},
{value: flux`"${1}"`, flux: '"1"'},
{value: flux`"${1.1}"`, flux: '"1.1"'},
{value: flux`"${-1.1}"`, flux: '"-1.1"'},
{value: flux`"${'a'}"`, flux: '"a"'},
{
value: flux`"${new Date(1589521447471)}"`,
flux: `"${new Date(1589521447471)}"`,
},
{value: flux`"${/abc/}"`, flux: `"${/abc/.toString()}"`},
{
value: flux`"${{
toString: function(): string {
return 'whatever'
},
}}"`,
flux: '"whatever"',
},
{value: flux`"${fluxExpression('1ms')}"`, flux: '"1ms"'},
{value: flux`"${'abc\n\r\t\\"def'}"`, flux: '"abc\\n\\r\\t\\\\\\"def"'},
{value: flux`"${'abc${val}def'}"`, flux: '"abc\\${val}def"'},
{value: flux`"${'abc$'}"`, flux: '"abc$"'},
{value: flux`"${'a"$d'}"`, flux: '"a\\"$d"'},
{value: flux`"${[]}"`, flux: `""`},
{value: flux`"${['a"$d']}"`, flux: `"a\\"$d"`},
{
value: flux`"${Symbol('thisSym')}"`,
flux: `"${Symbol('thisSym').toString()}"`,
},
]
pairs.forEach(pair => {
expect(pair.value.toString()).equals(pair.flux)
})
})
})