Skip to content
Open
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
6 changes: 6 additions & 0 deletions docs/syntax/substitutions.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ For variables declaring a semantic version or `Major.Minor` the following operat
| `M.x` | Display major component followed by '.x' |
| `M.M` | Display only the major and the minor |
| `M+1` | The next major version |
| `M-1` | The previous major version (returns original value if major is 0) |
| `M.M+1` | The next minor version |
| `M.M-1` | The previous minor version (returns original value if minor is 0) |

### Example

Expand Down Expand Up @@ -107,8 +109,10 @@ sub:
* M.M: {{version.stack | M.M }}
* M: {{version.stack | M }}
* M+1: {{version.stack | M+1 }}
* M-1: {{version.stack | M-1 }}
* M+1 | M.M: {{version.stack | M+1 | M.M }}
* M.M+1: {{version.stack | M.M+1 }}
* M.M-1: {{version.stack | M.M-1 }}

:::

Expand All @@ -128,8 +132,10 @@ sub:
* M.M: {{version.stack | M.M }}
* M: {{version.stack | M }}
* M+1: {{version.stack | M+1 }}
* M-1: {{version.stack | M-1 }}
* M+1 | M.M: {{version.stack | M+1 | M.M }}
* M.M+1: {{version.stack | M.M+1 }}
* M.M-1: {{version.stack | M.M-1 }}
````
:::

Expand Down
2 changes: 2 additions & 0 deletions docs/syntax/version-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ can be printed in any kind of ways.
| `{{version.stack| M.M}}` | {{version.stack|M.M}} |
| `{{version.stack.base | M }}` | {{version.stack.base | M }} |
| `{{version.stack | M+1 | M }}` | {{version.stack | M+1 | M }} |
| `{{version.stack | M-1 }}` | {{version.stack | M-1 }} |
| `{{version.stack.base | M.M+1 }}` | {{version.stack.base | M.M+1 }} |
| `{{version.stack | M.M-1 }}` | {{version.stack | M.M-1 }} |

