public void ParseActionWithValue_HandlesInput(string text, KeyValuePair <StringSegment, StringSegment> expected) { // Arrange & Act var actual = SlackCommand.ParseActionWithValue(text); // Assert Assert.Equal(expected, actual); }
public void ParseParameters_GetNormalizedParameterString_RoundTrips(string text, string expectedParameters) { // Arrange & Act var(result, error) = SlackCommand.ParseParameters(text); var actual = SlackCommand.GetNormalizedParameterString(result); // Assert Assert.Null(error); Assert.Equal(expectedParameters, actual); }
public void ParseParameters_ReturnsError_IfValueContainsMismatchedQuote(string input, char quote, int offset) { // Arrange var expected = $"Unmatched quote ({quote}) discovered at position {offset}."; // Act var(result, error) = SlackCommand.ParseParameters(input); // Assert Assert.Null(result); Assert.Equal(expected, error); }
public void ParseParameters_ReturnsError_IfTextFoundAfterQuotedString(string input, char ch, int offset) { // Arrange var expected = $"Parameter value contains text after a quoted string. Unexpected character ({ch}) " + $"discovered at position {offset}."; // Act var(result, error) = SlackCommand.ParseParameters(input); // Assert Assert.Null(result); Assert.Equal(expected, error); }
public void ParseParameters_ReturnsError_IfInvalidName(string name, int offset) { // Arrange var expected = "Parameter name cannot contain ';' characters. Unexpected escape sequence (\\;) " + $"discovered at position {offset}."; // Act var(result, error) = SlackCommand.ParseParameters(name); // Assert Assert.Null(result); Assert.Equal(expected, error); }
public void ParseParameters_ReturnsError_IfQuotedName(string name, char quote, int offset) { // Arrange var expected = $"Parameter name cannot be a quoted string. Unexpected character ({quote}) " + $"discovered at position {offset}."; // Act var(result, error) = SlackCommand.ParseParameters(name); // Assert Assert.Null(result); Assert.StartsWith(expected, error); }
public void ParseParameters_AcceptsValidValue(string value, string expectedValue) { // Arrange & Act var(result, error) = SlackCommand.ParseParameters($"name={value}"); // Assert var keyValuePair = Assert.Single(result); Assert.True(keyValuePair.Key.HasValue); Assert.Equal("name", keyValuePair.Key.Value); var segment = Assert.Single(keyValuePair.Value); Assert.True(segment.HasValue); Assert.Equal(expectedValue, segment.Value); Assert.Null(error); }
public void ParseParameters_AcceptsValidName(string name) { // Arrange & Act var expectedName = name.Trim(); var result = SlackCommand.TryParseParameters(name, out var error); // Assert var keyValuePair = Assert.Single(result); Assert.True(keyValuePair.Key.HasValue); Assert.Equal(expectedName, keyValuePair.Key.Value); var segment = Assert.Single(keyValuePair.Value); Assert.True(StringSegment.IsNullOrEmpty(segment)); Assert.Null(error); }