Add list-files: csv format

This commit is contained in:
Michal Dorner 2021-02-20 11:21:30 +01:00
parent e2bed85912
commit b5fa2d5c02
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
8 changed files with 127 additions and 51 deletions

View file

@ -0,0 +1,23 @@
import {csvEscape} from '../src/list-format/csv-escape'
describe('csvEscape() backslash escapes every character except subset of definitely safe characters', () => {
test('simple filename should not be modified', () => {
expect(csvEscape('file.txt')).toBe('file.txt')
})
test('directory separator should be preserved and not escaped', () => {
expect(csvEscape('path/to/file.txt')).toBe('path/to/file.txt')
})
test('filename with spaces should be quoted', () => {
expect(csvEscape('file with space')).toBe('"file with space"')
})
test('filename with "," should be quoted', () => {
expect(csvEscape('file, with coma')).toBe('"file, with coma"')
})
test('Double quote should be escaped by another double quote', () => {
expect(csvEscape('file " with double quote')).toBe('"file "" with double quote"')
})
})

View file

@ -1,24 +1,24 @@
import {escape, shellEscape} from '../src/shell-escape'
import {backslashEscape, shellEscape} from '../src/list-format/shell-escape'
describe('escape() backslash escapes every character except subset of definitely safe characters', () => {
test('simple filename should not be modified', () => {
expect(escape('file.txt')).toBe('file.txt')
expect(backslashEscape('file.txt')).toBe('file.txt')
})
test('directory separator should be preserved and not escaped', () => {
expect(escape('path/to/file.txt')).toBe('path/to/file.txt')
expect(backslashEscape('path/to/file.txt')).toBe('path/to/file.txt')
})
test('spaces should be escaped with backslash', () => {
expect(escape('file with space')).toBe('file\\ with\\ space')
expect(backslashEscape('file with space')).toBe('file\\ with\\ space')
})
test('quotes should be escaped with backslash', () => {
expect(escape('file\'with quote"')).toBe('file\\\'with\\ quote\\"')
expect(backslashEscape('file\'with quote"')).toBe('file\\\'with\\ quote\\"')
})
test('$variables should be escaped', () => {
expect(escape('$var')).toBe('\\$var')
expect(backslashEscape('$var')).toBe('\\$var')
})
})