-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
384749b
commit 9a17454
Showing
5 changed files
with
115 additions
and
63 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
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,22 @@ | ||
import * as path from 'path' | ||
|
||
/** | ||
* Get the file name for a given command ID replacing "-" with "__" and ":" with "-" | ||
* @param cmdId - command ID | ||
* @returns {string} - file name | ||
*/ | ||
export const getSchemaFileName = (cmdId: string): string => { | ||
const baseName = cmdId.replace(/-/g, '__').replace(/:/g, '-') | ||
return `${baseName}.json` | ||
} | ||
|
||
/** | ||
* Get the command ID from a given file name replacing "-" with ":" and "__" with "-" | ||
* @param file - file name | ||
* @returns {string} - command ID | ||
*/ | ||
export const getKeyNameFromFilename = (file: string): string => { | ||
return path.basename(file.replace(/-/g, ':')) | ||
.replace(/__/g, '-') | ||
.replace('.json', '') | ||
} |
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,40 @@ | ||
import {expect} from '@oclif/test' | ||
import {getKeyNameFromFilename} from '../src/util' | ||
import {getSchemaFileName} from '../lib/util' | ||
|
||
describe('util test', () => { | ||
describe('getKeyNameFromFilename', () => { | ||
it('should return correct command id when only hyphens in file name a-b-c.json', () => { | ||
expect(getKeyNameFromFilename('a-b-c.json')).to.equal('a:b:c') | ||
}) | ||
it('should return correct command id when escaped hyphens in file name a-b-c__d.json', () => { | ||
expect(getKeyNameFromFilename('a-b-c__d.json')).to.equal('a:b:c-d') | ||
}) | ||
it('should return correct command id when escaped hyphens in file name a__b-c__d.json', () => { | ||
expect(getKeyNameFromFilename('a__b-c__d.json')).to.equal('a-b:c-d') | ||
}) | ||
it('should return correct command id when escaped hyphens in file name a-b__c__d.json', () => { | ||
expect(getKeyNameFromFilename('a-b__c__d.json')).to.equal('a:b-c-d') | ||
}) | ||
it('should return correct command id when underscore in file name a-b-c_d.json', () => { | ||
expect(getKeyNameFromFilename('a-b-c_d.json')).to.equal('a:b:c_d') | ||
}) | ||
}) | ||
describe('getSchemaFileName', () => { | ||
it('should return correct file name when only ":" in command id a:b:c', () => { | ||
expect(getSchemaFileName('a:b:c')).to.equal('a-b-c.json') | ||
}) | ||
it('should return correct file name when hyphens in command id a:b:c-d', () => { | ||
expect(getSchemaFileName('a:b:c-d')).to.equal('a-b-c__d.json') | ||
}) | ||
it('should return correct file name when hyphens in command id a-b:c-d', () => { | ||
expect(getSchemaFileName('a-b:c-d')).to.equal('a__b-c__d.json') | ||
}) | ||
it('should return correct file name when hyphens in command id a:b-c-d', () => { | ||
expect(getSchemaFileName('a:b-c-d')).to.equal('a-b__c__d.json') | ||
}) | ||
it('should return correct file name when underscore in command id a:b:c_d', () => { | ||
expect(getSchemaFileName('a:b:c_d')).to.equal('a-b-c_d.json') | ||
}) | ||
}) | ||
}) |
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