Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for en ("–") and em dashes ("—") as separator between version and date #140

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- The en ("–") and em dashes ("") are also supported as separator between version and date

### Changed

- Renamed rule `entry-for-every-versions` to `all-h2-contain-a-version`
Expand Down
4 changes: 3 additions & 1 deletion heylogs-api/src/main/java/nbbrd/heylogs/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ private static String parseRef(Node firstPart) throws IllegalArgumentException {
private static LocalDate parseDate(Node secondPart) throws IllegalArgumentException {
BasedSequence date = secondPart.getChars();

if (!date.trimStart().startsWith("-")) {
BasedSequence trimmedStart = date.trimStart();
// The unicode en dash ("–") and em dash ("—") are also accepted as separators
if (!trimmedStart.startsWith("-") && !trimmedStart.startsWith("–") && !trimmedStart.startsWith("—")) {
throw new IllegalArgumentException("Missing date prefix");
}

Expand Down
8 changes: 8 additions & 0 deletions heylogs-api/src/test/java/nbbrd/heylogs/VersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public void testParse() {
assertThat(parse(asHeading("## [1.1.0] - 2019-02-15")))
.isEqualTo(Version.of("1.1.0", d20190215));

// Unicode en dash as separator
assertThat(parse(asHeading("## [1.1.0] – 2019-02-15")))
.isEqualTo(Version.of("1.1.0", d20190215));

// Unicode em dash as separator
assertThat(parse(asHeading("## [1.1.0] — 2019-02-15")))
.isEqualTo(Version.of("1.1.0", d20190215));

assertThatIllegalArgumentException()
.isThrownBy(() -> parse(asHeading("# [1.1.0] - 2019-02-15")))
.withMessageContaining("Invalid heading level");
Expand Down