-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2fa0bc
commit 87d0e88
Showing
9 changed files
with
191 additions
and
28 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
16 changes: 16 additions & 0 deletions
16
extensions/crossmodel-lang/test/language-server/test-utils/test-documents/entity/address.ts
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,16 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 CrossBreeze. | ||
********************************************************************************/ | ||
export const address = `entity: | ||
id: Address | ||
name: "Address" | ||
attributes: | ||
- id: CustomerID | ||
name: "CustomerID" | ||
datatype: "Integer" | ||
- id: Street | ||
name: "Street" | ||
datatype: "Varchar" | ||
- id: CountryCode | ||
name: "CountryCode" | ||
datatype: "Varchar"`; |
28 changes: 28 additions & 0 deletions
28
extensions/crossmodel-lang/test/language-server/test-utils/test-documents/entity/customer.ts
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,28 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 CrossBreeze. | ||
********************************************************************************/ | ||
export const customer = `entity: | ||
id: Customer | ||
name: "Customer" | ||
attributes: | ||
- id: Id | ||
name: "Id" | ||
datatype: "Integer" | ||
- id: FirstName | ||
name: "FirstName" | ||
datatype: "Varchar" | ||
- id: LastName | ||
name: "LastName" | ||
datatype: "Varchar" | ||
- id: City | ||
name: "City" | ||
datatype: "Varchar" | ||
- id: Country | ||
name: "Country" | ||
datatype: "Varchar" | ||
- id: Phone | ||
name: "Phone" | ||
datatype: "Varchar" | ||
- id: BirthDate | ||
name: "BirthDate" | ||
datatype: "DateTime"`; |
3 changes: 3 additions & 0 deletions
3
extensions/crossmodel-lang/test/language-server/test-utils/test-documents/entity/index.ts
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 CrossBreeze. | ||
********************************************************************************/ | ||
export * from './address.js'; | ||
export * from './customer.js'; | ||
export * from './entity1.js'; | ||
export * from './entity2.js'; | ||
export * from './entity3.js'; | ||
export * from './entity4.js'; | ||
export * from './order.js'; |
23 changes: 23 additions & 0 deletions
23
extensions/crossmodel-lang/test/language-server/test-utils/test-documents/entity/order.ts
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,23 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 CrossBreeze. | ||
********************************************************************************/ | ||
export const order = `entity: | ||
id: Order | ||
name: "Order" | ||
description: "Order placed by a customer in the Customer table." | ||
attributes: | ||
- id: Id | ||
name: "Id" | ||
datatype: "Integer" | ||
- id: OrderDate | ||
name: "OrderDate" | ||
datatype: "Integer" | ||
- id: OrderNumber | ||
name: "OrderNumber" | ||
datatype: "Varchar" | ||
- id: CustomerId | ||
name: "CustomerId" | ||
datatype: "Integer" | ||
- id: TotalAmount | ||
name: "TotalAmount" | ||
datatype: "Float"`; |
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
35 changes: 35 additions & 0 deletions
35
...ang/test/language-server/test-utils/test-documents/relationship/relationship_attribute.ts
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,35 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 CrossBreeze. | ||
********************************************************************************/ | ||
|
||
/** Valid relationship with attribute */ | ||
export const relationship_with_attribute = `relationship: | ||
id: Order_Customer | ||
parent: Customer | ||
child: Order | ||
type: "1:1" | ||
attributes: | ||
- parent: Customer.Id | ||
child: Order.CustomerId`; | ||
|
||
/** Relationship with invalid attribute (wrong entity) */ | ||
export const relationship_with_attribute_wrong_entity = `relationship: | ||
id: Order_Customer | ||
parent: Customer | ||
child: Order | ||
type: "1:1" | ||
attributes: | ||
- parent: Customer.Id | ||
child: Order.Address`; | ||
|
||
/** Relationship with invalid attribute (duplicates) */ | ||
export const relationship_with_duplicate_attributes = `relationship: | ||
id: Order_Customer | ||
parent: Customer | ||
child: Order | ||
type: "1:1" | ||
attributes: | ||
- parent: Customer.Id | ||
child: Order.CustomerId | ||
- parent: Customer.Id | ||
child: Order.CustomerId`; |
45 changes: 26 additions & 19 deletions
45
extensions/crossmodel-lang/test/language-server/test-utils/utils.ts
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 |
---|---|---|
@@ -1,26 +1,33 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 CrossBreeze. | ||
********************************************************************************/ | ||
import { AstNode, LangiumDocument, LangiumServices } from 'langium'; | ||
import { URI } from 'vscode-uri'; | ||
|
||
export async function parseDocument<T extends AstNode = AstNode>(services: LangiumServices, input: string): Promise<LangiumDocument<T>> { | ||
const document = await parseHelper<T>(services)(input); | ||
if (!document.parseResult) { | ||
throw new Error('Could not parse document'); | ||
} | ||
return document; | ||
import { AstNode, DefaultLangiumDocuments, EmptyFileSystem, LangiumDocument, LangiumServices } from 'langium'; | ||
import { ParseHelperOptions, clearDocuments, parseDocument } from 'langium/test'; | ||
import { CrossModelServices, createCrossModelServices } from '../../../src/language-server/cross-model-module.js'; | ||
|
||
export { parseDocument } from 'langium/test'; | ||
|
||
export function createCrossModelTestServices(): CrossModelServices { | ||
const services = createCrossModelServices({ ...EmptyFileSystem }).CrossModel; | ||
services.shared.workspace.LangiumDocuments = new DefaultLangiumDocuments(services.shared); | ||
return services; | ||
} | ||
|
||
export function parseHelper<T extends AstNode = AstNode>(services: LangiumServices): (input: string) => Promise<LangiumDocument<T>> { | ||
const metaData = services.LanguageMetaData; | ||
const documentBuilder = services.shared.workspace.DocumentBuilder; | ||
return async input => { | ||
const randomNumber = Math.floor(Math.random() * 10000000) + 1000000; | ||
const uri = URI.parse(`file:///${randomNumber}${metaData.fileExtensions[0]}`); | ||
const document = services.shared.workspace.LangiumDocumentFactory.fromString<T>(input, uri); | ||
services.shared.workspace.LangiumDocuments.addDocument(document); | ||
await documentBuilder.build([document]); | ||
return document; | ||
}; | ||
export async function parseDocuments<T extends AstNode = AstNode>( | ||
services: LangiumServices, | ||
inputs: string[], | ||
options?: ParseHelperOptions | ||
): Promise<LangiumDocument<T>[]> { | ||
return Promise.all(inputs.map(input => parseDocument<T>(services, input, options))); | ||
} | ||
|
||
export async function parseAndForgetDocument<T extends AstNode = AstNode>( | ||
services: LangiumServices, | ||
input: string, | ||
options?: ParseHelperOptions | ||
): Promise<LangiumDocument<T>> { | ||
const document = await parseDocument<T>(services, input, options); | ||
await clearDocuments(services, [document]); | ||
return document; | ||
} |