Skip to content

Commit

Permalink
add highlighting tests verifying addMarker and removeMarker calls
Browse files Browse the repository at this point in the history
  • Loading branch information
cpirich committed Jan 29, 2018
1 parent 101328c commit 11f93ef
Showing 1 changed file with 143 additions and 2 deletions.
145 changes: 143 additions & 2 deletions apps/test/unit/lib/tools/jsinterpreter/JSInterpreterTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,31 @@ myCallback("this message is coming from inside the interpreter");
});

let aceEditor;
let Range = function (startRow, startColumn, endRow, endColumn) {
this.start = {
row: startRow,
column: startColumn
};

this.end = {
row: endRow,
column: endColumn
};
};

function setupFakeAce() {
let oldAce;
let markerId = 1;
beforeEach(() => {
oldAce = window.ace;
window.ace = {
require: sinon.stub().returns({Range: sinon.stub()}),
require: sinon.stub().returns({Range}),
};
const breakpoints = [];
const aceSession = {
addMarker: sinon.spy(),
addMarker: sinon.spy(() => markerId++),
getBreakpoints: sinon.stub().returns(breakpoints),
removeMarker: sinon.spy(),
};
aceEditor = {
isRowFullyVisible: () => true,
Expand Down Expand Up @@ -380,6 +394,18 @@ myCallback("this message is coming from inside the interpreter");
it("will stop executing at the breakpoint", () => {
expect(getCurrentLine()).to.equal(1);
});
it("will highlight the line after the breakpoint", () => {
expect(aceEditor.getSession().addMarker.lastCall.args[0]).to.deep.equal({
start: {
row: 2,
column: 10,
},
end: {
row: 2,
column: 26,
},
});
});
it("will notify the onPause observer", () => {
expect(onPauseObserver).to.have.been.called;
});
Expand All @@ -393,13 +419,28 @@ myCallback("this message is coming from inside the interpreter");
it("will stop at the next breakpoint", () => {
expect(getCurrentLine()).to.equal(3);
});
it("will highlight the line after the breakpoint", () => {
expect(aceEditor.getSession().addMarker.lastCall.args[0]).to.deep.equal({
start: {
row: 4,
column: 10,
},
end: {
row: 4,
column: 26,
},
});
});
describe("and executed again after all breakpoints have been reached", () => {
beforeEach(() => {
jsInterpreter.executeInterpreter(false);
});
it("will execute the rest of the code", () => {
expect(getCurrentLine()).to.equal(5);
});
it("will remove the highlight marker for the most recent highlight", () => {
expect(aceEditor.getSession().removeMarker.lastCall.args[0]).to.equal(aceEditor.getSession().addMarker.lastCall.returnValue);
});
});
});
});
Expand All @@ -422,6 +463,18 @@ myCallback("this message is coming from inside the interpreter");
it("will execute the line that the breakpoint is on and move to the next one", () => {
expect(getCurrentLine()).to.equal(2);
});
it("will highlight the line after the step over", () => {
expect(aceEditor.getSession().addMarker.lastCall.args[0]).to.deep.equal({
start: {
row: 3,
column: 10,
},
end: {
row: 3,
column: 26,
},
});
});
});

describe("When executed with handleStepOut having been called", () => {
Expand Down Expand Up @@ -449,6 +502,18 @@ myCallback("this message is coming from inside the interpreter");
)).to.be.false;
expect(getCurrentLine()).to.equal(3);
});
it("will highlight the line after the function call", () => {
expect(aceEditor.getSession().addMarker.lastCall.args[0]).to.deep.equal({
start: {
row: 7,
column: 10,
},
end: {
row: 7,
column: 26,
},
});
});
});

describe("When executed with handleStepOut having been called inside a deeply nested function call", () => {
Expand Down Expand Up @@ -485,6 +550,18 @@ myCallback("this message is coming from inside the interpreter");
'middleFunctionScope'
)).to.be.true;
});
it("will highlight the line after the inner function call", () => {
expect(aceEditor.getSession().addMarker.lastCall.args[0]).to.deep.equal({
start: {
row: 8,
column: 12,
},
end: {
row: 8,
column: 28,
},
});
});

describe("and we step out again", () => {
beforeEach(() => {
Expand All @@ -494,6 +571,18 @@ myCallback("this message is coming from inside the interpreter");
it("will step out again", () => {
expect(getCurrentLine()).to.equal(8);
});
it("will highlight the line after the inner function call", () => {
expect(aceEditor.getSession().addMarker.lastCall.args[0]).to.deep.equal({
start: {
row: 12,
column: 10,
},
end: {
row: 12,
column: 27,
},
});
});
});
});

Expand Down Expand Up @@ -530,6 +619,18 @@ myCallback("this message is coming from inside the interpreter");
jsInterpreter.executeInterpreter(false);
expect(getCurrentLine()).to.equal(4);
});
it("will highlight the line at the inner breakpoint", () => {
expect(aceEditor.getSession().addMarker.lastCall.args[0]).to.deep.equal({
start: {
row: 4,
column: 12,
},
end: {
row: 4,
column: 28,
},
});
});
});

describe("When executed after handleStepIn() is called", () => {
Expand All @@ -551,6 +652,18 @@ myCallback("this message is coming from inside the interpreter");
it("will not execute the line it steps onto", () => {
expect(getCurrentLine()).to.be.undefined;
});
it("will highlight the first line", () => {
expect(aceEditor.getSession().addMarker.lastCall.args[0]).to.deep.equal({
start: {
row: 1,
column: 10,
},
end: {
row: 1,
column: 30,
},
});
});

describe("And after handleStepOver is subsequently called", () => {
beforeEach(() => {
Expand All @@ -560,6 +673,18 @@ myCallback("this message is coming from inside the interpreter");
it("will execute the line it is currently on", () => {
expect(getCurrentLine()).to.equal(1);
});
it("will highlight the line after the step over", () => {
expect(aceEditor.getSession().addMarker.lastCall.args[0]).to.deep.equal({
start: {
row: 2,
column: 10,
},
end: {
row: 2,
column: 26,
},
});
});
it("will keep the interpreter in the paused state", () => {
expect(jsInterpreter.paused).to.be.true;
});
Expand All @@ -572,6 +697,9 @@ myCallback("this message is coming from inside the interpreter");
it("will execute the rest of the code", () => {
expect(getCurrentLine()).to.equal(3);
});
it("will remove the highlight marker for the most recent highlight", () => {
expect(aceEditor.getSession().removeMarker.lastCall.args[0]).to.equal(aceEditor.getSession().addMarker.lastCall.returnValue);
});
it("will make the interpreter no longer paused", () => {
expect(jsInterpreter.paused).to.be.false;
});
Expand All @@ -594,6 +722,19 @@ myCallback("this message is coming from inside the interpreter");
expect(jsInterpreter.handleError).to.have.been.called;
expect(jsInterpreter.handleError).to.have.been.calledWith(2);
});
it("will highlight as an error the first character of the program since the exception wasn't handled", () => {
expect(aceEditor.getSession().addMarker.lastCall.args[0]).to.deep.equal({
start: {
row: 0,
column: 0,
},
end: {
row: 1,
column: 0,
},
});
expect(aceEditor.getSession().addMarker.lastCall.args[1]).to.equal('ace_error');
});
});
describe("with hideSource=true", () => {
beforeEach(() => {
Expand Down

0 comments on commit 11f93ef

Please sign in to comment.