Skip to content

Commit f8f8621

Browse files
authored
Merge pull request #342 from smalruby/fix-escape-keycode
Fix escape keycode
2 parents 4ac52eb + ad2c735 commit f8f8621

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/ruby-generator/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ RubyGenerator.scrubNakedValue = function (line) {
331331
};
332332

333333
RubyGenerator.escapeChars_ = {
334-
'"': '\\"'
334+
'"': '\\"',
335+
'\\': '\\\\'
335336
};
336337

337338
RubyGenerator.quote_ = function (string) {

test/integration/ruby-tab/operators.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import dedent from 'dedent';
22
import SeleniumHelper from '../../helpers/selenium-helper';
33
import RubyHelper from '../../helpers/ruby-helper';
4+
import {EDIT_MENU_XPATH} from '../../helpers/menu-xpaths';
45

56
const seleniumHelper = new SeleniumHelper();
67
const {
8+
clickText,
9+
clickXpath,
710
getDriver,
811
loadUri,
912
urlFor
1013
} = seleniumHelper;
1114

1215
const rubyHelper = new RubyHelper(seleniumHelper);
1316
const {
17+
fillInRubyProgram,
18+
currentRubyProgram,
1419
expectInterconvertBetweenCodeAndRuby
1520
} = rubyHelper;
1621

@@ -93,4 +98,28 @@ describe('Ruby Tab: Operators category blocks', () => {
9398
`;
9499
await expectInterconvertBetweenCodeAndRuby(code);
95100
});
101+
102+
test('Ruby -> Code -> Ruby (escape characters) ', async () => {
103+
await loadUri(urlFor('/'));
104+
105+
const beforeRuby = dedent`
106+
"\\\\" + "\\\\"
107+
108+
"\\n" + "\\n"
109+
`;
110+
111+
const afterRuby = dedent`
112+
"\\" + "\\"
113+
114+
"\n" + "\n"
115+
`;
116+
117+
await clickText('Ruby', '*[@role="tab"]');
118+
await fillInRubyProgram(beforeRuby);
119+
await clickText('Code', '*[@role="tab"]');
120+
await clickXpath(EDIT_MENU_XPATH);
121+
await clickText('Generate Ruby from Code');
122+
await clickText('Ruby', '*[@role="tab"]');
123+
expect(await currentRubyProgram()).toEqual(`${afterRuby}\n`);
124+
});
96125
});

test/unit/lib/ruby-generator.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('RubyGenerator', () => {
1515
describe('quote_', () => {
1616
test('escape only " to \\"', () => {
1717
const arg = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'; // eslint-disable-line
18-
const expected = '"!\\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"'; // eslint-disable-line
18+
const expected = '"!\\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"'; // eslint-disable-line
1919
expect(RubyGenerator.quote_(arg)).toEqual(expected);
2020
});
2121
});

0 commit comments

Comments
 (0)