add tests for new functions

This commit is contained in:
Chris Kruining 2025-02-11 17:09:09 +11:00
parent f444a9a17d
commit ac266bbc2f
No known key found for this signature in database
GPG key ID: EB894A3560CCCAD2

View file

@ -1,5 +1,5 @@
import { describe, beforeEach, it, expect, afterAll, spyOn } from 'bun:test';
import { decode, deepCopy, deepDiff, filter, map, MutarionKind, splitAt } from './utilities';
import { decode, deepCopy, deepDiff, filter, gen__split_by_filter, map, MutarionKind, split_by_filter, splitAt } from './utilities';
import { install } from '@sinonjs/fake-timers';
type MilliSeconds = number;
@ -72,6 +72,44 @@ describe('utilities', () => {
});
});
describe('gen__split_by_filter', () => {
it('should split the given string at the given filter', async () => {
// Arrange
const given = 'this is some string in which the word filter splits it';
const filter = 'some';
const expected: (readonly [boolean, string])[] = [
[false, 'this is '],
[true, 'some'],
[false, ' string in which the word filter splits it'],
] as const;
// Act
const actual = Array.from<readonly [boolean, string]>(gen__split_by_filter(given, filter));
// Assert
expect(actual).toEqual(expected);
});
});
describe('split_by_filter', () => {
it('should split the given string at the given filter', async () => {
// Arrange
const given = 'this is some string in which the word filter splits it';
const filter = 'some';
const expected: (readonly [boolean, string])[] = [
[false, 'this is '],
[true, 'some'],
[false, ' string in which the word filter splits it'],
] as const;
// Act
const actual = split_by_filter(given, filter);
// Assert
expect(actual).toEqual(expected);
});
});
describe('decode', () => {
it('should decode \\t characters', async () => {
// Arrange
@ -383,6 +421,30 @@ describe('utilities', () => {
{ kind: MutarionKind.Update, key: 'key.key', original: 'old', value: 'new' },
]);
});
it('should handle `null` values', async () => {
// arrange
const a = { key: null };
const b = { key: null };
// Act
const actual = deepDiff(a, b).toArray();
// Arrange
expect(actual).toEqual([]);
});
it('should handle `undefined` values', async () => {
// arrange
const a = { key: undefined };
const b = { key: undefined };
// Act
const actual = deepDiff(a, b).toArray();
// Arrange
expect(actual).toEqual([]);
});
});
describe('filter', () => {