-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle backticks surrounding IDs (#622)
Closes #579 ### Summary of Changes Backticks allow using keywords as IDs. This now removes them properly from IDs. --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
- Loading branch information
1 parent
a51a644
commit 608e470
Showing
20 changed files
with
137 additions
and
4 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js'; | ||
import { EmptyFileSystem } from 'langium'; | ||
import { getNodeOfType } from '../../helpers/nodeFinder.js'; | ||
import { | ||
isSdsClass, | ||
isSdsModule, | ||
isSdsTemplateStringEnd, | ||
isSdsTemplateStringInner, | ||
isSdsTemplateStringStart, | ||
} from '../../../src/language/generated/ast.js'; | ||
|
||
const services = createSafeDsServices(EmptyFileSystem).SafeDs; | ||
|
||
describe('runConverter', () => { | ||
it('should remove backticks from IDs (package)', async () => { | ||
const code = ` | ||
package \`foo\`.bar | ||
`; | ||
|
||
const module = await getNodeOfType(services, code, isSdsModule); | ||
expect(module.name).toBe('foo.bar'); | ||
}); | ||
|
||
it('should remove backticks from IDs (declaration)', async () => { | ||
const code = ` | ||
class \`MyClass\` | ||
`; | ||
|
||
const firstClass = await getNodeOfType(services, code, isSdsClass); | ||
expect(firstClass.name).toBe('MyClass'); | ||
}); | ||
|
||
it('should remove delimiters from TEMPLATE_STRING_STARTs', async () => { | ||
const code = ` | ||
pipeline myPipeline { | ||
"start{{ 1 }}inner{{ 2 }}end"; | ||
} | ||
`; | ||
|
||
const firstTemplateStringStart = await getNodeOfType(services, code, isSdsTemplateStringStart); | ||
expect(firstTemplateStringStart.value).toBe('start'); | ||
}); | ||
|
||
it('should handle escape sequences in TEMPLATE_STRING_STARTs', async () => { | ||
const code = ` | ||
pipeline myPipeline { | ||
"\\tstart{{ 1 }}inner{{ 2 }}end"; | ||
} | ||
`; | ||
|
||
const firstTemplateStringStart = await getNodeOfType(services, code, isSdsTemplateStringStart); | ||
expect(firstTemplateStringStart.value).toBe('\tstart'); | ||
}); | ||
|
||
it('should remove delimiters from TEMPLATE_STRING_INNERs', async () => { | ||
const code = ` | ||
pipeline myPipeline { | ||
"start{{ 1 }}inner{{ 2 }}end"; | ||
} | ||
`; | ||
|
||
const firstTemplateStringInner = await getNodeOfType(services, code, isSdsTemplateStringInner); | ||
expect(firstTemplateStringInner.value).toBe('inner'); | ||
}); | ||
|
||
it('should handle escape sequences in TEMPLATE_STRING_INNERs', async () => { | ||
const code = ` | ||
pipeline myPipeline { | ||
"start{{ 1 }}\\tinner{{ 2 }}end"; | ||
} | ||
`; | ||
|
||
const firstTemplateStringInner = await getNodeOfType(services, code, isSdsTemplateStringInner); | ||
expect(firstTemplateStringInner.value).toBe('\tinner'); | ||
}); | ||
|
||
it('should remove delimiters from TEMPLATE_STRING_ENDs', async () => { | ||
const code = ` | ||
pipeline myPipeline { | ||
"start{{ 1 }}inner{{ 2 }}end"; | ||
} | ||
`; | ||
|
||
const firstTemplateStringEnd = await getNodeOfType(services, code, isSdsTemplateStringEnd); | ||
expect(firstTemplateStringEnd.value).toBe('end'); | ||
}); | ||
|
||
it('should handle escape sequences in TEMPLATE_STRING_ENDs', async () => { | ||
const code = ` | ||
pipeline myPipeline { | ||
"start{{ 1 }}inner{{ 2 }}\\tend"; | ||
} | ||
`; | ||
|
||
const firstTemplateStringEnd = await getNodeOfType(services, code, isSdsTemplateStringEnd); | ||
expect(firstTemplateStringEnd.value).toBe('\tend'); | ||
}); | ||
}); |
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
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
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
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
2 changes: 2 additions & 0 deletions
2
tests/resources/validation/names/casing/package name lowercase escaped.sdstest
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,2 @@ | ||
// $TEST$ no warning "All segments of the qualified name of a package should be lowerCamelCase." | ||
package »tests.validation.declarations.`lowercase1`« |
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
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
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
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