Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 58af023

Browse files
authored
Markdown: Fix UTF8 chars breaking elements (#366)
* failing test for splitSpaceLeft and splitSpaceRight * fix splitSpaceLeft and splitSpaceRight
1 parent 80c9bf8 commit 58af023

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

claat/parser/trim.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func splitSpaceLeft(s string) (v string, sp string) {
161161
return s[i:], s[:i]
162162
}
163163
}
164-
return s, ""
164+
return "", s
165165
}
166166

167167
func splitSpaceRight(s string) (v string, sp string) {
@@ -171,7 +171,7 @@ func splitSpaceRight(s string) (v string, sp string) {
171171
return string(rs[:i+1]), string(rs[i+1:])
172172
}
173173
}
174-
return string(rs), ""
174+
return "", string(rs)
175175
}
176176

177177
func requiresSpacer(a, b types.Node) bool {

claat/parser/trim_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package parser
2+
3+
import "testing"
4+
5+
type testCase struct {
6+
s string
7+
v string
8+
sp string
9+
}
10+
11+
func TestSplitSpaceLeft(t *testing.T) {
12+
testCases := []testCase{
13+
{"basic test case", "basic test case", ""},
14+
{" some space ", "some space ", " "},
15+
{"\t\n\rsome less common spaces", "some less common spaces", "\t\n\r"},
16+
{" 🙂 a smiley space ", "🙂 a smiley space ", " "},
17+
{" ", "", " "},
18+
{"", "", ""},
19+
{" x", "x", " "},
20+
}
21+
22+
for _, tc := range testCases {
23+
v, sp := splitSpaceLeft(tc.s)
24+
if v != tc.v {
25+
t.Errorf("v=%#v, expected %#v, (s=%#v)", v, tc.v, tc.s)
26+
}
27+
if sp != tc.sp {
28+
t.Errorf("sp=%#v, expected %#v, (s=%#v)", sp, tc.sp, tc.s)
29+
}
30+
}
31+
}
32+
33+
func TestSplitSpaceRight(t *testing.T) {
34+
testCases := []testCase{
35+
{"basic test case", "basic test case", ""},
36+
{" some space ", " some space", " "},
37+
{"some less common spaces\t\n\r", "some less common spaces", "\t\n\r"},
38+
{" 🙂 a smiley space ", " 🙂 a smiley space", " "},
39+
{" ", "", " "},
40+
{"", "", ""},
41+
{"x ", "x", " "},
42+
}
43+
44+
for _, tc := range testCases {
45+
v, sp := splitSpaceRight(tc.s)
46+
if v != tc.v {
47+
t.Errorf("v=%#v, expected %#v, (s=%#v)", v, tc.v, tc.s)
48+
}
49+
if sp != tc.sp {
50+
t.Errorf("sp=%#v, expected %#v, (s=%#v)", sp, tc.sp, tc.s)
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)