From 93c0b3bf293d2fc8009077f1045c16f2ff8b1623 Mon Sep 17 00:00:00 2001 From: AB1908 <14124383+AB1908@users.noreply.github.com> Date: Thu, 21 Jul 2022 15:49:07 +0530 Subject: [PATCH] Add a few basic util tests --- src/tests/utils.test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/tests/utils.test.ts diff --git a/src/tests/utils.test.ts b/src/tests/utils.test.ts new file mode 100644 index 0000000..ce7a247 --- /dev/null +++ b/src/tests/utils.test.ts @@ -0,0 +1,24 @@ +import { wrapAround, containsOnlyLettersAndUnderscores, replaceIllegalFileNameCharactersInString} from '../utils/Utils'; + +test('If wrapAround wraps correctly', () => { + expect(wrapAround(100,5)).toBe(0); + expect(wrapAround(100,7)).toBe(2); +}); + +test('If wrapAround errors out when dividing by zero', () => { + expect(wrapAround(100,0)).toThrow(); +}); + +test('Letter and underscore string validity', () => { + expect(containsOnlyLettersAndUnderscores("asdkfj_")).toBe(true); + expect(containsOnlyLettersAndUnderscores("asdkfj0")).toBe(false); +}); + +test('Letter and underscore unicode char test', () =>{ + expect(containsOnlyLettersAndUnderscores("asdkaÈj")).toBe(true); + expect(containsOnlyLettersAndUnderscores("asdkaÈj0")).toBe(false); +}); + +test('Valid filename test', ()=>{ + expect(replaceIllegalFileNameCharactersInString("what?is\\this:")).toBe("whatisthis -"); +}) \ No newline at end of file