-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: extract option splitter and use it for --compiler (#958)
resolves #746
- Loading branch information
1 parent
184faba
commit 8b5fcdd
Showing
3 changed files
with
76 additions
and
14 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,17 @@ | ||
export default class OptionSplitter { | ||
static split(option) { | ||
const parts = option.split(/([^A-Z]):(?!\\)/) | ||
|
||
return parts.reduce((memo, part, i) => { | ||
if (partNeedsRecombined(i)) { | ||
memo.push(parts.slice(i, i + 2).join('')) | ||
} | ||
|
||
return memo | ||
}, []) | ||
} | ||
} | ||
|
||
function partNeedsRecombined(i) { | ||
return i % 2 === 0 | ||
} |
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,52 @@ | ||
import OptionSplitter from './option_splitter' | ||
|
||
describe('OptionSplitter', function() { | ||
const examples = [ | ||
{ | ||
description: "doesn't split when nothing to split on", | ||
input: '../custom/formatter', | ||
output: ['../custom/formatter'] | ||
}, | ||
{ | ||
description: 'splits relative unix paths', | ||
input: '../custom/formatter:../formatter/output.txt', | ||
output: ['../custom/formatter', '../formatter/output.txt'] | ||
}, | ||
{ | ||
description: 'splits absolute unix paths', | ||
input: '/custom/formatter:/formatter/output.txt', | ||
output: ['/custom/formatter', '/formatter/output.txt'] | ||
}, | ||
{ | ||
description: 'splits absolute windows paths', | ||
input: 'C:\\custom\\formatter:C:\\formatter\\output.txt', | ||
output: ['C:\\custom\\formatter', 'C:\\formatter\\output.txt'] | ||
}, | ||
{ | ||
description: 'does not split a single absolute windows paths', | ||
input: 'C:\\custom\\formatter', | ||
output: ['C:\\custom\\formatter'] | ||
}, | ||
{ | ||
description: 'splits extensions and modules', | ||
input: 'ts:typescript', | ||
output: ['ts', 'typescript'] | ||
}, | ||
{ | ||
description: 'splits extension and module with an absolute windows path', | ||
input: 'ts:C:/typescript', | ||
output: ['ts', 'C:/typescript'] | ||
}, | ||
{ | ||
description: 'splits more than 2 parts', | ||
input: 'part1:part2:part3', | ||
output: ['part1', 'part2', 'part3'] | ||
} | ||
] | ||
|
||
examples.forEach(({ description, input, output }) => { | ||
it(description, function() { | ||
expect(OptionSplitter.split(input)).to.eql(output) | ||
}) | ||
}) | ||
}) |