This commit is contained in:
@@ -199,6 +199,23 @@ describe('Enum', () => {
|
||||
test('number out', () => testing('4', Type.Enum(TestNumber), false))
|
||||
test('basic string', () => testing('a', Type.Enum(TestString), true, TestString.A))
|
||||
test('string out', () => testing('c', Type.Enum(TestString), false))
|
||||
test('number with transform', async () => {
|
||||
const scheme = Type.Transform(Type.String())
|
||||
.Decode(value => {
|
||||
value = value.toLowerCase()
|
||||
if (value === 'a') return TestNumber.A
|
||||
if (value === 'b') return TestNumber.B
|
||||
if (value === 'c') return TestNumber.C
|
||||
if (value === 'c') return TestNumber.D
|
||||
})
|
||||
.Encode(value => {
|
||||
if (value === 0) return 'A'
|
||||
if (value === 1) return 'B'
|
||||
if (value === 2) return 'C'
|
||||
return 'D'
|
||||
})
|
||||
await testing('A', scheme, true, TestNumber.A)
|
||||
})
|
||||
})
|
||||
|
||||
// Read specific types
|
||||
|
||||
Reference in New Issue
Block a user