Skip to content

Commit

Permalink
add tests for modelElementBase
Browse files Browse the repository at this point in the history
  • Loading branch information
pjmolina committed Dec 6, 2024
1 parent bb5bb2e commit e0dd854
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Base clases and interfaces for:
- Linting
- Model Element Sequencer

[Changelog](./doc/Changelog.md)

## License

Published as **Apache-2.0** License.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metadev/essential-core",
"version": "1.0.0",
"version": "1.0.1",
"bugs": {
"url": "https://github.com/metadevpro/essential-core/issues"
},
Expand Down
89 changes: 89 additions & 0 deletions src/modelElementBase.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { expect } from 'chai';
import { ModelElementBase } from './modelElementBase';
import { VisitMode } from './modelElement';

let sut!: ModelElementBase;
describe('ModelElementBase', () => {
beforeEach(() => {
sut = new ModelElementBase();
});

it('getId() is not null', () => {
expect(sut.getId()).not.eqls(null);
});
it('getId() is string', () => {
expect(sut.getId()).not.eqls(null);
expect(typeof sut.getId()).eqls('string');
});
it('getTypeName() is ModelElementDef', () => {
expect(sut.getTypeName()).eqls('ModelElementBase');
});

it('identity check', () => {
expect(sut.identity()).eqls(sut.identity());
const sut2 = new ModelElementBase();
expect(sut2.identity()).not.eqls(sut.identity());
});
it('sameConcept() compared with null', () => {
expect(sut.sameConcept(null)).eqls(false);
});
it('sameConcept() compared with undefined', () => {
expect(sut.sameConcept(undefined)).eqls(false);
});
it('sameConcept() compared with self', () => {
expect(sut.sameConcept(sut)).eqls(true);
});
it('sameConcept() compared with other', () => {
const sut2 = new ModelElementBase();
expect(sut.sameConcept(sut2)).eqls(false);
});
it('equals() compared with self', () => {
expect(sut.equals(sut)).eqls(true);
});
it('equals() compared with other', () => {
const sut2 = new ModelElementBase();
expect(sut.sameConcept(sut2)).eqls(false);
});
it('hashCodeElement() compared with other', () => {
const sut2 = new ModelElementBase();
const hash1 = sut.hashCodeElement();
const hash2 = sut2.hashCodeElement();
expect(hash1).not.eqls(hash2);
});
it('hashCodeElement() compared with self', () => {
const hash1 = sut.hashCodeElement();
const hash2 = sut.hashCodeElement();
expect(hash1).eqls(hash2);
});
it('visit() preOrder', () => {
let acc = 0;
sut.visit(VisitMode.PreOrder, () => {
acc++;
});
expect(acc).eqls(1);
});
it('visit() postOrder', () => {
let acc = 0;
sut.visit(VisitMode.PostOrder, () => {
acc++;
});
expect(acc).eqls(1);
});
it('toJson()', () => {
expect(sut.toJson()).eqls('{}');
});
it('toEssential()', () => {
const id = sut._meta.id;
expect(sut.toEssential()).eqls(`ModelElementBase ${id} {\n}\n`);
});
it('visitChildren()', () => {
let acc = 0;
sut.visitChildren(VisitMode.PreOrder, () => {
acc++;
});
expect(acc).eqls(0);
});
it('validate()', () => {
expect(sut.validate()).eqls([]);
});
});

0 comments on commit e0dd854

Please sign in to comment.