From dd8808b15d6aa7836b534e9fac0019eb4b1d2e2a Mon Sep 17 00:00:00 2001 From: Philipp Arndt <2f.mail@gmx.de> Date: Sun, 22 Nov 2020 13:54:44 +0100 Subject: [PATCH 1/3] regession test --- test/commands.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/commands.test.ts b/test/commands.test.ts index 224c525..814af21 100644 --- a/test/commands.test.ts +++ b/test/commands.test.ts @@ -19,6 +19,23 @@ function move(editor: vscode.TextEditor, line: number, col: number) { } suite('Commands', () => { + test('Regression: Format under cursor causes loss of data.', async () => { + const testCase = + `| A| B| + | -1| -1|`; + const expected = + `| A | B | +| -1 | -1 |`; + + await inTextEditor({language: 'markdown', content: testCase}, async (editor, document) => { + await cfg.override({mode: 'markdown'}); + move(editor, 0, 1); + await vscode.commands.executeCommand('text-tables.gotoNextCell'); + + assert.equal(document.getText(), expected); + }); + }); + test('Test "Create table" for markdown', async () => { const expectedResult = `| | | | --- | --- | From be1761755c7ce45239a0036c793d4c856b00a812 Mon Sep 17 00:00:00 2001 From: Philipp Arndt <2f.mail@gmx.de> Date: Sun, 22 Nov 2020 14:06:55 +0100 Subject: [PATCH 2/3] fix for markdown --- src/ttMarkdown.ts | 2 +- test/commands.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ttMarkdown.ts b/src/ttMarkdown.ts index d7607e7..05ee76c 100644 --- a/src/ttMarkdown.ts +++ b/src/ttMarkdown.ts @@ -71,7 +71,7 @@ export class MarkdownParser implements tt.Parser { isSeparatorRow(text: string): boolean { const cleaned = text.replace(/\s+/g, ''); - return cleaned.startsWith('|-') || cleaned.startsWith('|:-'); + return (cleaned.startsWith('|-') || cleaned.startsWith('|:-')) && cleaned.match(/^[:|-\s]+$/) ? true : false; } } diff --git a/test/commands.test.ts b/test/commands.test.ts index 814af21..0735ae1 100644 --- a/test/commands.test.ts +++ b/test/commands.test.ts @@ -22,7 +22,7 @@ suite('Commands', () => { test('Regression: Format under cursor causes loss of data.', async () => { const testCase = `| A| B| - | -1| -1|`; +| -1| -1|`; const expected = `| A | B | | -1 | -1 |`; From f70b3ede9d8224bb6ad54b8057d95e0b82f34c7a Mon Sep 17 00:00:00 2001 From: Philipp Arndt <2f.mail@gmx.de> Date: Sun, 22 Nov 2020 14:13:15 +0100 Subject: [PATCH 3/3] fix for org --- src/ttOrg.ts | 2 +- test/commands.test.ts | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ttOrg.ts b/src/ttOrg.ts index 4376be0..4f68c2b 100644 --- a/src/ttOrg.ts +++ b/src/ttOrg.ts @@ -38,7 +38,7 @@ export class OrgParser implements tt.Parser { } isSeparatorRow(text: string): boolean { - return text.length > 1 && text[1] === horizontalSeparator; + return text.length > 1 && text[1] === horizontalSeparator && text.match(/^[+|-\s]+$/) ? true : false;; } } diff --git a/test/commands.test.ts b/test/commands.test.ts index 0735ae1..e4022ea 100644 --- a/test/commands.test.ts +++ b/test/commands.test.ts @@ -28,7 +28,24 @@ suite('Commands', () => { | -1 | -1 |`; await inTextEditor({language: 'markdown', content: testCase}, async (editor, document) => { - await cfg.override({mode: 'markdown'}); + await cfg.override({mode: cfg.Mode.Markdown}); + move(editor, 0, 1); + await vscode.commands.executeCommand('text-tables.gotoNextCell'); + + assert.equal(document.getText(), expected); + }); + }); + + test('Regression: Format under cursor causes loss of data (org).', async () => { + const testCase = + `|A|B| +|-1|-1|`; + const expected = + `| A | B | +| -1 | -1 |`; + + await inTextEditor({language: 'markdown', content: testCase}, async (editor, document) => { + await cfg.override({mode: cfg.Mode.Org}); move(editor, 0, 1); await vscode.commands.executeCommand('text-tables.gotoNextCell');