Repository: ogen-go/ogen
Pull request #196 (2022-02-15 19:03:20)

fix(ir): cut doc lines correctly

codecov[bot]: # [Codecov](https://codecov.io/gh/ogen-go/ogen/pull/196?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) Report
> Merging [#196](https://codecov.io/gh/ogen-go/ogen/pull/196?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) (5168730) into [main](https://codecov.io/gh/ogen-go/ogen/commit/7bf98f6cfa041ac7ced38f5d4f2875b1b8c8e0db?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) (7bf98f6) will **decrease** coverage by `0.06%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/ogen-go/ogen/pull/196/graphs/tree.svg?width=650&height=150&src=pr&token=ZH7F81JBY7&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go)](https://codecov.io/gh/ogen-go/ogen/pull/196?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go)

```diff
@@            Coverage Diff             @@
##             main     #196      +/-   ##
==========================================
- Coverage   66.90%   66.83%   -0.07%     
==========================================
  Files         100      100              
  Lines        6426     6422       -4     
==========================================
- Hits         4299     4292       -7     
- Misses       1854     1856       +2     
- Partials      273      274       +1     
```


| [Impacted Files](https://codecov.io/gh/ogen-go/ogen/pull/196?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go) | Coverage Δ | |
|---|---|---|
| [internal/ir/description.go](https://codecov.io/gh/ogen-go/ogen/pull/196/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-aW50ZXJuYWwvaXIvZGVzY3JpcHRpb24uZ28=) | `100.00% <100.00%> (ø)` | |
| [gen/reduce.go](https://codecov.io/gh/ogen-go/ogen/pull/196/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go#diff-Z2VuL3JlZHVjZS5nbw==) | `65.71% <0.00%> (-8.58%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ogen-go/ogen/pull/196?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/ogen-go/ogen/pull/196?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go). Last update [7bf98f6...5168730](https://codecov.io/gh/ogen-go/ogen/pull/196?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ogen-go).


Patch:
diff --git a/internal/ir/description.go b/internal/ir/description.go
index 3fd47988..5eff7a73 100644
--- a/internal/ir/description.go
+++ b/internal/ir/description.go
@@ -21,29 +21,29 @@ func splitLine(s string, limit int) (r []string) {
 		}
 
 		idx := strings.LastIndexFunc(s[:limit-1], func(r rune) bool {
-			return unicode.IsSpace(r) || r == '.' || r == ','
+			return unicode.IsSpace(r) || r == '.' || r == ',' || r == ';'
 		})
 		if idx < 0 || len(s)-1 == idx {
 			r = append(r, s)
 			return
 		}
 
-		if ch, _ := utf8.DecodeRuneInString(s[idx:]); unicode.IsSpace(ch) {
+		if ch, size := utf8.DecodeRuneInString(s[idx:]); unicode.IsSpace(ch) {
 			r = append(r, s[:idx])
-			s = s[idx+1:]
+			s = s[idx+size:]
 		} else {
-			// Do not cut dots.
-			r = append(r, s[:idx+1])
-			s = s[idx+1:]
+			// Do not cut dots and commas.
+			r = append(r, s[:idx+size])
+			s = s[idx+size:]
 		}
 	}
 }
 
-func prettyDoc(s string) (r []string) {
-	const (
-		lineLimit = 100
-	)
+const (
+	lineLimit = 100
+)
 
+func prettyDoc(s string) (r []string) {
 	// TODO(tdakkota): basic common mark rendering?
 	for _, line := range strings.Split(s, "\n") {
 		r = append(r, splitLine(line, lineLimit)...)


Test patch:
diff --git a/internal/ir/description_test.go b/internal/ir/description_test.go
index 940c87ff..67d5ca52 100644
--- a/internal/ir/description_test.go
+++ b/internal/ir/description_test.go
@@ -2,9 +2,12 @@ package ir
 
 import (
 	"fmt"
+	"strings"
 	"testing"
 
 	"github.com/stretchr/testify/require"
+
+	"github.com/ogen-go/ogen/internal/capitalize"
 )
 
 func Test_prettyDoc(t *testing.T) {
@@ -53,6 +56,13 @@ func Test_prettyDoc(t *testing.T) {
 				"rate limits](https://docs.github.", "com/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits)\"for details.",
 			},
 		},
+		{
+			input: strings.Repeat("a", lineLimit-4) + string(rune(12288)) + strings.Repeat("a", 10),
+			wantR: []string{
+				capitalize.Capitalize(strings.Repeat("a", lineLimit-4)),
+				strings.Repeat("a", 10) + ".",
+			},
+		},
 	}
 	for i, tt := range tests {
 		tt := tt