-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
384 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import dedent from './dedent'; | ||
|
||
describe('dedent', () => { | ||
it('should remove leading spaces from each line', () => { | ||
const input = ` | ||
line1 | ||
line2 | ||
line3 | ||
`; | ||
const expected = ` | ||
line1 | ||
line2 | ||
line3 | ||
`; | ||
expect(dedent(input)).toBe(expected); | ||
}); | ||
|
||
it('should handle tabs correctly', () => { | ||
const input = ` | ||
\t\tline1 | ||
\t\tline2 | ||
\t\tline3 | ||
\t\t`; | ||
const expected = ` | ||
line1 | ||
line2 | ||
line3 | ||
`; | ||
expect(dedent(input)).toBe(expected); | ||
}); | ||
|
||
it('should return the same string if no indentation is found', () => { | ||
const input = `line1\nline2\nline3`; | ||
expect(dedent(input)).toBe(input); | ||
}); | ||
|
||
it('should handle empty strings', () => { | ||
const input = ``; | ||
expect(dedent(input)).toBe(input); | ||
}); | ||
|
||
it('should handle strings with inconsistent indentation', () => { | ||
const input = ` | ||
line1 | ||
line2 | ||
line3 | ||
`; | ||
const expected = ` | ||
line1 | ||
line2 | ||
line3 | ||
`; | ||
expect(dedent(input)).toBe(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { groupBy } from './groupBy'; | ||
|
||
describe('groupBy', () => { | ||
it('should group items by a string key', () => { | ||
const items = [ | ||
{ category: 'fruit', name: 'apple' }, | ||
{ category: 'fruit', name: 'banana' }, | ||
{ category: 'vegetable', name: 'carrot' } | ||
]; | ||
const result = groupBy(items, item => item.category); | ||
expect(result).toEqual({ | ||
fruit: [ | ||
{ category: 'fruit', name: 'apple' }, | ||
{ category: 'fruit', name: 'banana' } | ||
], | ||
vegetable: [ | ||
{ category: 'vegetable', name: 'carrot' } | ||
] | ||
}); | ||
}); | ||
|
||
it('should group items by a numeric key', () => { | ||
const items = [1.1, 2.2, 1.3, 2.4]; | ||
const result = groupBy(items, item => Math.floor(item)); | ||
expect(result).toEqual({ | ||
1: [1.1, 1.3], | ||
2: [2.2, 2.4] | ||
}); | ||
}); | ||
|
||
it('should handle an empty array', () => { | ||
const items: any[] = []; | ||
const result = groupBy(items, item => item); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should handle grouping by index', () => { | ||
const items = ['a', 'b', 'c', 'd']; | ||
const result = groupBy(items, (item, index) => index % 2); | ||
expect(result).toEqual({ | ||
0: ['a', 'c'], | ||
1: ['b', 'd'] | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import camelCaseToSlug from './camelCaseToSlug'; | ||
|
||
describe('camelCaseToSlug', () => { | ||
it('should convert single camelCase word to slug', () => { | ||
expect(camelCaseToSlug('camelCase')).toBe('camel-case'); | ||
}); | ||
|
||
it('should convert multiple camelCase words to slug', () => { | ||
expect(camelCaseToSlug('thisIsATest')).toBe('this-is-a-test'); | ||
}); | ||
|
||
it('should handle strings with no camelCase', () => { | ||
expect(camelCaseToSlug('test')).toBe('test'); | ||
}); | ||
|
||
it('should handle empty strings', () => { | ||
expect(camelCaseToSlug('')).toBe(''); | ||
}); | ||
|
||
it('should handle strings with multiple uppercase letters', () => { | ||
expect(camelCaseToSlug('camelCaseToSlug')).toBe('camel-case-to-slug'); | ||
}); | ||
|
||
it('should handle strings with numbers', () => { | ||
expect(camelCaseToSlug('test123Case')).toBe('test123-case'); | ||
}); | ||
|
||
it('should handle strings with special characters by stripping them out', () => { | ||
expect(camelCaseToSlug('test!@#$%^&*()_+Case')).toBe('test-case'); | ||
}); | ||
|
||
it('should trim leading and trailing whitespace', () => { | ||
expect(camelCaseToSlug(' test ')).toBe('test'); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import camelCaseToTitle from './camelCaseToTitle'; | ||
|
||
describe('camelCaseToTitle', () => { | ||
it('should convert camelCase to Title Case', () => { | ||
expect(camelCaseToTitle('camelCaseString')).toBe('Camel Case String'); | ||
}); | ||
|
||
it('should handle single word', () => { | ||
expect(camelCaseToTitle('word')).toBe('Word'); | ||
}); | ||
|
||
it('should handle empty string', () => { | ||
expect(camelCaseToTitle('')).toBe(''); | ||
}); | ||
|
||
it('should handle multiple camelCase words', () => { | ||
expect(camelCaseToTitle('thisIsATestString')).toBe('This Is A Test String'); | ||
}); | ||
|
||
it('should handle strings with numbers', () => { | ||
expect(camelCaseToTitle('testString123')).toBe('Test String123'); | ||
}); | ||
|
||
// trim leading and trailing whitespace | ||
it('should trim leading and trailing whitespace', () => { | ||
expect(camelCaseToTitle(' test ')).toBe('Test'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import deSlugify from './deSlugify'; | ||
|
||
describe('deSlugify', () => { | ||
it('should replace hyphens with spaces', () => { | ||
expect(deSlugify('hello-world')).toBe('Hello World'); | ||
}); | ||
|
||
it('should convert to Title Case', () => { | ||
expect(deSlugify('hello-world')).toBe('Hello World'); | ||
}); | ||
|
||
it('should handle multiple hyphens', () => { | ||
expect(deSlugify('this-is-a-test')).toBe('This Is A Test'); | ||
}); | ||
|
||
it('should handle single word', () => { | ||
expect(deSlugify('test')).toBe('Test'); | ||
}); | ||
|
||
it('should handle empty string', () => { | ||
expect(deSlugify('')).toBe(''); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { describe, it, expect, vi, beforeEach, afterEach, } from 'vitest'; | ||
import debounce from './debounce'; | ||
|
||
describe('debounce', () => { | ||
beforeEach(() => { | ||
vi.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllTimers(); | ||
}); | ||
|
||
it('should call the function after the specified delay', () => { | ||
// Arrange | ||
const func = vi.fn(); | ||
const debouncedFunc = debounce(func, 200); | ||
|
||
// Act | ||
debouncedFunc(); | ||
|
||
// Assert | ||
expect(func).not.toHaveBeenCalled(); | ||
vi.advanceTimersByTime(200); | ||
expect(func).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not call the function if called again within the delay', () => { | ||
// Arrange | ||
const func = vi.fn(); | ||
const debouncedFunc = debounce(func, 200); | ||
|
||
// Act | ||
debouncedFunc(); | ||
debouncedFunc(); | ||
|
||
// Assert | ||
expect(func).not.toHaveBeenCalled(); | ||
vi.advanceTimersByTime(200); | ||
expect(func).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call the function with the correct arguments', () => { | ||
// Arrange | ||
const func = vi.fn(); | ||
const debouncedFunc = debounce(func, 200); | ||
|
||
// Act | ||
debouncedFunc('arg1', 'arg2'); | ||
|
||
// Assert | ||
vi.advanceTimersByTime(200); | ||
expect(func).toHaveBeenCalledWith('arg1', 'arg2'); | ||
}); | ||
|
||
it('should reset the delay if called again within the delay period', () => { | ||
// Arrange | ||
const func = vi.fn(); | ||
const debouncedFunc = debounce(func, 200); | ||
|
||
// Act | ||
debouncedFunc(); | ||
vi.advanceTimersByTime(100); | ||
debouncedFunc(); | ||
vi.advanceTimersByTime(100); | ||
|
||
// Assert | ||
expect(func).not.toHaveBeenCalled(); | ||
vi.advanceTimersByTime(100); | ||
expect(func).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.