mirror of
https://github.com/sbrow/strings.git
synced 2025-12-29 23:17:39 -05:00
feat: First commit.
This commit is contained in:
55
src/index.spec.ts
Normal file
55
src/index.spec.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import fc from 'fast-check';
|
||||
import {
|
||||
afterFirstWord, beforeFirstWord, endsWith, ltrim, startsWith,
|
||||
} from './index';
|
||||
|
||||
describe('strings', () => {
|
||||
// describe('afterFirstWord', () => {
|
||||
// it('removes the first word', () => {
|
||||
// fc.assert(fc.property(fc.string(), (str) => {
|
||||
// const got = afterFirstWord(str);
|
||||
|
||||
// if (got !== '') {
|
||||
// expect(endsWith(got, str)).toBe(true);
|
||||
// if (str.indexOf(' ') !== -1) {
|
||||
// expect(`${beforeFirstWord(str)} ${got}`).toBe(str);
|
||||
// }
|
||||
// }
|
||||
// }));
|
||||
// });
|
||||
// });
|
||||
describe('ltrim', () => {
|
||||
it('returns input when cutset is empty', () => {
|
||||
expect(ltrim('', 'foo')).toBe('foo');
|
||||
});
|
||||
it('returns empty when input is empty', () => {
|
||||
expect(ltrim('foo', '')).toBe('');
|
||||
});
|
||||
it('can be curried', () => {
|
||||
expect(ltrim('foo', '')).toBe(ltrim('foo')(''));
|
||||
expect(ltrim(' ', 'foo')).toBe(ltrim(' ')('foo'));
|
||||
});
|
||||
it('trims cutset', () => {
|
||||
fc.assert(fc.property(fc.string(), fc.string(), (cutset, str) => {
|
||||
const got = ltrim(cutset, str);
|
||||
|
||||
if (cutset === '') {
|
||||
expect(got).toBe(str);
|
||||
} else if (str === '') {
|
||||
expect(got).toBe('');
|
||||
} else {
|
||||
if (got === '') {
|
||||
for (const char of str) {
|
||||
expect(cutset).contains(char);
|
||||
}
|
||||
}
|
||||
|
||||
for (const char of cutset) {
|
||||
expect(startsWith(char, got)).toBe(false);
|
||||
}
|
||||
}
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user