mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
a52d56f613
Summary: - Moved /test/client and /test/common to core. - Moved two files (CircularArray and RecentItems) from app/common to core/app/common. - Moved resetOrg test to gen-server. - `testrun.sh` is now invoking common and client test from core. - Added missing packages to core's package.json (and revealed underscore as it is used in the main app). - Removed Coord.js as it is not used anywhere. Test Plan: Existing tests Reviewers: paulfitz Reviewed By: paulfitz Subscribers: paulfitz Differential Revision: https://phab.getgrist.com/D3590
50 lines
2.2 KiB
TypeScript
50 lines
2.2 KiB
TypeScript
import * as csvFormat from 'app/common/csvFormat';
|
|
import {assert} from 'chai';
|
|
|
|
describe('csvFormat', function() {
|
|
it('should encode/decode csv values correctly', function() {
|
|
function verify(plain: string, encoded: string) {
|
|
assert.equal(csvFormat.csvEncodeCell(plain), encoded);
|
|
assert.equal(csvFormat.csvDecodeCell(encoded), plain);
|
|
}
|
|
verify("hello world", "hello world");
|
|
verify(`Commas,, galore, `, `"Commas,, galore, "`);
|
|
verify(`"Quote" 'me,', ""please!""`, `"""Quote"" 'me,', """"please!"""""`);
|
|
verify(` sing"le `, `" sing""le "`);
|
|
verify(``, ``);
|
|
verify(`""`, `""""""`);
|
|
verify(`\t\n'\`\\`, `"\t\n'\`\\"`);
|
|
// The exact interpretation of invalid encodings isn't too important, but should include most
|
|
// of the value and not throw exceptions.
|
|
assert.equal(csvFormat.csvDecodeCell(`invalid"e\ncoding `), `invalid"e\ncoding`);
|
|
assert.equal(csvFormat.csvDecodeCell(`"invalid"e`), `invalid"e`);
|
|
});
|
|
|
|
it('should encode/decode csv rows correctly', function() {
|
|
function verify(plain: string[], encoded: string, prettier: boolean) {
|
|
assert.equal(csvFormat.csvEncodeRow(plain, {prettier}), encoded);
|
|
assert.deepEqual(csvFormat.csvDecodeRow(encoded), plain);
|
|
}
|
|
verify(["hello", "world"], "hello,world", false);
|
|
verify(["hello", "world"], "hello, world", true);
|
|
verify(["hello ", " world"], `"hello "," world"`, false);
|
|
verify(["hello ", " world"], `"hello ", " world"`, true);
|
|
verify([' '], `" "`, false);
|
|
verify(['', ''], `,`, false);
|
|
verify(['', ' ', ''], `, " ", `, true);
|
|
verify([
|
|
"Commas,, galore, ",
|
|
`"Quote" 'me,', ""please!""`,
|
|
` sing"le `,
|
|
' ',
|
|
'',
|
|
], `"Commas,, galore, ","""Quote"" 'me,', """"please!"""""," sing""le "," ",`, false);
|
|
verify(['Medium', 'Very high', `with, comma*=~!|more`, `asdf\nsdf`],
|
|
`Medium, Very high, "with, comma*=~!|more", "asdf\nsdf"`, true);
|
|
// The exact interpretation of invalid encodings isn't too important, but should include most
|
|
// of the value and not throw exceptions.
|
|
assert.deepEqual(csvFormat.csvDecodeRow(`invalid"e\ncoding,","`),
|
|
['invalid"e\ncoding,', '']);
|
|
});
|
|
});
|