Skip to content

Commit 4e471e3

Browse files
author
Gurpreet Singh
committed
cleanup
1 parent e3e1409 commit 4e471e3

File tree

5 files changed

+34
-66
lines changed

5 files changed

+34
-66
lines changed

src/.editorconfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[*.cs]
22

3-
# Default severity for analyzer diagnostics with category 'Style'
4-
dotnet_analyzer_diagnostic.category-Style.severity = none
3+
4+
# SYSLIB1045: Convert to 'GeneratedRegexAttribute'.
5+
dotnet_diagnostic.SYSLIB1045.severity = none
Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using Microsoft.VisualBasic;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Globalization;
1+
using System;
52
using System.Linq;
63
using System.Text.RegularExpressions;
74
using TestStack.BDDfy.Configuration;
@@ -10,65 +7,49 @@ namespace TestStack.BDDfy
107
{
118
internal partial class DefaultHumanizer: IHumanizer
129
{
13-
private static readonly TextInfo textInfo = CultureInfo.CurrentCulture.TextInfo;
10+
private static readonly Regex ConsecutiveCapitalLetters = new("([A-Z]+)([A-Z][a-z])");
11+
private static readonly Regex TokensPattern = new("__([a-zA-Z0-9]+)__");
12+
private static readonly Regex PascalCaseRegex = new(@"(?<!^)([A-Z])");
13+
private static readonly Regex TokenReplacePattern = new("#(\\S+)#");
14+
private static readonly Regex SentenceWithNumerals = new(@"(?<=[a-zA-Z])(?=\d)(?![^<>]*>)");
15+
private static readonly Regex UnicodeMatchPattern = new(@"[^\u0000-\u007F]");
16+
private static readonly Regex LoneIReplacePattern = new(@"(?<=^|\s)i(?=\s|$)");
1417

1518
public string Humanize(string input)
1619
{
1720
var shouldPreserveCasing = input.Replace("__", "-").Contains('_');
1821

19-
input = TokensPattern().Replace(input, "-#$1#-");
22+
input = TokensPattern.Replace(input, "-#$1#-");
2023

2124
var words = input.Split(['_','-']);
2225

23-
var finalWords = words.Select(x => TokenReplacePattern().Replace(x, "<$1>"));
26+
var finalWords = words.Select(x => TokenReplacePattern.Replace(x, "<$1>"));
2427

2528
var sentence = string.Join(" ", finalWords);
2629

2730
if (!shouldPreserveCasing)
2831
{
29-
sentence = ConsecutiveCapitalLetters().Replace(sentence, "$1 $2");
32+
sentence = ConsecutiveCapitalLetters.Replace(sentence, "$1 $2");
3033
sentence = PascalToSentence(sentence);
31-
sentence = SentenceWithNumerals().Replace(sentence, " ");
32-
if (UnicodeMatchPattern().IsMatch(input))
34+
sentence = SentenceWithNumerals.Replace(sentence, " ");
35+
if (UnicodeMatchPattern.IsMatch(input))
3336
throw new ArgumentException("Non ascii characters detected");
3437
}
3538

3639

3740
sentence = sentence.Trim().Replace(" "," ");
38-
sentence = LoneIReplacePattern().Replace(sentence, "I");
41+
sentence = LoneIReplacePattern.Replace(sentence, "I");
3942
return sentence;
4043
}
4144

4245
public static string PascalToSentence(string input)
4346
{
4447
if (string.IsNullOrEmpty(input)) return input;
4548

46-
var sentence = PascalCaseRegex().Replace(input, " $1");
49+
var sentence = PascalCaseRegex.Replace(input, " $1");
4750
sentence = sentence.Replace("< ", "<").Replace(" >",">");
48-
var final = char.ToUpper(sentence[0]) + sentence.Substring(1).ToLower();
51+
var final = char.ToUpper(sentence[0]) + sentence[1..].ToLower();
4952
return final;
5053
}
51-
52-
53-
[GeneratedRegex("([A-Z]+)([A-Z][a-z])")]
54-
private static partial Regex ConsecutiveCapitalLetters();
55-
56-
[GeneratedRegex("__([a-zA-Z0-9]+)__")]
57-
private static partial Regex TokensPattern();
58-
59-
[GeneratedRegex(@"(?<!^)([A-Z])")]
60-
private static partial Regex PascalCaseRegex();
61-
62-
[GeneratedRegex("#(\\S+)#")]
63-
private static partial Regex TokenReplacePattern();
64-
65-
[GeneratedRegex(@"(?<=[a-zA-Z])(?=\d)(?![^<>]*>)")]
66-
private static partial Regex SentenceWithNumerals();
67-
68-
[GeneratedRegex(@"[^\u0000-\u007F]")]
69-
private static partial Regex UnicodeMatchPattern();
70-
71-
[GeneratedRegex(@"(?<=^|\s)i(?=\s|$)")]
72-
private static partial Regex LoneIReplacePattern();
7354
}
7455
}

src/TestStack.BDDfy/Processors/UnusedExampleException.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
namespace TestStack.BDDfy.Processors
44
{
5-
[Serializable]
6-
public class UnusedExampleException : Exception
7-
{
8-
public UnusedExampleException(ExampleValue unusedValue) : base(string.Format("Example Column '{0}' is unused, all examples should be consumed by the test (have you misspelt a field or property?)\r\n\r\n"
9-
+ "If this is not the case, raise an issue at https://github.com/TestStack/TestStack.BDDfy/issues.", unusedValue.Header))
10-
{
11-
}
12-
}
5+
[Serializable]
6+
public class UnusedExampleException : Exception
7+
{
8+
public UnusedExampleException(ExampleValue unusedValue)
9+
: base(string.Format("Example Column '{0}' is unused, all examples should be consumed by the test (have you misspelt a field or property?)\r\n\r\n"
10+
+ "If this is not the case, raise an issue at https://github.com/TestStack/TestStack.BDDfy/issues.", unusedValue.Header))
11+
{
12+
}
13+
}
1314
}

src/TestStack.BDDfy/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/TestStack.BDDfy/TestStack.BDDfy.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Company>TestStack.BDDfy - http://teststack.github.com/TestStack.BDDfy/</Company>
4+
<Product>TestStack.BDDfy</Product>
5+
<Copyright>Copyright © 2011-2017 TestStack.BDDfy contributors</Copyright>
6+
</PropertyGroup>
27
<PropertyGroup>
38
<TargetFrameworks>net8.0</TargetFrameworks>
49
<AssemblyName>TestStack.BDDfy</AssemblyName>
@@ -15,5 +20,6 @@
1520

1621
<ItemGroup>
1722
<EmbeddedResource Include="**\Scripts\*.*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
23+
<InternalsVisibleTo Include="$(AssemblyName).Tests"/>
1824
</ItemGroup>
1925
</Project>

0 commit comments

Comments
 (0)