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
7 changes: 5 additions & 2 deletions src/lineCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ export function cleanLine(text: string): string {
for (let i = 0; i < text.length; i++) {
const c = text[i];
if (isQuote(c)) {
withinQuotes = (withinQuotes === c) ? null : c;
if (withinQuotes === null) {
withinQuotes = c;
} else if (withinQuotes === c) {
withinQuotes = null;
}
}
if (isComment(c) && !withinQuotes) {
break;
}

cleaned += c;
}

return (cleaned.trimEnd());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as assert from 'assert';
import { extendSelection } from '../../selection';

// Defines a Mocha test suite to group tests of similar kind together
suite('Extension Tests', () => {
suite('extendSelection Tests', () => {

test('Selecting multi-line {} bracketed expression', () => {
const doc = `
Expand Down Expand Up @@ -615,4 +615,34 @@ suite('Extension Tests', () => {
assert.strictEqual(extendSelection(2, f, doc.length).endLine, 5);
});

test('extendSelection ignores commented out pipes - part 1', () => {
const doc = `
"a" %>%
print('a') # %>%
print("hi there")
`.split('\n');
function f(i: number) { return (doc[i]); }
assert.strictEqual(extendSelection(1, f, doc.length).startLine, 0);
assert.strictEqual(extendSelection(1, f, doc.length).endLine, 2);
assert.strictEqual(extendSelection(2, f, doc.length).startLine, 0);
assert.strictEqual(extendSelection(2, f, doc.length).endLine, 2);
assert.strictEqual(extendSelection(3, f, doc.length).startLine, 3);
assert.strictEqual(extendSelection(3, f, doc.length).endLine, 3);
});

test('extendSelection ignores commented out pipes - part 2', () => {
const doc = `
"a" %>%
print('a"inner comment"') # %>%
print("hi there")
`.split('\n');
function f(i: number) { return (doc[i]); }
assert.strictEqual(extendSelection(1, f, doc.length).startLine, 0);
assert.strictEqual(extendSelection(1, f, doc.length).endLine, 2);
assert.strictEqual(extendSelection(2, f, doc.length).startLine, 0);
assert.strictEqual(extendSelection(2, f, doc.length).endLine, 2);
assert.strictEqual(extendSelection(3, f, doc.length).startLine, 3);
assert.strictEqual(extendSelection(3, f, doc.length).endLine, 3);
});

});
16 changes: 16 additions & 0 deletions src/test/suite/lineCache.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as assert from 'assert';


import { cleanLine } from '../../lineCache';

// Defines a Mocha test suite to group tests of similar kind together
suite('lineCache Tests', () => {

test('cleanLine', () => {
assert.strictEqual(cleanLine('abcde '), 'abcde');
assert.strictEqual(cleanLine('abcde "abc" '), 'abcde "abc"');
assert.strictEqual(cleanLine('abcde #abd'), 'abcde');
assert.strictEqual(cleanLine('abcde "#abd" # jr2 2r'), 'abcde "#abd"');
assert.strictEqual(cleanLine('abcde "\'#abd\'" #jr 22r" '), 'abcde "\'#abd\'"');
});
});