|
| 1 | +const assert = require('assert'); |
| 2 | +const vscode = require('vscode'); |
| 3 | +const parseTable = require('../src/parse-table'); |
| 4 | + |
| 5 | +suite('Quoted Values Parsing Test Suite', () => { |
| 6 | + // Mock configuration |
| 7 | + const originalGetConfiguration = vscode.workspace.getConfiguration; |
| 8 | + |
| 9 | + setup(() => { |
| 10 | + vscode.workspace.getConfiguration = () => ({ |
| 11 | + get: (key) => { |
| 12 | + switch (key) { |
| 13 | + case 'decimalPoint': return '10,000.00'; |
| 14 | + case 'defaultConvention': return 'PascalCase'; |
| 15 | + default: return null; |
| 16 | + } |
| 17 | + } |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + teardown(() => { |
| 22 | + vscode.workspace.getConfiguration = originalGetConfiguration; |
| 23 | + }); |
| 24 | + |
| 25 | + test('should strip surrounding quotes from numeric values', () => { |
| 26 | + const input = 'Col1\n"1"'; |
| 27 | + const result = parseTable.parseClipboard(input); |
| 28 | + |
| 29 | + // Should catch the issue: currently "1" is parsed as string "1" (with quotes likely kept or treated as string) |
| 30 | + // We expect it to be parsed as a number 1 |
| 31 | + assert.ok(result); |
| 32 | + assert.strictEqual(result.data[0][0], 1); |
| 33 | + // If it fails, it probably returns "1" (string) or key remains string type |
| 34 | + }); |
| 35 | + |
| 36 | + test('should strip surrounding quotes from string values', () => { |
| 37 | + const input = 'Col1\n"foo"'; |
| 38 | + const result = parseTable.parseClipboard(input); |
| 39 | + |
| 40 | + assert.ok(result); |
| 41 | + assert.strictEqual(result.data[0][0], 'foo'); |
| 42 | + // If it fails, it probably returns "\"foo\"" |
| 43 | + }); |
| 44 | + |
| 45 | + test('complex row with mixed quoted types', () => { |
| 46 | + // From issue description: x Apple Pear Lemon "1" |
| 47 | + const input = 'x\tApple\tPear\tLemon\n"1"\t"fruit"\t"fruit"\t"fruit"'; |
| 48 | + const result = parseTable.parseClipboard(input); |
| 49 | + |
| 50 | + assert.ok(result); |
| 51 | + assert.strictEqual(result.headers[0], 'X'); |
| 52 | + assert.strictEqual(result.data[0][0], 1); // "1" -> 1 |
| 53 | + assert.strictEqual(result.data[0][1], 'fruit'); // "fruit" -> fruit |
| 54 | + }); |
| 55 | +}); |
0 commit comments