-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove excessive whitespace before sending to ai
- Loading branch information
Showing
8 changed files
with
107 additions
and
9 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
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,66 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { removeExcessiveWhitespace, truncate } from "./string"; | ||
|
||
// Run with: | ||
// pnpm test utils/string.test.ts | ||
|
||
describe("string utils", () => { | ||
describe("truncate", () => { | ||
it("should truncate strings longer than specified length", () => { | ||
expect(truncate("hello world", 5)).toBe("hello..."); | ||
}); | ||
|
||
it("should not truncate strings shorter than specified length", () => { | ||
expect(truncate("hello", 10)).toBe("hello"); | ||
}); | ||
}); | ||
|
||
describe("removeExcessiveWhitespace", () => { | ||
it("should collapse multiple spaces into single space", () => { | ||
expect(removeExcessiveWhitespace("hello world")).toBe("hello world"); | ||
}); | ||
|
||
it("should preserve single newlines", () => { | ||
expect(removeExcessiveWhitespace("hello\nworld")).toBe("hello\nworld"); | ||
}); | ||
|
||
it("should collapse multiple newlines into double newlines", () => { | ||
expect(removeExcessiveWhitespace("hello\n\n\n\nworld")).toBe( | ||
"hello\n\nworld", | ||
); | ||
}); | ||
|
||
it("should remove zero-width spaces", () => { | ||
expect(removeExcessiveWhitespace("hello\u200Bworld")).toBe("hello world"); | ||
}); | ||
|
||
it("should handle complex cases with multiple types of whitespace", () => { | ||
const input = "hello world\n\n\n\n next line\u200B\u200B test"; | ||
expect(removeExcessiveWhitespace(input)).toBe( | ||
"hello world\n\nnext line test", | ||
); | ||
}); | ||
|
||
it("should trim leading and trailing whitespace", () => { | ||
expect(removeExcessiveWhitespace(" hello world ")).toBe("hello world"); | ||
}); | ||
|
||
it("should handle empty string", () => { | ||
expect(removeExcessiveWhitespace("")).toBe(""); | ||
}); | ||
|
||
it("should handle string with only whitespace", () => { | ||
expect(removeExcessiveWhitespace(" \n\n \u200B ")).toBe(""); | ||
}); | ||
|
||
it("should handle soft hyphens and other special characters", () => { | ||
const input = "hello\u00ADworld\u034Ftest\u200B\u200Cspace"; | ||
expect(removeExcessiveWhitespace(input)).toBe("hello world test space"); | ||
}); | ||
|
||
it("should handle mixed special characters and whitespace", () => { | ||
const input = "hello\u00AD world\n\n\u034F\n\u200B test"; | ||
expect(removeExcessiveWhitespace(input)).toBe("hello world\n\ntest"); | ||
}); | ||
}); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.