[TestCase(@"^.{5,}:,$")] // dot, colon, comma public void UnEscape_Escaped_Special_Characters(string pattern) { var resultBuffer = new Span <char>(new char[pattern.Length]); var optionsEscaped = new string(EscapedLiteral.EscapeCharLiterals('\\', pattern, 0, pattern.Length, true).ToArray()); Assert.That(EscapedLiteral.UnEscapeCharLiterals('\\', optionsEscaped.AsSpan(0, optionsEscaped.Length), true, resultBuffer).ToString(), Is.EqualTo(pattern)); }
public void UnEscape_With_StartIndex_not_zero() { var full = "abc(de"; var startIndex = 3; var resultBuffer = new Span <char>(new char[full.Length]); Assert.That("(de", Is.EqualTo(EscapedLiteral.UnEscapeCharLiterals('\\', full.AsSpan(startIndex, full.Length - startIndex), true, resultBuffer).ToString())); }
[TestCase('9', '\0')] // not included in look-up table public void TryGetChar_FormatterOption_Test(char testChar, char testCharResult) { var found = EscapedLiteral.TryGetChar(testChar, out var result, true); if (found) { Assert.That(result, Is.EqualTo(testCharResult)); } else { Assert.That(found, Is.False); } }
[TestCase(@"\zabc", @"\z", true)] // not included in look-up table public void UnEscapeCharLiterals_FormatterOption_Test(string input, string expected, bool shouldThrow) { var resultBuffer = new Span <char>(new char[input.Length]); if (shouldThrow) { try { EscapedLiteral.UnEscapeCharLiterals('\\', input.AsSpan(0, input.Length), true, resultBuffer); Assert.Fail("Failure expected."); } catch (Exception e) { Assert.That(() => throw e, Throws.ArgumentException.And.Message.Contains(expected)); } } else { var result = EscapedLiteral.UnEscapeCharLiterals('\\', input.AsSpan(0, input.Length), true, resultBuffer); Assert.That(result.ToString(), Is.EqualTo(expected)); } }
[TestCase("{}\\\n", @"\{\}\\\n")] // to escape public void EscapeCharLiterals_General_Test(string input, string expected) { var result = new string(EscapedLiteral.EscapeCharLiterals('\\', input, 0, input.Length, false).ToArray()); Assert.That(result, Is.EqualTo(expected)); }