Skip to content

Commit 4fbf8ca

Browse files
committed
Added test cases with inheritance
1 parent ee3a3bd commit 4fbf8ca

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

javascript/ql/test/library-tests/CallGraphs/AnnotatedTest/Test.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ spuriousCallee
22
missingCallee
33
| constructor-field.ts:40:5:40:14 | f3.build() | constructor-field.ts:13:3:13:12 | build() {} | -1 | calls |
44
| constructor-field.ts:71:1:71:11 | bf3.build() | constructor-field.ts:13:3:13:12 | build() {} | -1 | calls |
5+
| prototypes.js:7:5:7:16 | this.greet() | prototypes.js:59:8:63:3 | () { \\n ... ); \\n } | -1 | calls |
6+
| prototypes.js:62:5:62:34 | Baz.pro ... l(this) | prototypes.js:10:8:10:39 | () { co ... et"); } | -1 | calls |
7+
| prototypes.js:77:3:77:32 | Baz.pro ... l(this) | prototypes.js:14:23:14:62 | functio ... ut"); } | -1 | calls |
58
badAnnotation
69
accessorCall
710
| accessors.js:12:1:12:5 | obj.f | accessors.js:5:8:5:12 | () {} |

javascript/ql/test/library-tests/CallGraphs/AnnotatedTest/prototypes.js

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
import 'dummy'
2+
13
class Baz {
24
baz() {
3-
/** calls:Baz.greet */
5+
console.log("Baz baz");
6+
/** calls:Baz.greet calls:Derived.greet1 calls:BazExtented.greet2 */
47
this.greet();
58
}
69
/** name:Baz.greet */
7-
greet() {}
10+
greet() { console.log("Baz greet"); }
811
}
912

1013
/** name:Baz.shout */
11-
Baz.prototype.shout = function() {};
14+
Baz.prototype.shout = function() { console.log("Baz shout"); };
1215
/** name:Baz.staticShout */
13-
Baz.staticShout = function() {};
16+
Baz.staticShout = function() { console.log("Baz staticShout"); };
1417

1518
function foo(baz){
1619
/** calls:Baz.greet */
@@ -23,3 +26,66 @@ function foo(baz){
2326

2427
const baz = new Baz();
2528
foo(baz);
29+
30+
class Derived extends Baz {
31+
/** name:Derived.greet1 */
32+
greet() {
33+
console.log("Derived greet");
34+
super.greet();
35+
}
36+
37+
/** name:Derived.shout1 */
38+
shout() {
39+
console.log("Derived shout");
40+
super.shout();
41+
}
42+
}
43+
44+
function bar(derived){
45+
/** calls:Derived.greet1 */
46+
derived.greet();
47+
/** calls:Derived.shout1 */
48+
derived.shout();
49+
}
50+
51+
bar(new Derived());
52+
53+
class BazExtented {
54+
constructor() {
55+
console.log("BazExtented construct");
56+
}
57+
58+
/** name:BazExtented.greet2 */
59+
greet() {
60+
console.log("BazExtented greet");
61+
/** calls:Baz.greet */
62+
Baz.prototype.greet.call(this);
63+
};
64+
}
65+
66+
BazExtented.prototype = Object.create(Baz.prototype);
67+
BazExtented.prototype.constructor = BazExtented;
68+
BazExtented.staticShout = Baz.staticShout;
69+
70+
/** name:BazExtented.talk */
71+
BazExtented.prototype.talk = function() { console.log("BazExtented talk"); };
72+
73+
/** name:BazExtented.shout2 */
74+
BazExtented.prototype.shout = function() {
75+
console.log("BazExtented shout");
76+
/** calls:Baz.shout */
77+
Baz.prototype.shout.call(this);
78+
};
79+
80+
function barbar(bazExtented){
81+
/** calls:BazExtented.talk */
82+
bazExtented.talk();
83+
/** calls:BazExtented.shout2 */
84+
bazExtented.shout();
85+
/** calls:BazExtented.greet2 */
86+
bazExtented.greet();
87+
/** calls:Baz.staticShout */
88+
BazExtented.staticShout();
89+
}
90+
91+
barbar(new BazExtented());

0 commit comments

Comments
 (0)