1
1
mirror of https://github.com/walles/moar.git synced 2024-11-27 01:05:23 +03:00

Fix a heading identification bug

This commit is contained in:
Johan Walles 2024-01-10 16:22:08 +01:00
parent 3b16284ed9
commit 4ccc36732d
2 changed files with 21 additions and 1 deletions

View File

@ -62,7 +62,7 @@ func isManPageHeading(s string) bool {
}
}
return true
return nextCharNumber%3 == 0
}
// Alphabetic chars must be upper case, all others are fine.

View File

@ -0,0 +1,20 @@
package textstyles
import (
"testing"
"gotest.tools/v3/assert"
)
func TestIsManPageHeading(t *testing.T) {
assert.Assert(t, !isManPageHeading(""))
assert.Assert(t, !isManPageHeading("A"), "Incomplete sequence")
assert.Assert(t, !isManPageHeading("A\b"), "Incomplete sequence")
assert.Assert(t, isManPageHeading("A\bA"))
assert.Assert(t, !isManPageHeading("A\bC"), "Different first and last char")
assert.Assert(t, !isManPageHeading("a\ba"), "Not ALL CAPS")
assert.Assert(t, !isManPageHeading("A\bAX"), "Incomplete sequence")
}