Reorganize test cases

This commit is contained in:
trevor-signal 2025-06-26 12:24:07 -04:00 committed by GitHub
commit 843f545ceb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
271 changed files with 236 additions and 245 deletions

View file

@ -0,0 +1,37 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { makeEnumParser } from '../../util/enum';
describe('enum utils', () => {
describe('makeEnumParser', () => {
enum Color {
Red = 'red',
Green = 'green',
Blue = 'blue',
}
const parse = makeEnumParser(Color, Color.Blue);
it('returns a parser that returns the default value if passed a non-string', () => {
[undefined, null, 0, 1, 123].forEach(serializedValue => {
const result: Color = parse(serializedValue);
assert.strictEqual(result, Color.Blue);
});
});
it('returns a parser that returns the default value if passed a string not in the enum', () => {
['', 'garbage', 'RED'].forEach(serializedValue => {
const result: Color = parse(serializedValue);
assert.strictEqual(result, Color.Blue);
});
});
it('returns a parser that parses enum values', () => {
const result: Color = parse('green');
assert.strictEqual(result, Color.Green);
});
});
});