Skip to content
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/lib/ruby-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ RubyGenerator.scrubNakedValue = function (line) {
};

RubyGenerator.escapeChars_ = {
'"': '\\"'
'"': '\\"',
'\\': '\\\\'
};

RubyGenerator.quote_ = function (string) {
Expand Down
29 changes: 29 additions & 0 deletions test/integration/ruby-tab/operators.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import dedent from 'dedent';
import SeleniumHelper from '../../helpers/selenium-helper';
import RubyHelper from '../../helpers/ruby-helper';
import {EDIT_MENU_XPATH} from '../../helpers/menu-xpaths';

const seleniumHelper = new SeleniumHelper();
const {
clickText,
clickXpath,
getDriver,
loadUri,
urlFor
} = seleniumHelper;

const rubyHelper = new RubyHelper(seleniumHelper);
const {
fillInRubyProgram,
currentRubyProgram,
expectInterconvertBetweenCodeAndRuby
} = rubyHelper;

Expand Down Expand Up @@ -93,4 +98,28 @@ describe('Ruby Tab: Operators category blocks', () => {
`;
await expectInterconvertBetweenCodeAndRuby(code);
});

test('Ruby -> Code -> Ruby (escape characters) ', async () => {
await loadUri(urlFor('/'));

const beforeRuby = dedent`
"\\\\" + "\\\\"

"\\n" + "\\n"
`;

const afterRuby = dedent`
"\\" + "\\"

"\n" + "\n"
`;

await clickText('Ruby', '*[@role="tab"]');
await fillInRubyProgram(beforeRuby);
await clickText('Code', '*[@role="tab"]');
await clickXpath(EDIT_MENU_XPATH);
await clickText('Generate Ruby from Code');
await clickText('Ruby', '*[@role="tab"]');
expect(await currentRubyProgram()).toEqual(`${afterRuby}\n`);
});
});
2 changes: 1 addition & 1 deletion test/unit/lib/ruby-generator.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('RubyGenerator', () => {
describe('quote_', () => {
test('escape only " to \\"', () => {
const arg = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'; // eslint-disable-line
const expected = '"!\\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"'; // eslint-disable-line
const expected = '"!\\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"'; // eslint-disable-line
expect(RubyGenerator.quote_(arg)).toEqual(expected);
});
});
Expand Down