Skip to content

Commit fb975bb

Browse files
authored
Merge pull request #19 from darkriszty/feature/EscapeCodeBlocks
Feature/escape code blocks
2 parents 64fbc56 + 448e925 commit fb975bb

5 files changed

Lines changed: 68 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88
### Added
9-
- Issue #12: Full rewrite for refactoring
10-
- Issue #11: Support escaping of separators with backslash
9+
- Issue #12: Full rewrite for refactoring.
10+
- Issue #11: Support escaping of separators with backslash.
11+
- Issue #16: Ignore separators that are in code blocks.
1112

1213
## 1.1.1 - 2017-05-27
1314
### Fixed

src/modelFactory/selectionInterpreter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class SelectionInterpreter {
1616
index = -1,
1717
previousSplitIndex = -1;
1818
while ((index = line.indexOf("|", index + 1)) > -1) {
19-
if (line[index - 1] != "\\") {
19+
if (line[index - 1] != "\\" && !this.codeBlockOpenTill(line.substr(0, index))) {
2020
result.push(line.substring(previousSplitIndex + 1, index));
2121
previousSplitIndex = index;
2222
}
@@ -25,4 +25,8 @@ export class SelectionInterpreter {
2525

2626
return result;
2727
}
28+
29+
private codeBlockOpenTill(text: string): boolean {
30+
return (text.match(/`/g) || []).length % 2 != 0;
31+
}
2832
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Type | Range | Size
2+
-------|-------------------------------------------------------------|--------------------------
3+
sbyte | -128 `|to|` 127 | Signed 8-bit integer
4+
byte | 0 `|to|` 255 | Unsigned 8-bit integer
5+
char | U+0000 `|to|` U+ffff | Unicode 16-bit character
6+
short | -32,768 `|to|` 32,767 | Signed 16-bit integer
7+
ushort | 0 `|to|` 65,535 | Unsigned 16-bit integer
8+
int | -2,147,483,648 `|to|` 2,147,483,647 | Signed 32-bit integer
9+
uint | 0 `|to|` 4,294,967,295 | Unsigned 32-bit integer
10+
long | -9,223,372,036,854,775,808 `|to|` 9,223,372,036,854,775,807 | Signed 64-bit integer
11+
ulong | 0 `|to|` 18,446,744,073,709,551,615 | Unsigned 64-bit integer
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Type | Range| Size
2+
-|-|-
3+
sbyte | -128 `|to|` 127| Signed 8-bit integer
4+
byte| 0 `|to|` 255| Unsigned 8-bit integer
5+
char| U+0000 `|to|` U+ffff| Unicode 16-bit character
6+
short| -32,768 `|to|` 32,767| Signed 16-bit integer
7+
ushort| 0 `|to|` 65,535| Unsigned 16-bit integer
8+
int| -2,147,483,648 `|to|` 2,147,483,647| Signed 32-bit integer
9+
uint| 0 `|to|` 4,294,967,295| Unsigned 32-bit integer
10+
long| -9,223,372,036,854,775,808 `|to|` 9,223,372,036,854,775,807| Signed 64-bit integer
11+
ulong| 0 `|to|` 18,446,744,073,709,551,615| Unsigned 64-bit integer

test/unitTests/modelFactory/selectionInterpreter.test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ suite("SelectionInterpreter tests", () => {
6060
assert.equal(rows[0][5], "");
6161
});
6262

63-
test("allRows() doesn't consider \\| as separator ", () => {
63+
test("allRows() doesn't consider \\| as separator", () => {
6464
const text = "h1|h2\\|still\\|h2\nv1|v2";
6565
const sut = createSut();
6666

@@ -75,6 +75,43 @@ suite("SelectionInterpreter tests", () => {
7575
assert.equal(rows[1][1], "v2");
7676
});
7777

78+
test("allRows() doesn't consider separator that's in a `code block` #1", () => {
79+
const text = "`h1|h2|h3`";
80+
const sut = createSut();
81+
82+
const rows = sut.allRows(text);
83+
84+
assert.equal(rows.length, 1);
85+
assert.equal(rows[0].length, 1);
86+
assert.equal(rows[0][0], "`h1|h2|h3`");
87+
});
88+
89+
test("allRows() doesn't consider separator that's in a `code block` #2", () => {
90+
const text = "h1|h2`|still|h2`|h3";
91+
const sut = createSut();
92+
93+
const rows = sut.allRows(text);
94+
95+
assert.equal(rows.length, 1);
96+
assert.equal(rows[0].length, 3);
97+
assert.equal(rows[0][0], "h1");
98+
assert.equal(rows[0][1], "h2`|still|h2`");
99+
assert.equal(rows[0][2], "h3");
100+
});
101+
102+
test("allRows() doesn't consider separator that's in a `code block` #3", () => {
103+
const text = "`h1|h1`|h2|h3`|h3`";
104+
const sut = createSut();
105+
106+
const rows = sut.allRows(text);
107+
108+
assert.equal(rows.length, 1);
109+
assert.equal(rows[0].length, 3);
110+
assert.equal(rows[0][0], "`h1|h1`");
111+
assert.equal(rows[0][1], "h2");
112+
assert.equal(rows[0][2], "h3`|h3`");
113+
});
114+
78115
test("separator() returns the first row", () => {
79116
const text = "h1|h2\r\n:-|-\r\nv1|v2";
80117
const sut = createSut();

0 commit comments

Comments
 (0)