Skip to content

Commit 8359b7d

Browse files
committed
modified: webview-ui/src/components/common/CodeAccordian.tsx
new file: webview-ui/src/components/common/__tests__/CodeAccordian.test.tsx
1 parent c6c70c2 commit 8359b7d

File tree

2 files changed

+120
-1
lines changed

2 files changed

+120
-1
lines changed

webview-ui/src/components/common/CodeAccordian.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ We need to remove leading non-alphanumeric characters from the path in order for
2020
[^a-zA-Z0-9]+: Matches one or more characters that are not alphanumeric.
2121
The replace method removes these matched characters, effectively trimming the string up to the first alphanumeric character.
2222
*/
23-
export const removeLeadingNonAlphanumeric = (path: string): string => path.replace(/^[^a-zA-Z0-9]+/, "")
23+
export const removeLeadingNonAlphanumeric = (path: string): string => path.replace(/^[^\u4e00-\u9fa5a-zA-Z0-9]+/, "")
2424

2525
const CodeAccordian = ({
2626
code,
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import { removeLeadingNonAlphanumeric } from "../CodeAccordian"
2+
3+
describe("removeLeadingNonAlphanumeric", () => {
4+
it("should return the original string if it's empty", () => {
5+
// Arrange
6+
const input = ""
7+
8+
// Act
9+
const result = removeLeadingNonAlphanumeric(input)
10+
11+
// Assert
12+
expect(result).toBe("")
13+
})
14+
15+
it("should return the original string if it starts with an alphanumeric character", () => {
16+
// Arrange
17+
const input = "abc"
18+
19+
// Act
20+
const result = removeLeadingNonAlphanumeric(input)
21+
22+
// Assert
23+
expect(result).toBe("abc")
24+
})
25+
26+
it("should return the original string if it starts with a Unicode character", () => {
27+
// Arrange
28+
const input = "你好world"
29+
30+
// Act
31+
const result = removeLeadingNonAlphanumeric(input)
32+
33+
// Assert
34+
expect(result).toBe("你好world")
35+
})
36+
37+
it("should remove all leading non-alphanumeric characters", () => {
38+
// Arrange
39+
const input = "~!@#$abc"
40+
41+
// Act
42+
const result = removeLeadingNonAlphanumeric(input)
43+
44+
// Assert
45+
expect(result).toBe("abc")
46+
})
47+
48+
it("should handle a string with only non-alphanumeric characters", () => {
49+
// Arrange
50+
const input = "~!@#$"
51+
52+
// Act
53+
const result = removeLeadingNonAlphanumeric(input)
54+
55+
// Assert
56+
expect(result).toBe("")
57+
})
58+
59+
it("should handle a long string with leading non-alphanumeric characters", () => {
60+
// Arrange
61+
const input = "~!@#$%^&*()_+=-`abcde12345"
62+
63+
// Act
64+
const result = removeLeadingNonAlphanumeric(input)
65+
66+
// Assert
67+
expect(result).toBe("abcde12345")
68+
})
69+
70+
it("should handle a string with only Unicode characters", () => {
71+
// Arrange
72+
const input = "你好"
73+
74+
// Act
75+
const result = removeLeadingNonAlphanumeric(input)
76+
77+
// Assert
78+
expect(result).toBe("你好")
79+
})
80+
81+
it("should handle a string with Unicode and alphanumeric characters", () => {
82+
// Arrange
83+
const input = "你好abc"
84+
85+
// Act
86+
const result = removeLeadingNonAlphanumeric(input)
87+
88+
// Assert
89+
expect(result).toBe("你好abc")
90+
})
91+
92+
it("should handle a string with Unicode and special characters", () => {
93+
// Arrange
94+
const input = "~!@#你好"
95+
96+
// Act
97+
const result = removeLeadingNonAlphanumeric(input)
98+
99+
// Assert
100+
expect(result).toBe("你好")
101+
})
102+
103+
it("should handle a string with mixed Unicode, alphanumeric, and special characters", () => {
104+
// Arrange
105+
const input = "~!@#你好abc"
106+
107+
// Act
108+
const result = removeLeadingNonAlphanumeric(input)
109+
110+
// Assert
111+
expect(result).toBe("你好abc")
112+
})
113+
114+
it("should not modify a string that already starts with an alphanumeric character after special characters", () => {
115+
const input = "你好123"
116+
const result = removeLeadingNonAlphanumeric(input)
117+
expect(result).toBe("你好123")
118+
})
119+
})

0 commit comments

Comments
 (0)