private static void Test_Matched(string str, string format, params NameValue[] expectedPairs) { var result = new FormattedStringValueExtracter().Extract(str, format); result.IsMatch.ShouldBe(true); if (expectedPairs == null) { result.Matches.Count.ShouldBe(0); return; } result.Matches.Count.ShouldBe(expectedPairs.Length); for (int i = 0; i < expectedPairs.Length; i++) { var actualMatch = result.Matches[i]; var expectedPair = expectedPairs[i]; actualMatch.Name.ShouldBe(expectedPair.Name); actualMatch.Value.ShouldBe(expectedPair.Value); } }
/// <summary> /// Checks if given <see cref="str"/> fits to given <see cref="format"/>. /// Also gets extracted values. /// </summary> /// <param name="str">String including dynamic values</param> /// <param name="format">Format of the string</param> /// <param name="values">Array of extracted values if matched</param> /// <param name="ignoreCase">True, to search case-insensitive</param> /// <returns>True, if matched.</returns> public static bool IsMatch(string str, string format, out string[] values, bool ignoreCase = false) { var result = new FormattedStringValueExtracter().Extract(str, format, ignoreCase); if (!result.IsMatch) { values = new string[0]; return false; } values = result.Matches.Select(m => m.Value).ToArray(); return true; }
private void Test_Not_Matched(string str, string format) { var result = new FormattedStringValueExtracter().Extract(str, format); result.IsMatch.ShouldBe(false); }