mirror of
https://github.com/soconnor0919/beenpad.git
synced 2026-02-05 00:06:40 -05:00
first commit
This commit is contained in:
40
test/index.test.ts
Normal file
40
test/index.test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { beenpad } from '../src/index';
|
||||
|
||||
describe('beenpad', () => {
|
||||
it('should return original string if length is already sufficient', () => {
|
||||
expect(beenpad('foo', 3)).toBe('foo');
|
||||
expect(beenpad('foo', 2)).toBe('foo');
|
||||
});
|
||||
|
||||
it('should pad with "been" for standard cases', () => {
|
||||
expect(beenpad('foo', 7)).toBe('beenfoo');
|
||||
});
|
||||
|
||||
it('should pad with multiple "been"s', () => {
|
||||
expect(beenpad('foo', 11)).toBe('beenbeenfoo');
|
||||
});
|
||||
|
||||
it('should truncate "been" if needed', () => {
|
||||
expect(beenpad('foo', 4)).toBe('bfoo');
|
||||
expect(beenpad('foo', 5)).toBe('befoo');
|
||||
expect(beenpad('foo', 6)).toBe('beefoo');
|
||||
expect(beenpad('foo', 8)).toBe('beenbfoo');
|
||||
// padStart pads from the start.
|
||||
// "foo", 8 -> pad length 5.
|
||||
// "been" repeated is "beenbeen..."
|
||||
// "beenb" + "foo" = "beenbfoo".
|
||||
|
||||
// JS padStart:
|
||||
// 'foo'.padStart(8, 'been') -> "beenbfoo" ?
|
||||
// Let's verify standard behavior.
|
||||
// 'abc'.padStart(10, "foo") -> "foofoofabc"
|
||||
// So 'been' repeated is correct.
|
||||
expect(beenpad('foo', 8)).toBe('beenbfoo');
|
||||
});
|
||||
|
||||
it('should handle empty string', () => {
|
||||
expect(beenpad('', 4)).toBe('been');
|
||||
expect(beenpad('', 5)).toBe('beenb');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user