-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for overlapping command names or aliases (#2059)
Co-authored-by: aweebit <[email protected]>
- Loading branch information
1 parent
b96af40
commit 1d3dd47
Showing
2 changed files
with
83 additions
and
4 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,49 @@ | ||
const { Command } = require('../'); | ||
|
||
test('when command name conflicts with existing name then throw', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program.command('one'); | ||
program.command('one'); | ||
}).toThrow('cannot add command'); | ||
}); | ||
|
||
test('when command name conflicts with existing alias then throw', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program.command('one').alias('1'); | ||
program.command('1'); | ||
}).toThrow('cannot add command'); | ||
}); | ||
|
||
test('when command alias conflicts with existing name then throw', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program.command('one'); | ||
program.command('1').alias('one'); | ||
}).toThrow('cannot add alias'); | ||
}); | ||
|
||
test('when command alias conflicts with existing alias then throw', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program.command('one').alias('1'); | ||
program.command('unity').alias('1'); | ||
}).toThrow('cannot add alias'); | ||
}); | ||
|
||
test('when .addCommand name conflicts with existing name then throw', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program.command('one'); | ||
program.addCommand(new Command('one')); | ||
}).toThrow('cannot add command'); | ||
}); | ||
|
||
test('when .addCommand alias conflicts with existing name then throw', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program.command('one'); | ||
program.addCommand(new Command('unity').alias('one')); | ||
}).toThrow('cannot add command'); | ||
}); |