mirror of
https://github.com/sbrow/strings.git
synced 2025-12-29 23:17:39 -05:00
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import fc from "fast-check";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { wordCount, words } from "./words";
|
|
import { complement, isEmpty } from "ramda";
|
|
|
|
describe("words", () => {
|
|
describe("words", () => {
|
|
it("returns '[]' for empty strings", () => {
|
|
expect(words("")).toEqual([]);
|
|
});
|
|
it("returns '[]' for strings with only whitespace characters", () => {
|
|
expect(words(" ")).toEqual([]);
|
|
expect(words(" ")).toEqual([]);
|
|
expect(words(" \r ")).toEqual([]);
|
|
expect(words("\n ")).toEqual([]);
|
|
});
|
|
it('passes', () => {
|
|
fc.assert(
|
|
fc.property(fc.string(), (str) => {
|
|
if (str === '' || str.trim() === '') {
|
|
expect(words(str).length).toEqual(0)
|
|
} else {
|
|
expect(words(str).length).toEqual(str.split(/\s+/).filter(complement(isEmpty)).length)
|
|
}
|
|
})
|
|
);
|
|
})
|
|
});
|
|
describe("wordCount", () => {
|
|
it("matches the length of the output from words", () => {
|
|
fc.assert(
|
|
fc.property(fc.string(), (str) => {
|
|
expect(wordCount(str)).toBe(words(str).length);
|
|
})
|
|
);
|
|
});
|
|
});
|
|
});
|