Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Apr 18, 2024
1 parent da17fdf commit 5d09b9f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/__tests__/path_validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as fs from 'fs'
import {
ILLEGAL_CHAR_REGEX_FILE,
replaceIllegalCharsFile,
replaceIllegalCharsFolder,
REPLACEMENT_CHAR,
} from '../util'

const expectedManualIllegalChars: string[] = [
'/',
const expectedManualIllegalCharsInFolderName: string[] = [
'\\',
'?',
'*',
Expand All @@ -19,9 +19,32 @@ const expectedManualIllegalChars: string[] = [
'\u001F',
]

// Adding forward slash too which is not allowed in file names
const expectedManualIllegalChars =
expectedManualIllegalCharsInFolderName.concat(['/'])

// ZERO WIDTH JOINER and SOFT HYPHEN
const expectedInvisibleChars: string[] = ['­', '‍']

describe('replaceIllegalCharsFolder() does not replace forward slash', () => {
test('Forward slash is not replaced', () => {
const input = 'this/that'
const output = replaceIllegalCharsFolder(input)
expect(output).toEqual(input)
})
})

describe('replaceIllegalCharsFolder() removes all expected characters', () => {
test.each(expectedManualIllegalCharsInFolderName)(
'Illegal character "%s" is removed',
(character) => {
const input = `this${character}string`
const output = replaceIllegalCharsFolder(input)
expect(output).not.toContain(character)
},
)
})

describe('replaceIllegalCharsFile() removes all expected characters', () => {
test.each(expectedManualIllegalChars)(
'Illegal character "%s" is removed',
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const REPLACEMENT_CHAR = '-'
// credit: https://github.com/sindresorhus/filename-reserved-regex
// eslint-disable-next-line no-control-regex
export const ILLEGAL_CHAR_REGEX_FILE = /[<>:"/\\|?*\u0000-\u001F]/g
export const ILLEGAL_CHAR_REGEX_FOLDER = /[<>"\\|?*\u0000-\u001F]/g
export const ILLEGAL_CHAR_REGEX_FOLDER = /[<>:"\\|?*\u0000-\u001F]/g

export interface HighlightPoint {
left: number
Expand Down

0 comments on commit 5d09b9f

Please sign in to comment.