Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Marusyk authored Aug 28, 2023
1 parent d728697 commit d36b3c7
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/Grok.Net.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void Parse_Multiline_String_As_A_Single_Line_With_Regex_Options_Specified
const string logs = @"2023-02-21 04:15:26.349 Parsing output [221206045974]: [XXXX=9999]Got error: Dimension error at argument [0]
Node: X
Token: Y
Context: Sample text
Context: Sample text
Second line
(Third one)";

Expand All @@ -331,7 +331,48 @@ Second line
var relevantMultilineObject = multilineResult[1].Value;
Assert.NotNull(relevantMultilineObject);

Assert.Contains("(Third one)", (string) relevantMultilineObject);
Assert.Contains("(Third one)", (string)relevantMultilineObject);
}

[Fact]
public void Load_Custom_Patterns_From_Stream_And_Parse_With_Regex_Options_Specified()
{
// Arrange
const RegexOptions options = RegexOptions.Singleline;
const string zipcode = "122001";
const string email = "[email protected]";

var sut = new Grok("%{ZIPCODE:zipcode}:%{EMAILADDRESS:email}", ReadCustomFile(), options);

// Act
GrokResult grokResult = sut.Parse($"{zipcode}:{email}");

// Assert
Assert.Equal(zipcode, grokResult[0].Value);
Assert.Equal(email, grokResult[1].Value);
}

[Fact]
public void Load_Custom_Patterns_And_Parse_With_Regex_Options_Specified()
{
// Arrange
const RegexOptions options = RegexOptions.Singleline;
const string zipcode = "122001";
var customPatterns = new Dictionary<string, string>
{
{ "ZIPCODE", "[1-9]{1}[0-9]{2}\\s{0,1}[0-9]{3}" },
{ "FLOAT", "[+-]?([0-9]*[.,]}?[0-9]+)" }
};
const string email = "[email protected]";

var sut = new Grok("%{ZIPCODE:zipcode}:%{EMAILADDRESS:email}", customPatterns, options);

// Act
GrokResult grokResult = sut.Parse($"{zipcode}:{email}");

// Assert
Assert.Equal(zipcode, grokResult[0].Value);
Assert.Equal(email, grokResult[1].Value);
}

[Fact]
Expand Down

0 comments on commit d36b3c7

Please sign in to comment.