## Mutation Operators in Links and Code Blocks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ private static string ApplySingleMutation(string value, SubstitutionMutation mut
SubstitutionMutation.MajorX => TryGetVersion(value, v => $"{v.Major}.x"),
SubstitutionMutation.MajorMinor => TryGetVersion(value, v => $"{v.Major}.{v.Minor}"),
SubstitutionMutation.IncreaseMajor => TryGetVersion(value, v => $"{v.Major + 1}.0.0"),
SubstitutionMutation.DecreaseMajor => TryGetVersion(value, v => v.Major == 0 ? value : $"{v.Major - 1}.0.0"),
SubstitutionMutation.IncreaseMinor => TryGetVersion(value, v => $"{v.Major}.{v.Minor + 1}.0"),
SubstitutionMutation.DecreaseMinor => TryGetVersion(value, v => v.Minor == 0 ? value : $"{v.Major}.{v.Minor - 1}.0"),
SubstitutionMutation.LowerCase => (true, value.ToLowerInvariant()),
SubstitutionMutation.UpperCase => (true, value.ToUpperInvariant()),
SubstitutionMutation.Capitalize => (true, Capitalize(value)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public enum SubstitutionMutation
[Display(Name = "M.x")] MajorX,
[Display(Name = "M.M")] MajorMinor,
[Display(Name = "M+1")] IncreaseMajor,
[Display(Name = "M-1")] DecreaseMajor,
[Display(Name = "M.M+1")] IncreaseMinor,
[Display(Name = "M.M-1")] DecreaseMinor,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well implement decreasemajor? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the use cases or benefits, but we can easily implement it, yeah. I'll add it to the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the PR. We'd return 8.0.0 now no matter what 9.x.x release we are currently in.
In the future, whenever we are on 10.x.x it would return 9.0.0.

If major is 0 (0.y.z) it would return the original value, same as with the M.M-1.

As soon as we decide what exactly to return in these corner cases I will adapt the PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye thats what i was thinking!

[Display(Name = "lc")] LowerCase,
[Display(Name = "uc")] UpperCase,
[Display(Name = "tc")] TitleCase,
Expand Down
70 changes: 69 additions & 1 deletion tests/Elastic.Markdown.Tests/Inline/SubstitutionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,12 @@ public class MutationOperatorTest(ITestOutputHelper output) : InlineTest(output,
Major.x with space: {{version | M.x}}
Increase major: {{version|M+1}}
Increase major with space: {{version | M+1}}
Decrease major: {{version|M-1}}
Decrease major with space: {{version | M-1}}
Increase minor: {{version|M.M+1}}
Increase minor with space: {{version | M.M+1}}
Decrease minor: {{version|M.M-1}}
Decrease minor with space: {{version | M.M-1}}
"""
)
{
Expand All @@ -240,8 +244,72 @@ public void MutationOperatorsWorkWithAndWithoutSpaces()
.And.Contain("Major.x with space: 9.x")
.And.Contain("Increase major: 10.0.0")
.And.Contain("Increase major with space: 10.0.0")
.And.Contain("Decrease major: 8.0.0")
.And.Contain("Decrease major with space: 8.0.0")
.And.Contain("Increase minor: 9.1.0")
.And.Contain("Increase minor with space: 9.1.0");
.And.Contain("Increase minor with space: 9.1.0")
.And.Contain("Decrease minor: 9.0.4")
.And.Contain("Decrease minor with space: 9.0.4");
}

[Fact]
public void HasNoErrors() => Collector.Diagnostics.Should().HaveCount(0);
}

public class DecreaseMinorMutationTest(ITestOutputHelper output) : InlineTest(output,
"""
---
sub:
version-with-minor: "9.2.3"
version-with-zero-minor: "9.0.4"
---

# Testing Decrease Minor Mutation

Version with minor greater than 0: {{version-with-minor|M.M-1}}
Version with minor greater than 0 and M.M: {{version-with-minor|M.M-1|M.M}}
Version with minor 0: {{version-with-zero-minor|M.M-1}}
"""
)
{
[Fact]
public void DecreaseMinorWorksCorrectly()
{
// When minor > 0, should decrease minor
Html.Should().Contain("Version with minor greater than 0: 9.1.0")
.And.Contain("Version with minor greater than 0 and M.M: 9.1")
// When minor = 0, should return original value
.And.Contain("Version with minor 0: 9.0.4");
}

[Fact]
public void HasNoErrors() => Collector.Diagnostics.Should().HaveCount(0);
}

public class DecreaseMajorMutationTest(ITestOutputHelper output) : InlineTest(output,
"""
---
sub:
version-with-major: "9.2.3"
version-with-zero-major: "0.5.2"
---

# Testing Decrease Major Mutation

Version with major greater than 0: {{version-with-major|M-1}}
Version with major greater than 0 and M.M: {{version-with-major|M-1|M.M}}
Version with major 0: {{version-with-zero-major|M-1}}
"""
)
{
[Fact]
public void DecreaseMajorWorksCorrectly()
{
// When major > 0, should decrease major and set minor/patch to 0
Html.Should().Contain("Version with major greater than 0: 8.0.0")
.And.Contain("Version with major greater than 0 and M.M: 8.0")
// When major = 0, should return original value
.And.Contain("Version with major 0: 0.5.2");
}

[Fact]
Expand Down
4 changes: 4 additions & 0 deletions tests/authoring/Inline/SubstitutionMutations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ sub:
* M.M: {{versions.stack | M.M }}
* M: {{versions.stack | M }}
* M+1: {{versions.stack | M+1 }}
* M-1: {{versions.stack | M-1 }}
* M+1 | M.M: {{versions.stack | M+1 | M.M }}
* M.M+1: {{versions.stack | M.M+1 }}
* M.M-1: {{versions.stack | M.M-1 }}
"""

[<Fact>]
Expand All @@ -46,7 +48,9 @@ sub:
<li>M.M: 9.1</li>
<li>M: 9</li>
<li>M+1: 10.0.0</li>
<li>M-1: 8.0.0</li>
<li>M+1 | M.M: 10.0</li>
<li>M.M+1: 9.2.0</li>
<li>M.M-1: 9.0.0</li>
</ul>
"""
Loading