-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Table.input for pasting tabular data (#11695)
Closes #11350 - Copy/pasting tabular data now creates `Table.input` nodes. - Column names are always copied when you work inside Enso (excluding cases when you paste some cells into an existing table) - When working with external apps, column names are copied only if `Copy with headers` is selected. https://github.com/user-attachments/assets/a1233483-ee4a-47e4-84a1-64dd0b1505ef Roundtrip with Google Spreadsheets (shows non-trivial TSV data that includes quotes and newlines): https://github.com/user-attachments/assets/4ac662a2-809f-423a-9e47-628f46f92835
- Loading branch information
Showing
16 changed files
with
325 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { expect, test } from 'vitest' | ||
import * as array from '../array' | ||
|
||
interface TransposeCase { | ||
matrix: number[][] | ||
expected: number[][] | ||
} | ||
|
||
const transposeCases: TransposeCase[] = [ | ||
{ matrix: [], expected: [] }, | ||
{ matrix: [[]], expected: [[]] }, | ||
{ matrix: [[1]], expected: [[1]] }, | ||
{ matrix: [[1, 2]], expected: [[1], [2]] }, | ||
{ matrix: [[1], [2]], expected: [[1, 2]] }, | ||
{ | ||
matrix: [ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
], | ||
expected: [ | ||
[1, 4], | ||
[2, 5], | ||
[3, 6], | ||
], | ||
}, | ||
] | ||
|
||
test.each(transposeCases)('transpose: case %#', ({ matrix, expected }) => { | ||
const transposed = array.transpose(matrix) | ||
expect(transposed).toStrictEqual(expected) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ject-view/components/GraphEditor/widgets/WidgetTableEditor/__tests__/tableParsing.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { assert } from '@/util/assert' | ||
import { expect, test } from 'vitest' | ||
import { parseTsvData, tableToEnsoExpression } from '../tableParsing' | ||
|
||
test.each([ | ||
{ | ||
description: 'Unpaired surrogate', | ||
tableData: '𝌆\t\uDAAA', | ||
expectedEnsoExpression: "Table.input [['Column #1', ['𝌆']], ['Column #2', ['\\u{daaa}']]]", | ||
}, | ||
{ | ||
description: 'Empty cell', | ||
tableData: '1\t2\n3\t', | ||
expectedEnsoExpression: | ||
"Table.input [['Column #1', ['1', '3']], ['Column #2', ['2', Nothing]]]", | ||
}, | ||
{ | ||
description: 'Line feed in cell', | ||
tableData: '1\t"2\n3"\n4\t5', | ||
expectedEnsoExpression: | ||
"Table.input [['Column #1', ['1', '4']], ['Column #2', ['2\\n3', '5']]]", | ||
}, | ||
{ | ||
description: 'Line feed in quoted cell', | ||
tableData: '1\t4\n2\t"""5\n6"""', | ||
expectedEnsoExpression: | ||
"Table.input [['Column #1', ['1', '2']], ['Column #2', ['4', '\"5\\n6\"']]]", | ||
}, | ||
{ | ||
description: 'Multiple rows, empty cells', | ||
tableData: [ | ||
'\t36\t52', | ||
'11\t\t4.727272727', | ||
'12\t\t4.333333333', | ||
'13\t2.769230769\t4', | ||
'14\t2.571428571\t3.714285714', | ||
'15\t2.4\t3.466666667', | ||
'16\t2.25\t3.25', | ||
'17\t2.117647059\t3.058823529', | ||
'19\t1.894736842\t2.736842105', | ||
'21\t1.714285714\t2.476190476', | ||
'24\t1.5\t2.166666667', | ||
'27\t1.333333333\t1.925925926', | ||
'30\t1.2\t', | ||
].join('\n'), | ||
expectedEnsoExpression: | ||
"Table.input [['Column #1', [Nothing, '11', '12', '13', '14', '15', '16', '17', '19', '21', '24', '27', '30']], ['Column #2', ['36', Nothing, Nothing, '2.769230769', '2.571428571', '2.4', '2.25', '2.117647059', '1.894736842', '1.714285714', '1.5', '1.333333333', '1.2']], ['Column #3', ['52', '4.727272727', '4.333333333', '4', '3.714285714', '3.466666667', '3.25', '3.058823529', '2.736842105', '2.476190476', '2.166666667', '1.925925926', Nothing]]]", | ||
}, | ||
])('Enso expression from Excel data: $description', ({ tableData, expectedEnsoExpression }) => { | ||
const rows = parseTsvData(tableData) | ||
expect(rows).not.toBeNull() | ||
assert(rows != null) | ||
expect(tableToEnsoExpression(rows)).toEqual(expectedEnsoExpression) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.