Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: ut for charAliases #791

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 51 additions & 8 deletions test/parser/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1749,15 +1749,58 @@ See more help with --help`)
expect(out.flags.foo).to.equal(true)
})

it('works with aliased short char', async () => {
const out = await parse(['-b'], {
flags: {
foo: Flags.boolean({
charAliases: ['b'],
}),
},
describe('aliased short char', () => {
it('boolean', async () => {
const out = await parse(['-b'], {
flags: {
foo: Flags.boolean({
charAliases: ['b'],
}),
},
})
expect(out.flags.foo).to.equal(true)
})
it('string', async () => {
const out = await parse(['-b', 'hello'], {
flags: {
foo: Flags.string({
charAliases: ['b'],
}),
},
})
expect(out.flags.foo).to.equal('hello')
})
it('empty charAliases', async () => {
const out = await parse(['--foo', 'hello'], {
flags: {
foo: Flags.string({
charAliases: [],
}),
},
})
expect(out.flags.foo).to.equal('hello')
})
it('duplicated flag via charAliases and full name (last in wins', async () => {
const out = await parse(['--foo', 'hello', '--foo', 'hi'], {
flags: {
foo: Flags.string({
charAliases: ['b'],
}),
},
})
expect(out.flags.foo).to.equal('hi')
})
it('duplicated via aliases charAliases (last in wins', async () => {
const out = await parse(['-b', 'hello', '-b', 'hi'], {
flags: {
foo: Flags.string({
aliases: ['b'],
charAliases: ['b'],
}),
},
})
expect(out.flags.foo).to.equal('hi')
})
expect(out.flags.foo).to.equal(true)
})
})
})
Loading