-
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.
test: data-driven scope testing (#546)
Closes partially #540. ### Summary of Changes * Data-driven creation of scope tests * Clean up of creation of grammar and formatter tests --------- Co-authored-by: megalinter-bot <[email protected]>
- Loading branch information
1 parent
c3c2aef
commit f814f16
Showing
20 changed files
with
621 additions
and
124 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
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,96 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { isLocationEqual, locationToString, positionToString, rangeToString } from './location'; | ||
|
||
describe('positionToString', () => { | ||
it.each([ | ||
{ | ||
position: { line: 0, character: 0 }, | ||
expected: '1:1', | ||
}, | ||
{ | ||
position: { line: 1, character: 0 }, | ||
expected: '2:1', | ||
}, | ||
])('should convert position to string ($expected)', ({ position, expected }) => { | ||
expect(positionToString(position)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('rangeToString', () => { | ||
it.each([ | ||
{ | ||
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } }, | ||
expected: '1:1 -> 1:1', | ||
}, | ||
{ | ||
range: { start: { line: 0, character: 0 }, end: { line: 1, character: 0 } }, | ||
expected: '1:1 -> 2:1', | ||
}, | ||
])('should convert range to string ($expected)', ({ range, expected }) => { | ||
expect(rangeToString(range)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('locationToString', () => { | ||
it.each([ | ||
{ | ||
location: { | ||
uri: 'file:///test.sdstest', | ||
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } }, | ||
}, | ||
expected: 'file:///test.sdstest:1:1 -> 1:1', | ||
}, | ||
{ | ||
location: { | ||
uri: 'file:///test.sdstest', | ||
range: { start: { line: 0, character: 0 }, end: { line: 1, character: 0 } }, | ||
}, | ||
expected: 'file:///test.sdstest:1:1 -> 2:1', | ||
}, | ||
])(`should convert location to string ($expected)`, ({ location, expected }) => { | ||
expect(locationToString(location)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('isLocationEqual', () => { | ||
it.each([ | ||
{ | ||
location1: { | ||
uri: 'file:///test.sdstest', | ||
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } }, | ||
}, | ||
location2: { | ||
uri: 'file:///test.sdstest', | ||
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } }, | ||
}, | ||
expected: true, | ||
id: 'same location', | ||
}, | ||
{ | ||
location1: { | ||
uri: 'file:///test.sdstest', | ||
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } }, | ||
}, | ||
location2: { | ||
uri: 'file:///test2.sdstest', | ||
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } }, | ||
}, | ||
expected: false, | ||
id: 'different uri', | ||
}, | ||
{ | ||
location1: { | ||
uri: 'file:///test.sdstest', | ||
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } }, | ||
}, | ||
location2: { | ||
uri: 'file:///test.sdstest', | ||
range: { start: { line: 0, character: 0 }, end: { line: 1, character: 0 } }, | ||
}, | ||
expected: false, | ||
id: 'different range', | ||
}, | ||
])('should compare locations for equality ($id)', ({ location1, location2, expected }) => { | ||
expect(isLocationEqual(location1, location2)).toBe(expected); | ||
}); | ||
}); |
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,43 @@ | ||
import { Location, Position, Range } from 'vscode-languageserver'; | ||
import { isRangeEqual } from 'langium/test'; | ||
|
||
/** | ||
* Converts a position to a string. | ||
* | ||
* @param position The position to convert. | ||
* @returns The string representation of the position. | ||
*/ | ||
export const positionToString = (position: Position): string => { | ||
return `${position.line + 1}:${position.character + 1}`; | ||
}; | ||
|
||
/** | ||
* Converts a range to a string. | ||
* | ||
* @param range The range to convert. | ||
* @returns The string representation of the range. | ||
*/ | ||
export const rangeToString = (range: Range): string => { | ||
return `${positionToString(range.start)} -> ${positionToString(range.end)}`; | ||
}; | ||
|
||
/** | ||
* Converts a location to a string. | ||
* | ||
* @param location The location to convert. | ||
* @returns The string representation of the location. | ||
*/ | ||
export const locationToString = (location: Location) => { | ||
return `${location.uri}:${rangeToString(location.range)}`; | ||
}; | ||
|
||
/** | ||
* Compare two locations for equality.ts. | ||
* | ||
* @param location1 The first location. | ||
* @param location2 The second location. | ||
* @returns True if the locations are equal, false otherwise. | ||
*/ | ||
export const isLocationEqual = (location1: Location, location2: Location): boolean => { | ||
return location1.uri === location2.uri && isRangeEqual(location1.range, location2.range); | ||
}; |
Oops, something went wrong.