implemented of() and named() for numbers

This commit is contained in:
2026-02-22 14:21:22 +01:00
parent 140896bd7c
commit c76b5c3f0a
40 changed files with 1876 additions and 4344 deletions

View File

@@ -0,0 +1,49 @@
import { FlagDefinition, FlagsDictionary } from '~'
import { describe, expect, test } from 'vitest'
import { ReusedFlagAliasError, ReusedFlagValueError } from '../../src/errors'
class TestDefinition implements FlagDefinition<unknown, unknown> {
private readonly _value: number
public constructor(value: number) {
this._value = value
}
public get values(): unknown {
return this._value
}
public hasSameValue(other: FlagDefinition<unknown, unknown>): boolean {
return other instanceof TestDefinition && this._value === other._value
}
}
describe(FlagsDictionary, () => {
test('define then look up', () => {
const dict = new FlagsDictionary()
const def = new TestDefinition(1)
dict.define('test', def)
expect(dict.findByAlias('test')).toBe(def)
expect(dict.findByAlias('undefined')).toBe(undefined)
})
test("can't use the same alias twice", () => {
const dict = new FlagsDictionary()
dict.define('test', new TestDefinition(1))
expect(() => dict.define('test', new TestDefinition(2))).toThrow(
ReusedFlagAliasError,
)
})
test("can't use the same value twice", () => {
const dict = new FlagsDictionary()
dict.define('test A', new TestDefinition(1))
expect(() => dict.define('test B', new TestDefinition(1))).toThrow(
ReusedFlagValueError,
)
})
})