@@ -2,132 +2,132 @@ import { Breakpoint, ParsedFunction } from '../JerryBreakpoints';
22import * as assert from 'assert' ;
33
44suite ( 'Jerry Breakpoints' , ( ) => {
5- suite ( 'Breakpoint constructor' , ( ) => {
6- const mockParsedFunction : any = {
7- scriptId : 42 ,
8- } ;
9-
10- test ( 'assigns values from options arg' , ( ) => {
11- const bp = new Breakpoint ( {
12- scriptId : 1 ,
13- func : mockParsedFunction ,
14- line : 42 ,
15- offset : 37 ,
16- activeIndex : 5 ,
17- } ) ;
18- assert . strictEqual ( bp . scriptId , 1 ) ;
19- assert . strictEqual ( bp . func , mockParsedFunction ) ;
20- assert . strictEqual ( bp . line , 42 ) ;
21- assert . strictEqual ( bp . offset , 37 ) ;
22- assert . strictEqual ( bp . activeIndex , 5 ) ;
23- } ) ;
24-
25- test ( 'sets activeIndex to -1 by default' , ( ) => {
26- const bp = new Breakpoint ( {
27- scriptId : 1 ,
28- func : mockParsedFunction ,
29- line : 42 ,
30- offset : 37 ,
31- } ) ;
32- assert . strictEqual ( bp . scriptId , 1 ) ;
33- assert . strictEqual ( bp . func , mockParsedFunction ) ;
34- assert . strictEqual ( bp . line , 42 ) ;
35- assert . strictEqual ( bp . offset , 37 ) ;
36- assert . strictEqual ( bp . activeIndex , - 1 ) ;
37- } ) ;
5+ suite ( 'Breakpoint constructor' , ( ) => {
6+ const mockParsedFunction : any = {
7+ scriptId : 42 ,
8+ } ;
9+
10+ test ( 'assigns values from options arg' , ( ) => {
11+ const bp = new Breakpoint ( {
12+ scriptId : 1 ,
13+ func : mockParsedFunction ,
14+ line : 42 ,
15+ offset : 37 ,
16+ activeIndex : 5 ,
17+ } ) ;
18+ assert . strictEqual ( bp . scriptId , 1 ) ;
19+ assert . strictEqual ( bp . func , mockParsedFunction ) ;
20+ assert . strictEqual ( bp . line , 42 ) ;
21+ assert . strictEqual ( bp . offset , 37 ) ;
22+ assert . strictEqual ( bp . activeIndex , 5 ) ;
3823 } ) ;
3924
40- suite ( 'Breakpoint toString' , ( ) => {
41- const mockParsedFunction : any = {
42- line : 21 ,
43- column : 61 ,
44- } ;
45-
46- mockParsedFunction . sourceName = 'jerry.js' ,
47- mockParsedFunction . isFunc = true ;
48- mockParsedFunction . name = undefined ;
49-
50- test ( 'displays function name, line and column' , ( ) => {
51- mockParsedFunction . name = 'cheese' ;
52-
53- const bp = new Breakpoint ( {
54- scriptId : 1 ,
55- func : mockParsedFunction ,
56- line : 42 ,
57- offset : 37 ,
58- } ) ;
59- assert . strictEqual ( bp . toString ( ) , 'jerry.js:42 (in cheese() at line:21, col:61)' ) ;
60- } ) ;
61-
62- test ( 'shows "function" for unnamed functions' , ( ) => {
63- mockParsedFunction . name = undefined ;
64- const bp = new Breakpoint ( {
65- scriptId : 1 ,
66- func : mockParsedFunction ,
67- line : 42 ,
68- offset : 37 ,
69- } ) ;
70- assert . strictEqual ( bp . toString ( ) , 'jerry.js:42 (in function() at line:21, col:61)' ) ;
71- } ) ;
72-
73- test ( 'drops function detail if not really a function (i.e. global scope)' , ( ) => {
74- mockParsedFunction . isFunc = false ;
75-
76- const bp = new Breakpoint ( {
77- scriptId : 1 ,
78- func : mockParsedFunction ,
79- line : 42 ,
80- offset : 37 ,
81- } ) ;
82- assert . strictEqual ( bp . toString ( ) , 'jerry.js:42' ) ;
83- } ) ;
84-
85- test ( 'reports source name as "<unknown>" if not given' , ( ) => {
86- mockParsedFunction . isFunc = false ;
87- mockParsedFunction . sourceName = undefined ;
88-
89- const bp = new Breakpoint ( {
90- scriptId : 1 ,
91- func : mockParsedFunction ,
92- line : 42 ,
93- offset : 37 ,
94- } ) ;
95- assert . strictEqual ( bp . toString ( ) , '<unknown>:42' ) ;
96- } ) ;
25+ test ( 'sets activeIndex to -1 by default' , ( ) => {
26+ const bp = new Breakpoint ( {
27+ scriptId : 1 ,
28+ func : mockParsedFunction ,
29+ line : 42 ,
30+ offset : 37 ,
31+ } ) ;
32+ assert . strictEqual ( bp . scriptId , 1 ) ;
33+ assert . strictEqual ( bp . func , mockParsedFunction ) ;
34+ assert . strictEqual ( bp . line , 42 ) ;
35+ assert . strictEqual ( bp . offset , 37 ) ;
36+ assert . strictEqual ( bp . activeIndex , - 1 ) ;
9737 } ) ;
38+ } ) ;
39+
40+ suite ( 'Breakpoint toString' , ( ) => {
41+ const mockParsedFunction : any = {
42+ line : 21 ,
43+ column : 61 ,
44+ } ;
45+
46+ mockParsedFunction . sourceName = 'jerry.js' ,
47+ mockParsedFunction . isFunc = true ;
48+ mockParsedFunction . name = undefined ;
49+
50+ test ( 'displays function name, line and column' , ( ) => {
51+ mockParsedFunction . name = 'cheese' ;
52+
53+ const bp = new Breakpoint ( {
54+ scriptId : 1 ,
55+ func : mockParsedFunction ,
56+ line : 42 ,
57+ offset : 37 ,
58+ } ) ;
59+ assert . strictEqual ( bp . toString ( ) , 'jerry.js:42 (in cheese() at line:21, col:61)' ) ;
60+ } ) ;
61+
62+ test ( 'shows "function" for unnamed functions' , ( ) => {
63+ mockParsedFunction . name = undefined ;
64+ const bp = new Breakpoint ( {
65+ scriptId : 1 ,
66+ func : mockParsedFunction ,
67+ line : 42 ,
68+ offset : 37 ,
69+ } ) ;
70+ assert . strictEqual ( bp . toString ( ) , 'jerry.js:42 (in function() at line:21, col:61)' ) ;
71+ } ) ;
72+
73+ test ( 'drops function detail if not really a function (i.e. global scope)' , ( ) => {
74+ mockParsedFunction . isFunc = false ;
9875
99- suite ( 'ParsedFunction constructor' , ( ) => {
100- test ( 'adds a breakpoint for each line/offset pair in the frame' , ( ) => {
101- const frame = {
102- isFunc : true ,
103- scriptId : 42 ,
104- line : 1 ,
105- column : 2 ,
106- source : '' ,
107- sourceName : 'cheese.js' ,
108- name : 'cheddar' ,
109- lines : [ 4 , 9 , 16 , 25 ] ,
110- offsets : [ 8 , 27 , 64 , 125 ] ,
111- } ;
112-
113- const pf = new ParsedFunction ( 7 , frame ) ;
114- assert . strictEqual ( pf . isFunc , true ) ;
115- assert . strictEqual ( pf . byteCodeCP , 7 ) ;
116- assert . strictEqual ( pf . scriptId , 42 ) ;
117- assert . strictEqual ( pf . line , 1 ) ;
118- assert . strictEqual ( pf . column , 2 ) ;
119- assert . strictEqual ( pf . name , 'cheddar' ) ;
120- assert . strictEqual ( pf . firstBreakpointLine , 4 ) ;
121- assert . strictEqual ( pf . firstBreakpointOffset , 8 ) ;
122- assert . strictEqual ( pf . sourceName , 'cheese.js' ) ;
123-
124- // the third breakpoint w/ line 16, offset 64 is indexed as 16 in lines
125- assert . strictEqual ( pf . lines [ 16 ] . line , 16 ) ;
126- assert . strictEqual ( pf . lines [ 16 ] . offset , 64 ) ;
127-
128- // the fourth breakpoint w/ line 25, offset 125 is indexed as 125 in offsets
129- assert . strictEqual ( pf . offsets [ 125 ] . line , 25 ) ;
130- assert . strictEqual ( pf . offsets [ 125 ] . offset , 125 ) ;
131- } ) ;
76+ const bp = new Breakpoint ( {
77+ scriptId : 1 ,
78+ func : mockParsedFunction ,
79+ line : 42 ,
80+ offset : 37 ,
81+ } ) ;
82+ assert . strictEqual ( bp . toString ( ) , 'jerry.js:42' ) ;
83+ } ) ;
84+
85+ test ( 'reports source name as "<unknown>" if not given' , ( ) => {
86+ mockParsedFunction . isFunc = false ;
87+ mockParsedFunction . sourceName = undefined ;
88+
89+ const bp = new Breakpoint ( {
90+ scriptId : 1 ,
91+ func : mockParsedFunction ,
92+ line : 42 ,
93+ offset : 37 ,
94+ } ) ;
95+ assert . strictEqual ( bp . toString ( ) , '<unknown>:42' ) ;
96+ } ) ;
97+ } ) ;
98+
99+ suite ( 'ParsedFunction constructor' , ( ) => {
100+ test ( 'adds a breakpoint for each line/offset pair in the frame' , ( ) => {
101+ const frame = {
102+ isFunc : true ,
103+ scriptId : 42 ,
104+ line : 1 ,
105+ column : 2 ,
106+ source : '' ,
107+ sourceName : 'cheese.js' ,
108+ name : 'cheddar' ,
109+ lines : [ 4 , 9 , 16 , 25 ] ,
110+ offsets : [ 8 , 27 , 64 , 125 ] ,
111+ } ;
112+
113+ const pf = new ParsedFunction ( 7 , frame ) ;
114+ assert . strictEqual ( pf . isFunc , true ) ;
115+ assert . strictEqual ( pf . byteCodeCP , 7 ) ;
116+ assert . strictEqual ( pf . scriptId , 42 ) ;
117+ assert . strictEqual ( pf . line , 1 ) ;
118+ assert . strictEqual ( pf . column , 2 ) ;
119+ assert . strictEqual ( pf . name , 'cheddar' ) ;
120+ assert . strictEqual ( pf . firstBreakpointLine , 4 ) ;
121+ assert . strictEqual ( pf . firstBreakpointOffset , 8 ) ;
122+ assert . strictEqual ( pf . sourceName , 'cheese.js' ) ;
123+
124+ // the third breakpoint w/ line 16, offset 64 is indexed as 16 in lines
125+ assert . strictEqual ( pf . lines [ 16 ] . line , 16 ) ;
126+ assert . strictEqual ( pf . lines [ 16 ] . offset , 64 ) ;
127+
128+ // the fourth breakpoint w/ line 25, offset 125 is indexed as 125 in offsets
129+ assert . strictEqual ( pf . offsets [ 125 ] . line , 25 ) ;
130+ assert . strictEqual ( pf . offsets [ 125 ] . offset , 125 ) ;
132131 } ) ;
132+ } ) ;
133133} ) ;
0 commit comments