Skip to content

Commit

Permalink
bug: Use * as part of a label string
Browse files Browse the repository at this point in the history
Fixes #61
  • Loading branch information
Kieranties authored Apr 29, 2019
2 parents 4b591ea + 1c6a52a commit 9daa404
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/SimpleVersion.Core/Rules/HeightRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public IEnumerable<string> Apply(VersionContext context, IEnumerable<string> inp
{
if (!context.Configuration.Version.Contains(Token)
&& input.Count() != 0
&& !input.Contains(Token))
&& !input.Any(x => x.Contains(Token)))
{
return input.Concat(new[] { Token });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public static IEnumerable<object[]> LabelParts()
yield return new object[] { new[] { "one", "two" }, "1.2.0", 106, "1.2.0-one-two-0106" };
yield return new object[] { new[] { "*", "one", "two" }, "1.2.0", 106, "1.2.0-0106-one-two" };
yield return new object[] { new[] { "one", "*", "two" }, "1.2.0", 106, "1.2.0-one-0106-two" };
yield return new object[] { new[] { "one", "two*", "three" }, "1.2.0", 106, "1.2.0-one-two0106-three" };
yield return new object[] { new[] { "one", "*two*", "three" }, "1.2.0", 106, "1.2.0-one-0106two0106-three" };
yield return new object[] { new[] { "one", "*t*o*", "three" }, "1.2.0", 106, "1.2.0-one-0106t0106o0106-three" };
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ public Semver2FormatProcessFixture()

public static IEnumerable<object[]> LabelParts()
{
return new List<object[]>
{
new object[] { Array.Empty<object>(), "1.2.0", 10 },
new object[] { new[] { "one" }, "1.2.0", 10 },
new object[] { new[] { "one", "two" }, "1.2.0", 106 }
};
yield return new object[] { Array.Empty<object>(), "1.2.0", 10, "1.2.0" };
yield return new object[] { new[] { "one" }, "1.2.0", 10, "1.2.0-one.10" };
yield return new object[] { new[] { "one", "two" }, "1.2.0", 106, "1.2.0-one.two.106" };
yield return new object[] { new[] { "*", "one", "two" }, "1.2.0", 106, "1.2.0-106.one.two" };
yield return new object[] { new[] { "one", "*", "two" }, "1.2.0", 106, "1.2.0-one.106.two" };
yield return new object[] { new[] { "one", "two*", "three" }, "1.2.0", 106, "1.2.0-one.two106.three" };
yield return new object[] { new[] { "one", "*two*", "three" }, "1.2.0", 106, "1.2.0-one.106two106.three" };
yield return new object[] { new[] { "one", "*t*o*", "three" }, "1.2.0", 106, "1.2.0-one.106t106o106.three" };
}

[Theory]
[MemberData(nameof(LabelParts))]
public void Apply_LabelParts_NonRelease_Is_Formatted(
string[] parts,
string version,
int height)
int height,
string expectedPart)
{
// Arrange
var context = new VersionContext
Expand All @@ -41,18 +44,16 @@ public void Apply_LabelParts_NonRelease_Is_Formatted(
};
context.Result.Version = context.Configuration.Version;

string expected;
if (parts.Length > 0)
expected = $"{version}-{string.Join(".", parts)}.{height}.c4ca82d2";
else
expected = $"{version}-c4ca82d2";
var divider = parts.Length > 0 ? '.' : '-';
var shaSub = context.Result.Sha.Substring(0, 7);
var fullExpected = $"{expectedPart}{divider}c{shaSub}";

// Act
_sut.Apply(context);

// Assert
context.Result.Formats.Should().ContainKey("Semver2");
context.Result.Formats["Semver2"].Should().Be(expected);
context.Result.Formats["Semver2"].Should().Be(fullExpected);
}


Expand All @@ -61,7 +62,8 @@ public void Apply_LabelParts_NonRelease_Is_Formatted(
public void Apply_LabelParts_Release_Is_Formatted(
string[] parts,
string version,
int height)
int height,
string expected)
{
// Arrange
var context = new VersionContext
Expand All @@ -70,13 +72,7 @@ public void Apply_LabelParts_Release_Is_Formatted(
Result = Utils.GetVersionResult(height)
};
context.Result.Version = context.Configuration.Version;

string expected;
if (parts.Length > 0)
expected = $"{version}-{string.Join(".", parts)}.{height}";
else
expected = $"{version}";


// Act
_sut.Apply(context);

Expand Down Expand Up @@ -106,12 +102,13 @@ public void Apply_MetaDataParts_NonRelease_Is_Formatted(
Result = Utils.GetVersionResult(height, false)
};
context.Result.Version = context.Configuration.Version;

var shaSub = context.Result.Sha.Substring(0, 7);

string expected;
if (parts.Length > 0)
expected = $"{version}-c4ca82d2+{string.Join(".", parts)}";
expected = $"{version}-c{shaSub}+{string.Join(".", parts)}";
else
expected = $"{version}-c4ca82d2";
expected = $"{version}-c{shaSub}";

// Act
_sut.Apply(context);
Expand Down

0 comments on commit 9daa404

Please sign in to comment.