|
using System.Collections.Generic; |
|
using Xunit; |
|
|
|
namespace RegexTests |
|
{ |
|
public class TestCases |
|
{ |
|
[Theory] |
|
[MemberData(nameof(InputOutputData))] |
|
public void Solution0_Test(IReadOnlyDictionary<string, string> map, string input, string expected) |
|
{ |
|
var sut = new Solution0(); |
|
var result = sut.Substitute(input, map); |
|
Assert.Equal(expected, result); |
|
} |
|
|
|
[Theory] |
|
[MemberData(nameof(InputOutputData))] |
|
public void Solution1_Test(IReadOnlyDictionary<string, string> map, string input, string expected) |
|
{ |
|
var sut = new Solution1(); |
|
var result = sut.Substitute(input, map); |
|
Assert.Equal(expected, result); |
|
} |
|
|
|
[Theory] |
|
[MemberData(nameof(InputOutputData))] |
|
public void Solution2_Test(IReadOnlyDictionary<string, string> map, string input, string expected) |
|
{ |
|
var sut = new Solution2(map); |
|
var result = sut.Substitute(input); |
|
Assert.Equal(expected, result); |
|
} |
|
|
|
[Theory] |
|
[MemberData(nameof(InputOutputData))] |
|
public void Solution3_Test(IReadOnlyDictionary<string, string> map, string input, string expected) |
|
{ |
|
var sut = new Solution3(map); |
|
var result = sut.Substitute(input); |
|
Assert.Equal(expected, result); |
|
} |
|
|
|
[Theory] |
|
[MemberData(nameof(InputOutputData))] |
|
public void Solution4_Test(IReadOnlyDictionary<string, string> map, string input, string expected) |
|
{ |
|
var sut = new Solution4(map); |
|
var result = sut.Substitute(input); |
|
Assert.Equal(expected, result); |
|
} |
|
|
|
[Theory] |
|
[MemberData(nameof(InputOutputData))] |
|
public void Solution5_Test(IReadOnlyDictionary<string, string> map, string input, string expected) |
|
{ |
|
var sut = new Solution5(map); |
|
var result = sut.Substitute(input); |
|
Assert.Equal(expected, result); |
|
} |
|
|
|
[Theory] |
|
[MemberData(nameof(InputOutputData))] |
|
public void Solution6_Test(IReadOnlyDictionary<string, string> map, string input, string expected) |
|
{ |
|
var sut = new Solution6(map); |
|
var result = sut.Substitute(input); |
|
Assert.Equal(expected, result); |
|
} |
|
|
|
[Theory] |
|
[MemberData(nameof(InputOutputData))] |
|
public void Solution7_Test(IReadOnlyDictionary<string, string> map, string input, string expected) |
|
{ |
|
var sut = new Solution7(map); |
|
var result = sut.Substitute(input); |
|
Assert.Equal(expected, result); |
|
} |
|
|
|
[Theory] |
|
[MemberData(nameof(RecursiveInputOutputData))] |
|
public void Recursive0_Test(IReadOnlyDictionary<string, string> map, string input, string expected) |
|
{ |
|
var sut = new Recursive0(); |
|
var result = sut.Substitute(input, map); |
|
Assert.Equal(expected, result); |
|
} |
|
|
|
[Theory] |
|
[MemberData(nameof(RecursiveInputOutputData))] |
|
public void Recursive7_Test(IReadOnlyDictionary<string, string> map, string input, string expected) |
|
{ |
|
var sut = new Recursive7(map); |
|
var result = sut.Substitute(input); |
|
Assert.Equal(expected, result); |
|
} |
|
|
|
public static IEnumerable<object[]> Common() |
|
{ |
|
yield return new object[] { Map, string.Empty, string.Empty }; |
|
yield return new object[] { Map, "%final_result%", "%final_result%" }; |
|
yield return new object[] { Map, "[%%]", "[%%]" }; |
|
yield return new object[] { Map, "[%]", "[%]" }; |
|
yield return new object[] { Map, "[%", "[%" }; |
|
yield return new object[] { Map, "%]", "%]" }; |
|
yield return new object[] { Map, "[%%%]", "[%%%]" }; |
|
yield return new object[] { Map, "This is a false [%positive%].", "This is a false [%positive%]." }; |
|
yield return new object[] { Map, "This is a half [%po", "This is a half [%po" }; |
|
yield return new object[] { Map, "This is another half po%]", "This is another half po%]" }; |
|
yield return new object[] { Map, "This is a half [%po [%verynice%]", "This is a half [%po very nice" }; |
|
yield return new object[] { Map, "This is another half po%] [%verynice%]", "This is another half po%] very nice" }; |
|
yield return new object[] { Map, "This is a half [%verynice%] [%po", "This is a half very nice [%po" }; |
|
yield return new object[] { Map, "This is another half [%verynice%] po%]", "This is another half very nice po%]" }; |
|
yield return new object[] { Map, "This is a full [%po[%verynice%]po%]", "This is a full [%povery nicepo%]" }; |
|
yield return new object[] { Map, "This is an empty text", "This is an empty text" }; |
|
yield return new object[] { Map, "This is an [%this_is_my_super_template%] empty text", "This is an containing brackets and percent sign to encapsulate template data empty text" }; |
|
yield return new object[] { Map, "[%final_result%]b", "a final, longer textual result.b" }; |
|
yield return new object[] { Map, "a[%final_result%]", "aa final, longer textual result." }; |
|
yield return new object[] { Map, "a[%final_result%]b", "aa final, longer textual result.b" }; |
|
yield return new object[] { Map, "a[%final_0result%]b", "a[%final_0result%]b" }; |
|
yield return new object[] { Map, "a[%final result%]b", "a[%final result%]b" }; |
|
yield return new object[] { Map, "[%final_result%][%final_result%]", "a final, longer textual result.a final, longer textual result." }; |
|
yield return new object[] { Map, "[%final_result%]A[%final_result%]", "a final, longer textual result.Aa final, longer textual result." }; |
|
} |
|
|
|
public static IEnumerable<object[]> InputOutputData() |
|
{ |
|
foreach (var common in Common()) |
|
yield return common; |
|
yield return new object[] { Map, "With inner replacement [%replacement_text%]", "With inner replacement sample [%verynice%] message" }; |
|
yield return new object[] { Map, "With cycle [%cycle%]", "With cycle a[%cycle%]b" }; |
|
yield return new object[] { Map, "With cycle [%cycle_a%]", "With cycle a[%cycle_b%]b" }; |
|
} |
|
|
|
public static IEnumerable<object[]> RecursiveInputOutputData() |
|
{ |
|
foreach (var common in Common()) |
|
yield return common; |
|
yield return new object[] { Map, "With inner replacement [%replacement_text%]", "With inner replacement sample very nice message" }; |
|
yield return new object[] { Map, "With cycle [%cycle%]", "With cycle a[%cycle%]b" }; |
|
yield return new object[] { Map, "With cycle [%cycle_a%]", "With cycle aa[%cycle_a%]bb" }; |
|
yield return new object[] { Map, "With [%multiple%] in a row.", "With ba[%multiple_a%] and ab[%multiple_b%] in a row." }; |
|
} |
|
|
|
public static Dictionary<string, string> Map { get; } = new Dictionary<string, string>() { |
|
{ "[%this_is_my_super_template%]", "containing brackets and percent sign to encapsulate template data" }, |
|
{ "[%replacement_text%]", "sample [%verynice%] message" }, |
|
{ "[%final_result%]", "a final, longer textual result." }, |
|
{ "[%type_of_document%]","short text"}, |
|
{ "[%exec_order%]","from left to right"}, |
|
{ "[%user_do%]","can chain together successive"}, |
|
{ "[%verynice%]", "very nice" }, |
|
{ "[%cycle%]", "a[%cycle%]b" }, |
|
{ "[%cycle_a%]", "a[%cycle_b%]b" }, |
|
{ "[%cycle_b%]", "a[%cycle_a%]b" }, |
|
{ "[%multiple%]", "[%multiple_a%] and [%multiple_b%]" }, |
|
{ "[%multiple_a%]", "b[%multiple_b%]" }, |
|
{ "[%multiple_b%]", "a[%multiple_a%]" }, |
|
}; |
|
} |
|
} |