ts2famix 1.0.1 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyze.js +102 -0
- package/dist/analyze_functions/processAccesses.js +47 -0
- package/dist/analyze_functions/processFiles.js +540 -0
- package/dist/analyze_functions/processImportClauses.js +70 -0
- package/dist/analyze_functions/processInheritances.js +73 -0
- package/dist/analyze_functions/processInvocations.js +49 -0
- package/dist/famix2puml.js +125 -0
- package/dist/famix_functions/famix_functions.js +513 -0
- package/dist/famix_functions/famix_functions_associations.js +205 -0
- package/dist/famix_functions/famix_functions_index.js +62 -0
- package/dist/famix_functions/famix_functions_types.js +110 -0
- package/dist/fqn.js +126 -0
- package/dist/fqp_implementation.js +73 -0
- package/dist/lib/famix/src/famix_JSON_exporter.js +54 -0
- package/dist/lib/famix/src/famix_base_element.js +13 -0
- package/dist/lib/famix/src/famix_repository.js +187 -0
- package/dist/lib/famix/src/index.js +30 -0
- package/dist/lib/famix/src/model/famix/access.js +39 -0
- package/dist/lib/famix/src/model/famix/accessor.js +16 -0
- package/dist/lib/famix/src/model/famix/alias.js +32 -0
- package/dist/lib/famix/src/model/famix/association.js +36 -0
- package/dist/lib/famix/src/model/famix/behavioral_entity.js +81 -0
- package/dist/lib/famix/src/model/famix/c_source_language.js +16 -0
- package/dist/lib/famix/src/model/famix/class.js +70 -0
- package/dist/lib/famix/src/model/famix/comment.js +38 -0
- package/dist/lib/famix/src/model/famix/container_entity.js +125 -0
- package/dist/lib/famix/src/model/famix/custom_source_language.js +23 -0
- package/dist/lib/famix/src/model/famix/decorator.js +31 -0
- package/dist/lib/famix/src/model/famix/entity.js +16 -0
- package/dist/lib/famix/src/model/famix/enum.js +30 -0
- package/dist/lib/famix/src/model/famix/enum_value.js +24 -0
- package/dist/lib/famix/src/model/famix/function.js +16 -0
- package/dist/lib/famix/src/model/famix/implicit_variable.js +16 -0
- package/dist/lib/famix/src/model/famix/import_clause.js +39 -0
- package/dist/lib/famix/src/model/famix/index.js +87 -0
- package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +37 -0
- package/dist/lib/famix/src/model/famix/inheritance.js +32 -0
- package/dist/lib/famix/src/model/famix/interface.js +63 -0
- package/dist/lib/famix/src/model/famix/invocation.js +53 -0
- package/dist/lib/famix/src/model/famix/method.js +66 -0
- package/dist/lib/famix/src/model/famix/module.js +30 -0
- package/dist/lib/famix/src/model/famix/named_entity.js +77 -0
- package/dist/lib/famix/src/model/famix/namespace.js +24 -0
- package/dist/lib/famix/src/model/famix/parameter.js +24 -0
- package/dist/lib/famix/src/model/famix/parameterizable_class.js +30 -0
- package/dist/lib/famix/src/model/famix/parameterizable_interface.js +30 -0
- package/dist/lib/famix/src/model/famix/parameterized_type.js +36 -0
- package/dist/lib/famix/src/model/famix/primitive_type.js +16 -0
- package/dist/lib/famix/src/model/famix/property.js +44 -0
- package/dist/lib/famix/src/model/famix/reference.js +32 -0
- package/dist/lib/famix/src/model/famix/scoping_entity.js +30 -0
- package/dist/lib/famix/src/model/famix/script_entity.js +30 -0
- package/dist/lib/famix/src/model/famix/source_anchor.js +26 -0
- package/dist/lib/famix/src/model/famix/source_language.js +30 -0
- package/dist/lib/famix/src/model/famix/sourced_entity.js +55 -0
- package/dist/lib/famix/src/model/famix/structural_entity.js +38 -0
- package/dist/lib/famix/src/model/famix/text_anchor.js +37 -0
- package/dist/lib/famix/src/model/famix/type.js +71 -0
- package/dist/lib/famix/src/model/famix/type_parameter.js +24 -0
- package/dist/lib/famix/src/model/famix/variable.js +23 -0
- package/dist/lib/ts-complex/cyclomatic-service.js +83 -0
- package/dist/ts2famix-cli.js +51 -0
- package/dist/ts2famix-tsconfig.js +53 -0
- package/doc-uml/.gitkeep +0 -0
- package/docs/.gitkeep +0 -0
- package/jest.config.json +10 -0
- package/package.json +1 -1
- package/tsconfig.json +1 -1
- package/.github/workflows/node.js.yml +0 -60
- package/doc-metamodel/skins.include.puml +0 -2
- package/test/abstractClassWithComments.test.ts +0 -58
- package/test/abstracts.test.ts +0 -53
- package/test/access.test.ts +0 -62
- package/test/accesses.test.ts +0 -42
- package/test/accessorsWithDecorators.test.ts +0 -98
- package/test/alias.test.ts +0 -39
- package/test/classExtendsUndefinedClass.test.ts +0 -41
- package/test/classImplementsUndefinedInterface.test.ts +0 -45
- package/test/classWithDecorators.test.ts +0 -65
- package/test/entities.test.ts +0 -232
- package/test/entities_json.test.ts +0 -48
- package/test/enum.test.ts +0 -55
- package/test/functionReturnsFunction.test.ts +0 -53
- package/test/functionWithParameters.test.ts +0 -38
- package/test/functionWithVariables.test.ts +0 -64
- package/test/functions.test.ts +0 -23
- package/test/functionsInFunction.test.ts +0 -40
- package/test/functionsInMethod.test.ts +0 -42
- package/test/genericClass.test.ts +0 -42
- package/test/genericClassInheritsInterface.test.ts +0 -47
- package/test/genericInterface.test.ts +0 -38
- package/test/genericMethod.test.ts +0 -65
- package/test/genericWithInvocation.test.ts +0 -71
- package/test/generics.test.ts +0 -68
- package/test/inheritance.test.ts +0 -50
- package/test/interfaceInheritsInterface.test.ts +0 -40
- package/test/interfaceInheritsUndefinedInterface.test.ts +0 -41
- package/test/invocation.test.ts +0 -94
- package/test/invocationWithFunction.test.ts +0 -42
- package/test/invocationWithVariable.test.ts +0 -46
- package/test/invocation_json.test.ts +0 -63
- package/test/invocations.test.ts +0 -131
- package/test/jsDoc.test.ts +0 -31
- package/test/methodWithDecorator.test.ts +0 -44
- package/test/methods.test.ts +0 -42
- package/test/metrics.test.ts +0 -51
- package/test/module.test.ts +0 -71
- package/test/namespaces.test.ts +0 -54
- package/test/namespacesAndClasses.test.ts +0 -66
- package/test/parameterWithDecorators.test.ts +0 -54
- package/test/propertyWithDecorators.test.ts +0 -80
- package/test/sample.test.ts +0 -13
- package/test/simpleFunction.test.ts +0 -32
- package/test/simpleTest.test.ts +0 -18
- package/test/simpleTest2.test.ts +0 -36
- package/test/types.test.ts +0 -58
- package/test_src/sample.ts +0 -103
- package/test_src/sampleForModule.ts +0 -10
- package/test_src/sampleForModule2.ts +0 -7
- package/test_src/sampleForModule3.ts +0 -2
- /package/{jest.config.ts → jest.config-old.ts} +0 -0
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Importer } from '../src/analyze';
|
|
2
|
-
import { Function } from "../src/lib/famix/src/model/famix/function";
|
|
3
|
-
import { Variable } from "../src/lib/famix/src/model/famix/variable";
|
|
4
|
-
import { Invocation } from "../src/lib/famix/src/model/famix/invocation";
|
|
5
|
-
|
|
6
|
-
const importer = new Importer();
|
|
7
|
-
|
|
8
|
-
const fmxRep = importer.famixRepFromSource("invocationWithFunction",
|
|
9
|
-
'function func(): void {}\n\
|
|
10
|
-
\n\
|
|
11
|
-
const x1 = func();\n\
|
|
12
|
-
');
|
|
13
|
-
|
|
14
|
-
describe('Tests for invocation with function', () => {
|
|
15
|
-
|
|
16
|
-
it("should contain a variable 'x1'", () => {
|
|
17
|
-
const pList = Array.from(fmxRep._getAllEntitiesWithType("Variable") as Set<Variable>);
|
|
18
|
-
expect(pList).toBeTruthy();
|
|
19
|
-
const x1 = pList.find(p => p.getName() === "x1");
|
|
20
|
-
expect(x1).toBeTruthy();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const theFunction = fmxRep._getFamixFunction("func") as Function;
|
|
24
|
-
const invocations = Array.from(fmxRep._getAllEntitiesWithType("Invocation"));
|
|
25
|
-
|
|
26
|
-
it("should contain one invocation", () => {
|
|
27
|
-
expect(invocations).toBeTruthy();
|
|
28
|
-
expect(invocations.length).toBe(1);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("should contain an invocation for 'func'", () => {
|
|
32
|
-
expect((invocations[0] as Invocation).getCandidates().has(theFunction));
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should contain an invocation with a sender 'invocationWithFunction.ts'", () => {
|
|
36
|
-
expect((invocations[0] as Invocation).getSender()).toBe(fmxRep._getFamixFile("invocationWithFunction.ts"));
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should contain an invocation with a receiver 'invocationWithFunction.ts'", () => {
|
|
40
|
-
expect((invocations[0] as Invocation).getReceiver()).toBe(fmxRep._getFamixFile("invocationWithFunction.ts"));
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Importer } from '../src/analyze';
|
|
2
|
-
import { Method } from "../src/lib/famix/src/model/famix/method";
|
|
3
|
-
import { Variable } from "../src/lib/famix/src/model/famix/variable";
|
|
4
|
-
import { Invocation } from "../src/lib/famix/src/model/famix/invocation";
|
|
5
|
-
|
|
6
|
-
const importer = new Importer();
|
|
7
|
-
|
|
8
|
-
const fmxRep = importer.famixRepFromSource("invocationWithVariable",
|
|
9
|
-
'class AAA {\n\
|
|
10
|
-
public method(): void {}\n\
|
|
11
|
-
}\n\
|
|
12
|
-
\n\
|
|
13
|
-
const x1 = new AAA();\n\
|
|
14
|
-
x1.method();\n\
|
|
15
|
-
');
|
|
16
|
-
|
|
17
|
-
describe('Tests for invocation with variable', () => {
|
|
18
|
-
|
|
19
|
-
it("should contain a variable 'x1' instance of 'AAA'", () => {
|
|
20
|
-
const pList = Array.from(fmxRep._getAllEntitiesWithType("Variable") as Set<Variable>);
|
|
21
|
-
expect(pList).toBeTruthy();
|
|
22
|
-
const x1 = pList.find(p => p.getName() === "x1");
|
|
23
|
-
expect(x1).toBeTruthy();
|
|
24
|
-
expect(x1?.getDeclaredType().getName()).toBe("AAA");
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const theMethod = fmxRep._getFamixMethod("method") as Method;
|
|
28
|
-
const invocations = Array.from(fmxRep._getAllEntitiesWithType("Invocation"));
|
|
29
|
-
|
|
30
|
-
it("should contain one invocation", () => {
|
|
31
|
-
expect(invocations).toBeTruthy();
|
|
32
|
-
expect(invocations.length).toBe(1);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should contain an invocation for 'method'", () => {
|
|
36
|
-
expect((invocations[0] as Invocation).getCandidates().has(theMethod));
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should contain an invocation with a sender 'invocationWithVariable.ts'", () => {
|
|
40
|
-
expect((invocations[0] as Invocation).getSender()).toBe(fmxRep._getFamixFile("invocationWithVariable.ts"));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should contain an invocation with a receiver 'AAA'", () => {
|
|
44
|
-
expect((invocations[0] as Invocation).getReceiver()).toBe(fmxRep._getFamixClass("AAA"));
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Importer } from '../src/analyze';
|
|
2
|
-
|
|
3
|
-
const importer = new Importer();
|
|
4
|
-
|
|
5
|
-
const fmxRep = importer.famixRepFromSource("invocation_json",
|
|
6
|
-
'class Class1 {\n\
|
|
7
|
-
public returnHi() {}\n\
|
|
8
|
-
}\n\
|
|
9
|
-
\n\
|
|
10
|
-
class Class2 {\n\
|
|
11
|
-
public returnName() {}\n\
|
|
12
|
-
}\n\
|
|
13
|
-
\n\
|
|
14
|
-
class Class3 {\n\
|
|
15
|
-
public getString() {\n\
|
|
16
|
-
var class1Obj = new Class1();\n\
|
|
17
|
-
var class2Obj = new Class2();\n\
|
|
18
|
-
var returnValue1 = class1Obj.returnHi();\n\
|
|
19
|
-
var returnValue2 = class2Obj.returnName();\n\
|
|
20
|
-
}\n\
|
|
21
|
-
}\n\
|
|
22
|
-
');
|
|
23
|
-
|
|
24
|
-
describe('Invocations json', () => {
|
|
25
|
-
|
|
26
|
-
const jsonOutput = fmxRep.getJSON();
|
|
27
|
-
const parsedModel = JSON.parse(jsonOutput);
|
|
28
|
-
|
|
29
|
-
it("should contain a class Class3 with one method: getString", () => {
|
|
30
|
-
const invocationCls = parsedModel.filter(el => (el.FM3 === "FamixTypeScript.Class" && el.name === "Class3"))[0];
|
|
31
|
-
expect(invocationCls.methods.length).toBe(1);
|
|
32
|
-
const methodNames: Array<string> = ['getString'];
|
|
33
|
-
const invocationClsMethods = parsedModel.filter(e => invocationCls.methods.some(m => m.ref === e.id));
|
|
34
|
-
expect(invocationClsMethods.length).toBeGreaterThan(0);
|
|
35
|
-
const checkMethodName = invocationClsMethods.every(m => methodNames.includes(m.name));
|
|
36
|
-
expect(checkMethodName).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should have one invocation for method returnHi in Class1", () => {
|
|
40
|
-
verifyInvocation(parsedModel, "Class1", "returnHi");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should have one invocation for method returnName in Class2", () => {
|
|
44
|
-
verifyInvocation(parsedModel, "Class2", "returnName");
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
function verifyInvocation(parsedModel: any, theClass: string, theMethod: string) {
|
|
49
|
-
const invocationCls = parsedModel.filter(el => (el.FM3 === "FamixTypeScript.Class" && el.name === theClass))[0];
|
|
50
|
-
const invocationClsMethods = parsedModel.filter(e => invocationCls.methods.some(m => m.ref === e.id));
|
|
51
|
-
const methodNames: Array<string> = [theMethod];
|
|
52
|
-
invocationClsMethods.forEach(m => expect(methodNames).toContain(m.name));
|
|
53
|
-
const foundMethods = invocationClsMethods.filter(m => methodNames.includes(m.name));
|
|
54
|
-
expect(foundMethods.length).toBe(1);
|
|
55
|
-
const checkMethodHasInvocation = foundMethods.every(m => m.incomingInvocations !== undefined);
|
|
56
|
-
expect(checkMethodHasInvocation).toBe(true);
|
|
57
|
-
invocationClsMethods.forEach(method => {
|
|
58
|
-
const invocationCls = parsedModel.filter(e => e.FM3 === "FamixTypeScript.Invocation"
|
|
59
|
-
&& method.incomingInvocations.some(m => m.ref === e.id));
|
|
60
|
-
const checkHasRelatedToMethod = invocationCls.every(a => a.candidates.length && a.candidates[0].ref === method.id);
|
|
61
|
-
expect(checkHasRelatedToMethod).toBe(true);
|
|
62
|
-
});
|
|
63
|
-
}
|
package/test/invocations.test.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { Importer } from '../src/analyze';
|
|
2
|
-
import { Invocation, Method } from "../src/lib/famix/src/model/famix";
|
|
3
|
-
|
|
4
|
-
const importer = new Importer();
|
|
5
|
-
|
|
6
|
-
const fmxRep = importer.famixRepFromSource("invocations",
|
|
7
|
-
'class Class1 {\n\
|
|
8
|
-
public returnHi(): string {\n\
|
|
9
|
-
return "Hi";\n\
|
|
10
|
-
}\n\
|
|
11
|
-
}\n\
|
|
12
|
-
\n\
|
|
13
|
-
class Class2 {\n\
|
|
14
|
-
public returnName() {}\n\
|
|
15
|
-
}\n\
|
|
16
|
-
\n\
|
|
17
|
-
class Class3 {\n\
|
|
18
|
-
public getString() {\n\
|
|
19
|
-
var class1Obj = new Class1();\n\
|
|
20
|
-
var class2Obj = new Class2();\n\
|
|
21
|
-
var returnValue1 = class1Obj.returnHi();\n\
|
|
22
|
-
var returnValue2 = class2Obj.returnName();\n\
|
|
23
|
-
var x = a();\n\
|
|
24
|
-
}\n\
|
|
25
|
-
}\n\
|
|
26
|
-
\n\
|
|
27
|
-
function a() {}\n\
|
|
28
|
-
');
|
|
29
|
-
|
|
30
|
-
describe('Invocations', () => {
|
|
31
|
-
|
|
32
|
-
it("should contain method returnHi in Class1", () => {
|
|
33
|
-
const clsName = "Class1";
|
|
34
|
-
const mName = "returnHi";
|
|
35
|
-
const theClass = fmxRep._getFamixClass(clsName);
|
|
36
|
-
expect(theClass).toBeTruthy();
|
|
37
|
-
if (theClass) {
|
|
38
|
-
const methodFqn = Array.from(theClass.getMethods())[0].getFullyQualifiedName();
|
|
39
|
-
expect(methodFqn.substring(methodFqn.length-clsName.length-1-mName.length)).toBe(clsName + '.' + mName);
|
|
40
|
-
const theMethod = fmxRep.getFamixEntityByFullyQualifiedName(methodFqn);
|
|
41
|
-
expect(theMethod).toBeTruthy();
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should contain method returnName in Class2", () => {
|
|
46
|
-
const clsName = "Class2";
|
|
47
|
-
const mName = "returnName";
|
|
48
|
-
const theClass = fmxRep._getFamixClass(clsName);
|
|
49
|
-
expect(theClass).toBeTruthy();
|
|
50
|
-
if (theClass) {
|
|
51
|
-
const methodFqn = Array.from(theClass.getMethods())[0].getFullyQualifiedName();
|
|
52
|
-
expect(methodFqn.substring(methodFqn.length-clsName.length-1-mName.length)).toBe(clsName + '.' + mName);
|
|
53
|
-
const theMethod = fmxRep.getFamixEntityByFullyQualifiedName(methodFqn);
|
|
54
|
-
expect(theMethod).toBeTruthy();
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("should contain method getString in Class3", () => {
|
|
59
|
-
const clsName = "Class3";
|
|
60
|
-
const mName = "getString";
|
|
61
|
-
const theClass = fmxRep._getFamixClass(clsName);
|
|
62
|
-
expect(theClass).toBeTruthy();
|
|
63
|
-
if (theClass) {
|
|
64
|
-
const methodFqn = Array.from(theClass.getMethods())[0].getFullyQualifiedName();
|
|
65
|
-
expect(methodFqn.substring(methodFqn.length-clsName.length-1-mName.length)).toBe(clsName + '.' + mName);
|
|
66
|
-
const theMethod = fmxRep.getFamixEntityByFullyQualifiedName(methodFqn);
|
|
67
|
-
expect(theMethod).toBeTruthy();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("should contain an invocation for returnHi", () => {
|
|
72
|
-
const clsName = "Class1";
|
|
73
|
-
const theClass = fmxRep._getFamixClass(clsName);
|
|
74
|
-
expect(theClass).toBeTruthy();
|
|
75
|
-
if (theClass) {
|
|
76
|
-
const methodFqn = Array.from(theClass.getMethods())[0].getFullyQualifiedName();
|
|
77
|
-
const theMethod = fmxRep.getFamixEntityByFullyQualifiedName(methodFqn) as Method;
|
|
78
|
-
expect(theMethod).toBeTruthy();
|
|
79
|
-
const invocations = Array.from(fmxRep._getAllEntitiesWithType("Invocation"));
|
|
80
|
-
expect(invocations).toBeTruthy();
|
|
81
|
-
expect(invocations.length).toBeTruthy();
|
|
82
|
-
const candidates = invocations.filter(i => {
|
|
83
|
-
const invocation = i as Invocation;
|
|
84
|
-
return invocation.getCandidates().has(theMethod);
|
|
85
|
-
});
|
|
86
|
-
expect(candidates).toHaveLength(1);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("should contain an invocation for returnHi with a receiver of 'Class1'", () => {
|
|
91
|
-
const clsName = "Class1";
|
|
92
|
-
const theClass = fmxRep._getFamixClass(clsName);
|
|
93
|
-
expect(theClass).toBeTruthy();
|
|
94
|
-
if (theClass) {
|
|
95
|
-
const methodFqn = Array.from(theClass.getMethods())[0].getFullyQualifiedName();
|
|
96
|
-
const theMethod = fmxRep.getFamixEntityByFullyQualifiedName(methodFqn) as Method;
|
|
97
|
-
expect(theMethod).toBeTruthy();
|
|
98
|
-
const invocations = Array.from(fmxRep._getAllEntitiesWithType("Invocation"));
|
|
99
|
-
expect(invocations).toBeTruthy();
|
|
100
|
-
expect(invocations.length).toBeTruthy();
|
|
101
|
-
expect((invocations[0] as Invocation).getReceiver()).toBeTruthy();
|
|
102
|
-
expect((invocations[0] as Invocation).getReceiver()).toBe(fmxRep._getFamixClass("Class1"));
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("should contain an invocation for returnHi with a signature 'public returnHi(): string'", () => {
|
|
107
|
-
const clsName = "Class1";
|
|
108
|
-
const theClass = fmxRep._getFamixClass(clsName);
|
|
109
|
-
expect(theClass).toBeTruthy();
|
|
110
|
-
if (theClass) {
|
|
111
|
-
const methodFqn = Array.from(theClass.getMethods())[0].getFullyQualifiedName();
|
|
112
|
-
const theMethod = fmxRep.getFamixEntityByFullyQualifiedName(methodFqn) as Method;
|
|
113
|
-
expect(theMethod).toBeTruthy();
|
|
114
|
-
const invocations = Array.from(fmxRep._getAllEntitiesWithType("Invocation"));
|
|
115
|
-
expect(invocations).toBeTruthy();
|
|
116
|
-
expect(invocations.length).toBeTruthy();
|
|
117
|
-
expect((invocations[0] as Invocation).getSignature()).toBeTruthy();
|
|
118
|
-
expect((invocations[0] as Invocation).getSignature()).toBe('public returnHi(): string');
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("should contain an invocation for a function 'a'", () => {
|
|
123
|
-
const theFunction = fmxRep._getFamixFunction("a");
|
|
124
|
-
expect(theFunction).toBeTruthy();
|
|
125
|
-
const invocations = Array.from(fmxRep._getAllEntitiesWithType("Invocation"));
|
|
126
|
-
expect(invocations).toBeTruthy();
|
|
127
|
-
expect(invocations.length).toBeTruthy();
|
|
128
|
-
expect((invocations[0] as Invocation).getSignature()).toBeTruthy();
|
|
129
|
-
expect((invocations[0] as Invocation).getSignature()).toBe('public returnHi(): string');
|
|
130
|
-
});
|
|
131
|
-
});
|
package/test/jsDoc.test.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Importer } from '../src/analyze';
|
|
2
|
-
import { Comment } from '../src/lib/famix/src/model/famix/comment';
|
|
3
|
-
|
|
4
|
-
const importer = new Importer();
|
|
5
|
-
|
|
6
|
-
const fmxRep = importer.famixRepFromSource("jsDoc",
|
|
7
|
-
'/**\n\
|
|
8
|
-
* Gets the name.\n\
|
|
9
|
-
* @param person - Person to get the name from.\n\
|
|
10
|
-
*/\n\
|
|
11
|
-
function getName(person: string) {}\n\
|
|
12
|
-
');
|
|
13
|
-
|
|
14
|
-
describe('Tests for JS doc', () => {
|
|
15
|
-
|
|
16
|
-
it("should contain one function and one comment", () => {
|
|
17
|
-
expect(fmxRep._getAllEntitiesWithType("Function").size).toBe(1);
|
|
18
|
-
expect(fmxRep._getAllEntitiesWithType("Comment").size).toBe(1);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const theFunction = fmxRep._getFamixFunction("getName");
|
|
22
|
-
const theJSDoc = Array.from(fmxRep._getAllEntitiesWithType("Comment") as Set<Comment>)[0];
|
|
23
|
-
|
|
24
|
-
it("should have one comment for the function", () => {
|
|
25
|
-
expect(theFunction?.getComments().size).toBe(1);
|
|
26
|
-
expect(theFunction?.getComments().has(theJSDoc)).toBe(true);
|
|
27
|
-
expect(theJSDoc?.getContent()).toBe("/**\n* Gets the name.\n* @param person - Person to get the name from.\n*/");
|
|
28
|
-
expect(theJSDoc?.getContainer()).toBe(theFunction);
|
|
29
|
-
expect(theJSDoc?.getIsJSDoc()).toBe(true);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Importer } from '../src/analyze';
|
|
2
|
-
import { Decorator } from '../src/lib/famix/src/model/famix/decorator';
|
|
3
|
-
|
|
4
|
-
const importer = new Importer();
|
|
5
|
-
|
|
6
|
-
const fmxRep = importer.famixRepFromSource("methodWithDecorator",
|
|
7
|
-
'function first() {\n\
|
|
8
|
-
console.log("first(): factory evaluated");\n\
|
|
9
|
-
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {\n\
|
|
10
|
-
console.log("first(): called");\n\
|
|
11
|
-
};\n\
|
|
12
|
-
}\n\
|
|
13
|
-
\n\
|
|
14
|
-
class ExampleClass {\n\
|
|
15
|
-
@first()\n\
|
|
16
|
-
method() {}\n\
|
|
17
|
-
}\n\
|
|
18
|
-
');
|
|
19
|
-
|
|
20
|
-
describe('Tests for method with decorator', () => {
|
|
21
|
-
|
|
22
|
-
it("should contain one class", () => {
|
|
23
|
-
expect(fmxRep._getAllEntitiesWithType("Class").size).toBe(1);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should contain a method 'method'", () => {
|
|
27
|
-
expect(fmxRep._getAllEntitiesWithType("Method").size).toBe(1);
|
|
28
|
-
const theMethod = fmxRep._getFamixMethod("method");
|
|
29
|
-
expect(theMethod).toBeTruthy();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should contain one decorator", () => {
|
|
33
|
-
expect(fmxRep._getAllEntitiesWithType("Decorator").size).toBe(1);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const theMethod = fmxRep._getFamixMethod("method");
|
|
37
|
-
const d = (Array.from(fmxRep._getAllEntitiesWithType("Decorator")) as Array<Decorator>).find((d) => d.getName() === "@first");
|
|
38
|
-
|
|
39
|
-
it("should contain a method with one decorator", () => {
|
|
40
|
-
expect(theMethod?.getDecorators().size).toBe(1);
|
|
41
|
-
expect(d?.getDecoratedEntity()).toBe(theMethod);
|
|
42
|
-
expect(d?.getDecoratorExpression()).toBe("first()");
|
|
43
|
-
});
|
|
44
|
-
});
|
package/test/methods.test.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Importer } from '../src/analyze';
|
|
2
|
-
import { Method } from "../src/lib/famix/src/model/famix/method";
|
|
3
|
-
|
|
4
|
-
const importer = new Importer();
|
|
5
|
-
|
|
6
|
-
const fmxRep = importer.famixRepFromSource("methods",
|
|
7
|
-
'class AAA {\n\
|
|
8
|
-
public method(): void {}\n\
|
|
9
|
-
}\n\
|
|
10
|
-
');
|
|
11
|
-
|
|
12
|
-
describe('Tests for methods', () => {
|
|
13
|
-
|
|
14
|
-
const methodList = fmxRep._getAllEntitiesWithType('Method');
|
|
15
|
-
it("should have method", () => {
|
|
16
|
-
expect(methodList?.size).toBe(1);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const theMethod = Array.from(methodList)[0] as Method;
|
|
20
|
-
it("should contain a method 'method'", () => {
|
|
21
|
-
expect(theMethod).toBeTruthy();
|
|
22
|
-
expect(theMethod?.getName()).toBe('method');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
it("should return void", () => {
|
|
27
|
-
expect(theMethod?.getDeclaredType().getName()).toBe("void");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should have no parameter", () => {
|
|
31
|
-
expect(theMethod?.getParameters().size).toBe(0);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should be a public method 'method", () => {
|
|
35
|
-
expect(theMethod.getKind()).toBe(undefined);
|
|
36
|
-
expect(theMethod.getIsAbstract()).toBe(false);
|
|
37
|
-
expect(theMethod.getIsClassSide()).toBe(false);
|
|
38
|
-
expect(theMethod.getIsPrivate()).toBe(false);
|
|
39
|
-
expect(theMethod.getIsProtected()).toBe(false);
|
|
40
|
-
expect(theMethod.getIsPublic()).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
});
|
package/test/metrics.test.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Importer } from '../src/analyze';
|
|
2
|
-
|
|
3
|
-
const importer = new Importer();
|
|
4
|
-
|
|
5
|
-
const fmxRep = importer.famixRepFromSource("metrics",
|
|
6
|
-
'class ForMetrics {\n\
|
|
7
|
-
public methodCyclomaticOne() {}\n\
|
|
8
|
-
\n\
|
|
9
|
-
public methodCyclomaticFour() {\n\
|
|
10
|
-
// make higher cyclomatic complexity\n\
|
|
11
|
-
for (let i = 0; i < 50; i++) { // 2\n\
|
|
12
|
-
for (let j = 0; j < 50; j++) { // 3\n\
|
|
13
|
-
if (i < 10) {} // 4\n\
|
|
14
|
-
}\n\
|
|
15
|
-
}\n\
|
|
16
|
-
}\n\
|
|
17
|
-
}\n\
|
|
18
|
-
\n\
|
|
19
|
-
function functionCyclomaticOne() {}\n\
|
|
20
|
-
\n\
|
|
21
|
-
function functionCyclomaticFour() {\n\
|
|
22
|
-
// make higher cyclomatic complexity\n\
|
|
23
|
-
for (let i = 0; i < 50; i++) { // 2\n\
|
|
24
|
-
for (let j = 0; j < 50; j++) { // 3\n\
|
|
25
|
-
if (i < 10) {} // 4\n\
|
|
26
|
-
}\n\
|
|
27
|
-
}\n\
|
|
28
|
-
}\n\
|
|
29
|
-
');
|
|
30
|
-
|
|
31
|
-
describe('Metrics', () => {
|
|
32
|
-
|
|
33
|
-
const jsonOutput = fmxRep.getJSON();
|
|
34
|
-
const parsedModel = JSON.parse(jsonOutput);
|
|
35
|
-
|
|
36
|
-
it("should calculate cyclomatic complexity", () => {
|
|
37
|
-
let theMethod = parsedModel.filter(el => (el.FM3 === "FamixTypeScript.Method" && el.name === "methodCyclomaticOne"))[0];
|
|
38
|
-
expect(theMethod).toBeTruthy();
|
|
39
|
-
expect(theMethod.cyclomaticComplexity).toBe(1);
|
|
40
|
-
theMethod = parsedModel.filter(el => (el.FM3 === "FamixTypeScript.Method" && el.name === "methodCyclomaticFour"))[0];
|
|
41
|
-
expect(theMethod).toBeTruthy();
|
|
42
|
-
expect(theMethod.cyclomaticComplexity).toBe(4);
|
|
43
|
-
|
|
44
|
-
let theFunction = parsedModel.filter(el => (el.FM3 === "FamixTypeScript.Function" && el.name === "functionCyclomaticOne"))[0];
|
|
45
|
-
expect(theFunction).toBeTruthy();
|
|
46
|
-
expect(theFunction.cyclomaticComplexity).toBe(1);
|
|
47
|
-
theFunction = parsedModel.filter(el => (el.FM3 === "FamixTypeScript.Function" && el.name === "functionCyclomaticFour"))[0];
|
|
48
|
-
expect(theFunction).toBeTruthy();
|
|
49
|
-
expect(theFunction.cyclomaticComplexity).toBe(4);
|
|
50
|
-
});
|
|
51
|
-
});
|
package/test/module.test.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { Importer } from '../src/analyze';
|
|
2
|
-
import { ImportClause } from '../src/lib/famix/src/model/famix/import_clause';
|
|
3
|
-
import { Module } from '../src/lib/famix/src/model/famix/module';
|
|
4
|
-
|
|
5
|
-
const importer = new Importer();
|
|
6
|
-
|
|
7
|
-
const filePaths = new Array<string>();
|
|
8
|
-
filePaths.push("test_src/sampleForModule.ts");
|
|
9
|
-
filePaths.push("test_src/sampleForModule2.ts");
|
|
10
|
-
filePaths.push("test_src/sampleForModule3.ts");
|
|
11
|
-
|
|
12
|
-
const fmxRep = importer.famixRepFromPaths(filePaths);
|
|
13
|
-
|
|
14
|
-
describe('Tests for module', () => {
|
|
15
|
-
|
|
16
|
-
const moduleList = Array.from(fmxRep._getAllEntitiesWithType('Module')) as Array<Module>;
|
|
17
|
-
const theFile = moduleList.find(e => e.getName() === 'sampleForModule.ts');
|
|
18
|
-
const theFile2 = moduleList.find(e => e.getName() === 'sampleForModule2.ts');
|
|
19
|
-
const theFile3 = moduleList.find(e => e.getName() === 'sampleForModule3.ts');
|
|
20
|
-
it("should have three modules", () => {
|
|
21
|
-
expect(moduleList?.length).toBe(3);
|
|
22
|
-
expect(theFile).toBeTruthy();
|
|
23
|
-
expect(theFile2).toBeTruthy();
|
|
24
|
-
expect(theFile3).toBeTruthy();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const theClass = fmxRep._getFamixClass('ClassZ');
|
|
28
|
-
const importClauseList = Array.from(fmxRep._getAllEntitiesWithType('ImportClause')) as Array<ImportClause>;
|
|
29
|
-
it("should have ten import clauses", () => {
|
|
30
|
-
expect(importClauseList?.length).toBe(10);
|
|
31
|
-
expect(theFile2?.getImportClauses().size).toBe(8);
|
|
32
|
-
expect(theFile3?.getImportClauses().size).toBe(2);
|
|
33
|
-
|
|
34
|
-
const theImportClause = importClauseList.find(e => e.getImporter().getName() === 'sampleForModule2.ts' && e.getImportedEntity().getName() === 'ClassDeclaration' && e.getModuleSpecifier() === 'ts-morph');
|
|
35
|
-
expect(theImportClause).toBeTruthy();
|
|
36
|
-
const entity = theImportClause?.getImportedEntity();
|
|
37
|
-
expect(entity?.getName()).toBe('ClassDeclaration');
|
|
38
|
-
expect(entity?.getIsStub()).toBe(true);
|
|
39
|
-
|
|
40
|
-
const theImportClause2 = importClauseList.find(e => e.getImporter().getName() === 'sampleForModule2.ts' && e.getImportedEntity().getName() === 'ConstructorDeclaration' && e.getModuleSpecifier() === 'ts-morph');
|
|
41
|
-
expect(theImportClause2).toBeTruthy();
|
|
42
|
-
const entity2 = theImportClause2?.getImportedEntity();
|
|
43
|
-
expect(entity2?.getName()).toBe('ConstructorDeclaration');
|
|
44
|
-
expect(entity2?.getIsStub()).toBe(true);
|
|
45
|
-
|
|
46
|
-
const theImportClause3 = importClauseList.find(e => e.getImporter().getName() === 'sampleForModule2.ts' && e.getImportedEntity().getName() === 'Importer' && e.getModuleSpecifier() === '../test_src/sampleForModule');
|
|
47
|
-
expect(theImportClause3).toBeTruthy();
|
|
48
|
-
|
|
49
|
-
const theImportClause4 = importClauseList.find(e => e.getImporter().getName() === 'sampleForModule2.ts' && e.getImportedEntity().getName() === 'ClassZ' && e.getModuleSpecifier() === '../test_src/sampleForModule');
|
|
50
|
-
expect(theImportClause4).toBeTruthy();
|
|
51
|
-
expect(theImportClause4?.getImportedEntity()).toBe(theClass);
|
|
52
|
-
|
|
53
|
-
const theImportClause5 = importClauseList.find(e => e.getImporter().getName() === 'sampleForModule2.ts' && e.getImportedEntity().getName() === 'Cls' && e.getModuleSpecifier() === '../test_src/sampleForModule');
|
|
54
|
-
expect(theImportClause5).toBeTruthy();
|
|
55
|
-
|
|
56
|
-
const theImportClause6 = importClauseList.find(e => e.getImporter().getName() === 'sampleForModule2.ts' && e.getImportedEntity().getName() === 'Nsp' && e.getModuleSpecifier() === '../test_src/sampleForModule');
|
|
57
|
-
expect(theImportClause6).toBeTruthy();
|
|
58
|
-
|
|
59
|
-
const theImportClause7 = importClauseList.find(e => e.getImporter().getName() === 'sampleForModule2.ts' && e.getImportedEntity().getName() === 'Famix' && e.getModuleSpecifier() === '../src/lib/famix/src/model/famix');
|
|
60
|
-
expect(theImportClause7).toBeTruthy();
|
|
61
|
-
|
|
62
|
-
const theImportClause8 = importClauseList.find(e => e.getImporter().getName() === 'sampleForModule2.ts' && e.getImportedEntity().getName() === 'express' && e.getModuleSpecifier() === 'express');
|
|
63
|
-
expect(theImportClause8).toBeTruthy();
|
|
64
|
-
|
|
65
|
-
const theImportClause9 = importClauseList.find(e => e.getImporter().getName() === 'sampleForModule3.ts' && e.getImportedEntity().getName() === 'ClassX' && e.getModuleSpecifier() === 'express.ts');
|
|
66
|
-
expect(theImportClause9).toBeTruthy();
|
|
67
|
-
|
|
68
|
-
const theImportClause10 = importClauseList.find(e => e.getImporter().getName() === 'sampleForModule3.ts' && e.getImportedEntity().getName() === 'test' && e.getModuleSpecifier() === './sampleForModule.ts');
|
|
69
|
-
expect(theImportClause10).toBeTruthy();
|
|
70
|
-
});
|
|
71
|
-
});
|
package/test/namespaces.test.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Importer } from '../src/analyze';
|
|
2
|
-
|
|
3
|
-
const importer = new Importer();
|
|
4
|
-
|
|
5
|
-
const fmxRep = importer.famixRepFromSource("namespaces",
|
|
6
|
-
'namespace MyNamespace {}\n\
|
|
7
|
-
\n\
|
|
8
|
-
module MyModule {}\n\
|
|
9
|
-
\n\
|
|
10
|
-
declare module aModule {}\n\
|
|
11
|
-
\n\
|
|
12
|
-
declare module "someModule" {}\n\
|
|
13
|
-
\n\
|
|
14
|
-
declare module "otherModule";\n\
|
|
15
|
-
\n\
|
|
16
|
-
declare namespace MyNamespace2 {}\n\
|
|
17
|
-
');
|
|
18
|
-
|
|
19
|
-
describe('Tests for namespaces', () => {
|
|
20
|
-
|
|
21
|
-
it("should contain six namespaces", () => {
|
|
22
|
-
expect(fmxRep._getFamixNamespaces().size).toBe(6);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const theNamespace1 = fmxRep._getFamixNamespace("MyNamespace");
|
|
26
|
-
it("should contain a namespace MyNamespace", () => {
|
|
27
|
-
expect(theNamespace1).toBeTruthy();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const theNamespace2 = fmxRep._getFamixNamespace("MyModule");
|
|
31
|
-
it("should contain a namespace MyModule", () => {
|
|
32
|
-
expect(theNamespace2).toBeTruthy();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const theNamespace3 = fmxRep._getFamixNamespace("aModule");
|
|
36
|
-
it("should contain a namespace aModule", () => {
|
|
37
|
-
expect(theNamespace3).toBeTruthy();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const theNamespace4 = fmxRep._getFamixNamespace("\"someModule\"");
|
|
41
|
-
it("should contain a namespace \"someModule\"", () => {
|
|
42
|
-
expect(theNamespace4).toBeTruthy();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const theNamespace5 = fmxRep._getFamixNamespace("\"otherModule\"");
|
|
46
|
-
it("should contain a namespace \"otherModule\"", () => {
|
|
47
|
-
expect(theNamespace5).toBeTruthy();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const theNamespace6 = fmxRep._getFamixNamespace("MyNamespace2");
|
|
51
|
-
it("should contain a namespace MyNamespace2", () => {
|
|
52
|
-
expect(theNamespace6).toBeTruthy();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Importer } from '../src/analyze';
|
|
2
|
-
import { Type } from '../src/lib/famix/src/model/famix/type';
|
|
3
|
-
import { Class } from '../src/lib/famix/src/model/famix/class';
|
|
4
|
-
|
|
5
|
-
const importer = new Importer();
|
|
6
|
-
|
|
7
|
-
const fmxRep = importer.famixRepFromSource("namespacesAndClasses",
|
|
8
|
-
'namespace MyNamespace {\n\
|
|
9
|
-
class EntityClass {}\n\
|
|
10
|
-
class class2 {}\n\
|
|
11
|
-
}\n\
|
|
12
|
-
\n\
|
|
13
|
-
class clsOutNsp {}\n\
|
|
14
|
-
\n\
|
|
15
|
-
namespace Nsp3 {\n\
|
|
16
|
-
class clsInNsp3 {}\n\
|
|
17
|
-
}\n\
|
|
18
|
-
');
|
|
19
|
-
|
|
20
|
-
describe('Tests for namespaces and classes', () => {
|
|
21
|
-
|
|
22
|
-
it("should contain two namespaces", () => {
|
|
23
|
-
expect(fmxRep._getFamixNamespaces().size).toBe(2);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const theFile = fmxRep._getFamixFile("namespacesAndClasses.ts");
|
|
27
|
-
const theNamespace1 = fmxRep._getFamixNamespace("MyNamespace");
|
|
28
|
-
it("should contain a namespace MyNamespace", () => {
|
|
29
|
-
expect(theNamespace1).toBeTruthy();
|
|
30
|
-
expect(theNamespace1?.getParentScope()).toBe(theFile);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("should contain two classes", () => {
|
|
34
|
-
expect(Array.from(theNamespace1?.getTypes() as Set<Type>).filter(t => (t instanceof Class)).length).toBe(2);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const theNamespace2 = fmxRep._getFamixNamespace("Nsp3");
|
|
38
|
-
it("should contain a namespace Nsp3", () => {
|
|
39
|
-
expect(theNamespace2).toBeTruthy();
|
|
40
|
-
expect(theNamespace2?.getParentScope()).toBe(theFile);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should contain one class", () => {
|
|
44
|
-
expect(Array.from(theNamespace2?.getTypes() as Set<Type>).filter(t => (t instanceof Class)).length).toBe(1);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("should contain four classes", () => {
|
|
48
|
-
expect(fmxRep._getAllEntitiesWithType("Class").size).toBe(4);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("should contain a class EntityClass", () => {
|
|
52
|
-
expect(fmxRep._getFamixClass("EntityClass")).toBeTruthy();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("should contain a class class2", () => {
|
|
56
|
-
expect(fmxRep._getFamixClass("class2")).toBeTruthy();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("should contain a class clsInNsp3", () => {
|
|
60
|
-
expect(fmxRep._getFamixClass("clsInNsp3")).toBeTruthy();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("should contain a class clsOutNsp", () => {
|
|
64
|
-
expect(fmxRep._getFamixClass("clsOutNsp")).toBeTruthy();
|
|
65
|
-
});
|
|
66
|
-
});
|