Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Proper marking of flat compound statements while debugging #4766

Merged
merged 7 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions static/js/appbundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions static/js/debugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const blockCommands = [
'ifpressed_elifs',
]

const ifRegex = "^((__if__) *[^\n ]+ *((__is__)|(__in__)) *[^\n ]+) *.+$";
const repeatRegex = "^((__repeat__) *[^\n ]+ *(__times__)) *[^\n ]+ *.+$";
const ifRegex = "((__if__) *[^\n ]+ *((__is__)|(__in__)) *[^\n ]+) *.*";
const repeatRegex = "((__repeat__) *[^\n ]+ *(__times__)) *[^\n ]+ *.+";
const elseRegex = "^(__else__) *[^\n ]+.+$";

/**
Expand Down Expand Up @@ -357,8 +357,13 @@ export function incrementDebugLine() {
break
} else if (theLevel <= 7 && blockCommands.includes(map.command)){
const lines = theGlobalEditor.contents.split('\n');
const fullLine = lines[map.hedy_range.from_line - 1];
const line = fullLine.substring(map.hedy_range.from_column - 1, map.hedy_range.to_column - 1);
let line: string;
if (map.hedy_range.from_line < map.hedy_range.to_line) {
line = lines[map.hedy_range.from_line - 1];
} else {
const fullLine = lines[map.hedy_range.from_line - 1];
line = fullLine.substring(map.hedy_range.from_column - 1, map.hedy_range.to_column - 1);
}
const activeLine: string = theGlobalDebugger.get_source_line(lineNumber - 1);

if (activeLine.match(/ *if/)) {
Expand Down
64 changes: 64 additions & 0 deletions tests/cypress/e2e/hedy_page/debugger.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,70 @@ describe('Test editor box functionality', () => {

cy.get('#output').should('contain.text', 'nice!');
});

it('Test flat if split between lines', () => {
cy.intercept('/parse').as('parse');

visitLevel(5);

cy.focused().type("if x is y\nprint '!bonito!'\nelse print 'meh'");

cy.get('#debug_button').click();
cy.wait('@parse')

cy.get('.cm-debugger-current-line > span').then(els => {
const texts = [...els].map(getText);
expect(texts).to.deep.eq('if x is y'.split(' '));
});
cy.get('#debug_continue').click();

cy.get('.cm-debugger-current-line > span').then(els => {
const texts = [...els].map(getText);
expect(texts).to.deep.eq(['print', "'meh'"]);
});

cy.get('#debug_continue').click();

cy.get('#output').should('contain.text', 'meh');
});

it('Test repeat with flat if split between lines inside', () => {
cy.intercept('/parse').as('parse');

visitLevel(7);

cy.focused().type("repeat 1 times if x is x print 'a'\nelse print 'b'");

cy.get('#debug_button').click();
cy.wait('@parse')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed a semicolon and they magically worked again 😐


cy.get('.cm-debugger-current-line > span').then(els => {
const texts = [...els].map(getText);
expect(texts).to.deep.eq('repeat 1 times'.split(' '));
});
cy.get('#debug_continue').click();

cy.get('.cm-debugger-current-line > span').then(els => {
const texts = [...els].map(getText);
expect(texts).to.deep.eq('repeat 1 times'.split(' '));
});
cy.get('#debug_continue').click();

cy.get('.cm-debugger-current-line > span').then(els => {
const texts = [...els].map(getText);
expect(texts).to.deep.eq('if x is x'.split(' '));
});
cy.get('#debug_continue').click();

cy.get('.cm-debugger-current-line > span').then(els => {
const texts = [...els].map(getText);
expect(texts).to.deep.eq(['print', "'a'"]);
});

cy.get('#debug_continue').click();

cy.get('#output').should('contain.text', 'a');
});
});

/**
Expand Down
Loading