From ac266bbc2f90ae94a9382298a8e2f92bfbfb0901 Mon Sep 17 00:00:00 2001 From: Chris Kruining Date: Tue, 11 Feb 2025 17:09:09 +1100 Subject: [PATCH] add tests for new functions --- src/utilities.spec.ts | 64 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/utilities.spec.ts b/src/utilities.spec.ts index 018c15e..622180b 100644 --- a/src/utilities.spec.ts +++ b/src/utilities.spec.ts @@ -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(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', () => {