|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { ModelElementBase } from './modelElementBase'; |
| 3 | +import { VisitMode } from './modelElement'; |
| 4 | + |
| 5 | +let sut!: ModelElementBase; |
| 6 | +describe('ModelElementBase', () => { |
| 7 | + beforeEach(() => { |
| 8 | + sut = new ModelElementBase(); |
| 9 | + }); |
| 10 | + |
| 11 | + it('getId() is not null', () => { |
| 12 | + expect(sut.getId()).not.eqls(null); |
| 13 | + }); |
| 14 | + it('getId() is string', () => { |
| 15 | + expect(sut.getId()).not.eqls(null); |
| 16 | + expect(typeof sut.getId()).eqls('string'); |
| 17 | + }); |
| 18 | + it('getTypeName() is ModelElementDef', () => { |
| 19 | + expect(sut.getTypeName()).eqls('ModelElementBase'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('identity check', () => { |
| 23 | + expect(sut.identity()).eqls(sut.identity()); |
| 24 | + const sut2 = new ModelElementBase(); |
| 25 | + expect(sut2.identity()).not.eqls(sut.identity()); |
| 26 | + }); |
| 27 | + it('sameConcept() compared with null', () => { |
| 28 | + expect(sut.sameConcept(null)).eqls(false); |
| 29 | + }); |
| 30 | + it('sameConcept() compared with undefined', () => { |
| 31 | + expect(sut.sameConcept(undefined)).eqls(false); |
| 32 | + }); |
| 33 | + it('sameConcept() compared with self', () => { |
| 34 | + expect(sut.sameConcept(sut)).eqls(true); |
| 35 | + }); |
| 36 | + it('sameConcept() compared with other', () => { |
| 37 | + const sut2 = new ModelElementBase(); |
| 38 | + expect(sut.sameConcept(sut2)).eqls(false); |
| 39 | + }); |
| 40 | + it('equals() compared with self', () => { |
| 41 | + expect(sut.equals(sut)).eqls(true); |
| 42 | + }); |
| 43 | + it('equals() compared with other', () => { |
| 44 | + const sut2 = new ModelElementBase(); |
| 45 | + expect(sut.sameConcept(sut2)).eqls(false); |
| 46 | + }); |
| 47 | + it('hashCodeElement() compared with other', () => { |
| 48 | + const sut2 = new ModelElementBase(); |
| 49 | + const hash1 = sut.hashCodeElement(); |
| 50 | + const hash2 = sut2.hashCodeElement(); |
| 51 | + expect(hash1).not.eqls(hash2); |
| 52 | + }); |
| 53 | + it('hashCodeElement() compared with self', () => { |
| 54 | + const hash1 = sut.hashCodeElement(); |
| 55 | + const hash2 = sut.hashCodeElement(); |
| 56 | + expect(hash1).eqls(hash2); |
| 57 | + }); |
| 58 | + it('visit() preOrder', () => { |
| 59 | + let acc = 0; |
| 60 | + sut.visit(VisitMode.PreOrder, () => { |
| 61 | + acc++; |
| 62 | + }); |
| 63 | + expect(acc).eqls(1); |
| 64 | + }); |
| 65 | + it('visit() postOrder', () => { |
| 66 | + let acc = 0; |
| 67 | + sut.visit(VisitMode.PostOrder, () => { |
| 68 | + acc++; |
| 69 | + }); |
| 70 | + expect(acc).eqls(1); |
| 71 | + }); |
| 72 | + it('toJson()', () => { |
| 73 | + expect(sut.toJson()).eqls('{}'); |
| 74 | + }); |
| 75 | + it('toEssential()', () => { |
| 76 | + const id = sut._meta.id; |
| 77 | + expect(sut.toEssential()).eqls(`ModelElementBase ${id} {\n}\n`); |
| 78 | + }); |
| 79 | + it('visitChildren()', () => { |
| 80 | + let acc = 0; |
| 81 | + sut.visitChildren(VisitMode.PreOrder, () => { |
| 82 | + acc++; |
| 83 | + }); |
| 84 | + expect(acc).eqls(0); |
| 85 | + }); |
| 86 | + it('validate()', () => { |
| 87 | + expect(sut.validate()).eqls([]); |
| 88 | + }); |
| 89 | +}); |
0 commit comments