feat: add string.test.ts (#2557)
* feat: add `string.test.ts` refactor: type improvement of variable `match` in file `src/api/transform/o1-format.ts` * feat: add more test with function `removeInvalidChars`
This commit is contained in:
1 parent
8cd50e7a31
commit
04e4f25865
2 files changed
+58
-1
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import { describe, it } from "mocha"
|
||||
import "should"
|
||||
import { fixModelHtmlEscaping, removeInvalidChars } from "./string"
|
||||
|
||||
describe("fixModelHtmlEscaping", () => {
|
||||
it("should convert > to >", () => {
|
||||
fixModelHtmlEscaping("foo > bar").should.equal("foo > bar")
|
||||
})
|
||||
|
||||
it("should convert < to <", () => {
|
||||
fixModelHtmlEscaping("foo < bar").should.equal("foo < bar")
|
||||
})
|
||||
|
||||
it('should convert " to "', () => {
|
||||
fixModelHtmlEscaping("foo "bar"").should.equal('foo "bar"')
|
||||
})
|
||||
|
||||
it("should convert & to &", () => {
|
||||
fixModelHtmlEscaping("foo & bar").should.equal("foo & bar")
|
||||
})
|
||||
|
||||
it("should convert ' to '", () => {
|
||||
fixModelHtmlEscaping("foo 'bar'").should.equal("foo 'bar'")
|
||||
})
|
||||
|
||||
it("should handle multiple entities in the same string", () => {
|
||||
fixModelHtmlEscaping("<div>Hello "World" & 'Universe'</div>").should.equal(
|
||||
"<div>Hello \"World\" & 'Universe'</div>",
|
||||
)
|
||||
})
|
||||
|
||||
it("should return unchanged string when no HTML entities are present", () => {
|
||||
fixModelHtmlEscaping("normal string").should.equal("normal string")
|
||||
})
|
||||
})
|
||||
|
||||
describe("removeInvalidChars", () => {
|
||||
it("should remove replacement characters", () => {
|
||||
removeInvalidChars("hello\uFFFDworld").should.equal("helloworld")
|
||||
})
|
||||
|
||||
it("should remove � characters", () => {
|
||||
removeInvalidChars("hello�world").should.equal("helloworld")
|
||||
})
|
||||
|
||||
it("should remove multiple replacement characters", () => {
|
||||
removeInvalidChars("h\uFFFDe\uFFFDl\uFFFDl\uFFFDo").should.equal("hello")
|
||||
})
|
||||
|
||||
it("should remove multiple � characters", () => {
|
||||
removeInvalidChars("h�e�l�lo").should.equal("hello")
|
||||
})
|
||||
|
||||
it("should return unchanged string when no replacement characters are present", () => {
|
||||
removeInvalidChars("normal string").should.equal("normal string")
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user