-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: escape keban case in jsonata expression
- Loading branch information
Showing
3 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/components/Extensibility/helpers/tests/escapeKebabCase.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { escapeKebabCase } from '../jsonataWrapper'; | ||
|
||
describe('escapeKebabCase', () => { | ||
it('regular path', () => { | ||
const expression = '$root.spec.myRegularPath'; | ||
expect(escapeKebabCase(expression)).toBe('$root.spec.myRegularPath'); | ||
}); | ||
|
||
it('kebab path 1', () => { | ||
const expression = '$root.spec.my-kebab-path'; | ||
expect(escapeKebabCase(expression)).toBe('$root.spec.`my-kebab-path`'); | ||
}); | ||
|
||
it('kebab path, regular path', () => { | ||
const expression = '$root.spec.my-kebab-path.subPath'; | ||
expect(escapeKebabCase(expression)).toBe( | ||
'$root.spec.`my-kebab-path`.subPath', | ||
); | ||
}); | ||
|
||
it('multiple kebab paths', () => { | ||
const expression = '$root.spec.my-kebab-path.sub-path'; | ||
expect(escapeKebabCase(expression)).toBe( | ||
'$root.spec.`my-kebab-path`.`sub-path`', | ||
); | ||
}); | ||
|
||
it('special path', () => { | ||
const expression = '$root.spec.some-$special-path'; | ||
expect(escapeKebabCase(expression)).toBe('$root.spec.`some-$special-path`'); | ||
}); | ||
|
||
it('direct follow-up 1', () => { | ||
const expression = '$root.spec.my-kebab-path.subPath!=true'; | ||
expect(escapeKebabCase(expression)).toBe( | ||
'$root.spec.`my-kebab-path`.subPath!=true', | ||
); | ||
}); | ||
|
||
it('direct follow-up 2', () => { | ||
const expression = '$root.spec.my-kebab-path.subPath != true'; | ||
expect(escapeKebabCase(expression)).toBe( | ||
'$root.spec.`my-kebab-path`.subPath != true', | ||
); | ||
}); | ||
|
||
it('numeric expression 1', () => { | ||
const expression = '4 - 6'; | ||
expect(escapeKebabCase(expression)).toBe('4 - 6'); | ||
}); | ||
|
||
it('numeric expression 2', () => { | ||
const expression = '$item.value1 - $item.value2'; | ||
expect(escapeKebabCase(expression)).toBe('$item.value1 - $item.value2'); | ||
}); | ||
|
||
it('numeric expression 3', () => { | ||
const expression = '$item.value-one - $item.value-two'; | ||
expect(escapeKebabCase(expression)).toBe( | ||
'$item.`value-one` - $item.`value-two`', | ||
); | ||
}); | ||
|
||
it('string literal 1', () => { | ||
const expression = "hello, 'this-is-a-string', some-path"; | ||
expect(escapeKebabCase(expression)).toBe( | ||
"hello, 'this-is-a-string', `some-path`", | ||
); | ||
}); | ||
|
||
it('string literal 2', () => { | ||
const expression = 'hello, "this-is-a-string", some-path'; | ||
expect(escapeKebabCase(expression)).toBe( | ||
'hello, "this-is-a-string", `some-path`', | ||
); | ||
}); | ||
|
||
it('string literal 3', () => { | ||
const expression = 'hello, `this-is-a-string`, some-path'; | ||
expect(escapeKebabCase(expression)).toBe( | ||
'hello, `this-is-a-string`, `some-path`', | ||
); | ||
}); | ||
}); |