-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented testing for new language
- Loading branch information
1 parent
62ae32c
commit a40b2b8
Showing
33 changed files
with
3,829 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node' | ||
}; |
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,5 @@ | ||
const baseConfig = require('../../configs/jest.config'); | ||
|
||
module.exports = { | ||
...baseConfig | ||
}; |
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
133 changes: 133 additions & 0 deletions
133
extensions/crossmodel-lang/test/language-server/cross-model-lang-diagram.test.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,133 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 CrossBreeze. | ||
********************************************************************************/ | ||
import { describe, expect, test } from '@jest/globals'; | ||
import { EmptyFileSystem, isReference } from 'langium'; | ||
|
||
import { parseDocument } from './utils/utils'; | ||
import { diagram1, diagram2, diagram3, diagram4, diagram5, diagram6 } from './utils/test-documents/diagram/index'; | ||
|
||
import { CrossModelRoot } from '../../src/language-server/generated/ast'; | ||
import { createCrossModelServices } from '../../src/language-server/cross-model-module'; | ||
|
||
const services = createCrossModelServices({ ...EmptyFileSystem }).CrossModel; | ||
|
||
describe('CrossModel language Diagram', () => { | ||
describe('Diagram without nodes and edges', () => { | ||
test('Simple file for diagram', async () => { | ||
const document = diagram1; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
|
||
expect(model).toHaveProperty('diagram'); | ||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(0); | ||
|
||
expect(model.diagram?.name).toBe('Systemdiagram1'); | ||
}); | ||
|
||
test('Diagram with indentation error', async () => { | ||
const document = diagram4; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
|
||
expect(model).toHaveProperty('diagram'); | ||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('Diagram with nodes', () => { | ||
test('Simple file for diagram and nodes', async () => { | ||
const document = diagram2; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
const node1 = model.diagram?.nodes[0]; | ||
|
||
expect(model).toHaveProperty('diagram'); | ||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(0); | ||
|
||
expect(model.diagram?.nodes.length).toBe(1); | ||
|
||
expect(node1?.name).toBe('CustomerNode'); | ||
expect(isReference(node1?.for)).toBe(true); | ||
expect(node1?.for?.$refText).toBe('Customer'); | ||
expect(node1?.x).toBe(100); | ||
}); | ||
}); | ||
|
||
describe('Diagram with edges', () => { | ||
test('Simple file for diagram and edges', async () => { | ||
const document = diagram3; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
const edge1 = model.diagram?.edges[0]; | ||
|
||
expect(model).toHaveProperty('diagram'); | ||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(0); | ||
|
||
expect(model.diagram?.edges.length).toBe(1); | ||
|
||
expect(edge1?.name).toBe('OrderCustomerEdge'); | ||
expect(isReference(edge1?.for)).toBe(true); | ||
expect(edge1?.for?.$refText).toBe('Order_Customer'); | ||
}); | ||
}); | ||
|
||
describe('Diagram with nodes and edges', () => { | ||
test('Simple file for diagram and edges', async () => { | ||
const document = diagram5; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
const node1 = model.diagram?.nodes[0]; | ||
const edge1 = model.diagram?.edges[0]; | ||
|
||
expect(model).toHaveProperty('diagram'); | ||
|
||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(0); | ||
|
||
expect(model.diagram?.name_val).toBe('System diagram 1'); | ||
expect(model.diagram?.description).toBe('This is a basic diagram with nodes and edges'); | ||
expect(model.diagram?.nodes.length).toBe(1); | ||
expect(model.diagram?.edges.length).toBe(1); | ||
|
||
expect(node1?.name).toBe('CustomerNode'); | ||
expect(isReference(node1?.for)).toBe(true); | ||
expect(node1?.for?.$refText).toBe('Customer'); | ||
expect(node1?.x).toBe(100); | ||
|
||
expect(edge1?.name).toBe('OrderCustomerEdge'); | ||
expect(isReference(edge1?.for)).toBe(true); | ||
expect(edge1?.for?.$refText).toBe('Order_Customer'); | ||
}); | ||
|
||
test('Simple file for diagram and edges, but descirption and name coming last', async () => { | ||
const document = diagram6; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
const node1 = model.diagram?.nodes[0]; | ||
const edge1 = model.diagram?.edges[0]; | ||
|
||
expect(model).toHaveProperty('diagram'); | ||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(0); | ||
|
||
expect(model.diagram?.name_val).toBe('System diagram 1'); | ||
expect(model.diagram?.description).toBe('This is a basic diagram with nodes and edges'); | ||
expect(model.diagram?.nodes.length).toBe(1); | ||
expect(model.diagram?.edges.length).toBe(1); | ||
|
||
expect(node1?.name).toBe('CustomerNode'); | ||
expect(isReference(node1?.for)).toBe(true); | ||
expect(node1?.for?.$refText).toBe('Customer'); | ||
expect(node1?.x).toBe(100); | ||
|
||
expect(edge1?.name).toBe('OrderCustomerEdge'); | ||
expect(isReference(edge1?.for)).toBe(true); | ||
expect(edge1?.for?.$refText).toBe('Order_Customer'); | ||
}); | ||
}); | ||
}); |
79 changes: 79 additions & 0 deletions
79
extensions/crossmodel-lang/test/language-server/cross-model-lang-entity.test.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,79 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 CrossBreeze. | ||
********************************************************************************/ | ||
|
||
import { describe, expect, test } from '@jest/globals'; | ||
import { EmptyFileSystem } from 'langium'; | ||
|
||
import { parseDocument } from './utils/utils'; | ||
import { entity1, entity2, entity3, entity4 } from './utils/test-documents/entity/index'; | ||
|
||
import { CrossModelRoot } from '../../src/language-server/generated/ast'; | ||
import { createCrossModelServices } from '../../src/language-server/cross-model-module'; | ||
|
||
const services = createCrossModelServices({ ...EmptyFileSystem }).CrossModel; | ||
|
||
describe('CrossModel language Entity', () => { | ||
describe('Without attributes', () => { | ||
test('Simple file for entity', async () => { | ||
const document = entity1; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
|
||
expect(model).toHaveProperty('entity'); | ||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(0); | ||
|
||
expect(model.entity?.name).toBe('Customer'); | ||
expect(model.entity?.name_val).toBe('Customer'); | ||
expect(model.entity?.description).toBe('A customer with whom a transaction has been made.'); | ||
}); | ||
}); | ||
|
||
describe('With attributes', () => { | ||
test('entity with attributes', async () => { | ||
const document = entity2; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
|
||
expect(model).toHaveProperty('entity'); | ||
|
||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(0); | ||
|
||
expect(model.entity?.attributes.length).toBe(6); | ||
expect(model.entity?.attributes[0].name).toBe('Id'); | ||
expect(model.entity?.attributes[0].name_val).toBe('Id'); | ||
expect(model.entity?.attributes[0].datatype).toBe('int'); | ||
}); | ||
|
||
test('entity with attributes coming before the description and name', async () => { | ||
const document = entity4; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
|
||
expect(model).toHaveProperty('entity'); | ||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(0); | ||
|
||
expect(model.entity?.name).toBe('Customer'); | ||
expect(model.entity?.name_val).toBe('Customer'); | ||
expect(model.entity?.description).toBe('A customer with whom a transaction has been made.'); | ||
|
||
expect(model.entity?.attributes.length).toBe(6); | ||
expect(model.entity?.attributes[0].name).toBe('Id'); | ||
expect(model.entity?.attributes[0].name_val).toBe('Id'); | ||
expect(model.entity?.attributes[0].datatype).toBe('int'); | ||
}); | ||
|
||
test('entity with indentation error', async () => { | ||
const document = entity3; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
|
||
expect(model).toHaveProperty('entity'); | ||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(1); | ||
}); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
extensions/crossmodel-lang/test/language-server/cross-model-lang-relationship.test.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,46 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 CrossBreeze. | ||
********************************************************************************/ | ||
|
||
import { describe, expect, test } from '@jest/globals'; | ||
import { EmptyFileSystem, isReference } from 'langium'; | ||
|
||
import { parseDocument } from './utils/utils'; | ||
import { relationship1, relationship2 } from './utils/test-documents/relationship/index'; | ||
|
||
import { CrossModelRoot } from '../../src/language-server/generated/ast'; | ||
import { createCrossModelServices } from '../../src/language-server/cross-model-module'; | ||
|
||
const services = createCrossModelServices({ ...EmptyFileSystem }).CrossModel; | ||
|
||
describe('CrossModel language Relationship', () => { | ||
test('Simple file for relationship', async () => { | ||
const document = relationship1; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
|
||
expect(model).toHaveProperty('relationship'); | ||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(0); | ||
|
||
expect(model.relationship?.name).toBe('Order_Customer'); | ||
expect(model.relationship?.name_val).toBe('Customer Order relationship'); | ||
expect(model.relationship?.type).toBe('1:1'); | ||
expect(model.relationship?.description).toBe('A relationship between a customer and an order.'); | ||
|
||
expect(isReference(model.relationship?.parent)).toBe(true); | ||
expect(isReference(model.relationship?.child)).toBe(true); | ||
expect(model.relationship?.parent?.$refText).toBe('Customer'); | ||
expect(model.relationship?.child?.$refText).toBe('Order'); | ||
}); | ||
|
||
test('relationship with indentation error', async () => { | ||
const document = relationship2; | ||
const parsedDocument = await parseDocument(services, document); | ||
const model = parsedDocument.parseResult.value as CrossModelRoot; | ||
|
||
expect(model).toHaveProperty('relationship'); | ||
expect(parsedDocument.parseResult.lexerErrors.length).toBe(0); | ||
expect(parsedDocument.parseResult.parserErrors.length).toBe(1); | ||
}); | ||
}); |
Oops, something went wrong.