Skip to content

Commit

Permalink
Merge pull request #106 from thomasdc/feature-regex-matching
Browse files Browse the repository at this point in the history
Allow regex matching on name and full name when providing a string pattern
  • Loading branch information
fgather authored Aug 30, 2021
2 parents 9c0d03b + c9a4cad commit a3355d3
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 55 deletions.
16 changes: 8 additions & 8 deletions ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ public TGivenRuleTypeConjunction HaveName(string name)
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}

public TGivenRuleTypeConjunction HaveNameMatching(string pattern)
public TGivenRuleTypeConjunction HaveNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.AddPredicate(ObjectPredicatesDefinition<TRuleType>.HaveNameMatching(pattern));
_ruleCreator.AddPredicate(ObjectPredicatesDefinition<TRuleType>.HaveNameMatching(pattern, useRegularExpressions));
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}

Expand All @@ -400,9 +400,9 @@ public TGivenRuleTypeConjunction HaveFullName(string fullname)
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}

public TGivenRuleTypeConjunction HaveFullNameMatching(string pattern)
public TGivenRuleTypeConjunction HaveFullNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.AddPredicate(ObjectPredicatesDefinition<TRuleType>.HaveFullNameMatching(pattern));
_ruleCreator.AddPredicate(ObjectPredicatesDefinition<TRuleType>.HaveFullNameMatching(pattern, useRegularExpressions));
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}

Expand Down Expand Up @@ -738,9 +738,9 @@ public TGivenRuleTypeConjunction DoNotHaveName(string name)
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}

public TGivenRuleTypeConjunction DoNotHaveNameMatching(string pattern)
public TGivenRuleTypeConjunction DoNotHaveNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.AddPredicate(ObjectPredicatesDefinition<TRuleType>.DoNotHaveNameMatching(pattern));
_ruleCreator.AddPredicate(ObjectPredicatesDefinition<TRuleType>.DoNotHaveNameMatching(pattern, useRegularExpressions));
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}

Expand All @@ -750,9 +750,9 @@ public TGivenRuleTypeConjunction DoNotHaveFullName(string fullname)
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}

public TGivenRuleTypeConjunction DoNotHaveFullNameMatching(string pattern)
public TGivenRuleTypeConjunction DoNotHaveFullNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.AddPredicate(ObjectPredicatesDefinition<TRuleType>.DoNotHaveFullNameMatching(pattern));
_ruleCreator.AddPredicate(ObjectPredicatesDefinition<TRuleType>.DoNotHaveFullNameMatching(pattern, useRegularExpressions));
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}

Expand Down
8 changes: 4 additions & 4 deletions ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public interface IObjectConditions<out TReturnType, out TRuleType> where TRuleTy
TReturnType HaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string,object)> attributeArguments);
TReturnType HaveAttributeWithNamedArguments(Type attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments);
TReturnType HaveName(string name);
TReturnType HaveNameMatching(string pattern);
TReturnType HaveNameMatching(string pattern, bool useRegularExpressions = false);
TReturnType HaveFullName(string fullname);
TReturnType HaveFullNameMatching(string pattern);
TReturnType HaveFullNameMatching(string pattern, bool useRegularExpressions = false);
TReturnType HaveNameStartingWith(string pattern);
TReturnType HaveNameEndingWith(string pattern);
TReturnType HaveNameContaining(string pattern);
Expand Down Expand Up @@ -129,9 +129,9 @@ public interface IObjectConditions<out TReturnType, out TRuleType> where TRuleTy
TReturnType NotHaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string,object)> attributeArguments);
TReturnType NotHaveAttributeWithNamedArguments(Type attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments);
TReturnType NotHaveName(string name);
TReturnType NotHaveNameMatching(string pattern);
TReturnType NotHaveNameMatching(string pattern, bool useRegularExpressions = false);
TReturnType NotHaveFullName(string fullname);
TReturnType NotHaveFullNameMatching(string pattern);
TReturnType NotHaveFullNameMatching(string pattern, bool useRegularExpressions = false);
TReturnType NotHaveNameStartingWith(string pattern);
TReturnType NotHaveNameEndingWith(string pattern);
TReturnType NotHaveNameContaining(string pattern);
Expand Down
8 changes: 4 additions & 4 deletions ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public interface IObjectPredicates<out TReturnType, TRuleType> where TRuleType :
TReturnType HaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string,object)> attributeArguments);
TReturnType HaveAttributeWithNamedArguments(Type attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments);
TReturnType HaveName(string name);
TReturnType HaveNameMatching(string pattern);
TReturnType HaveNameMatching(string pattern, bool useRegularExpressions = false);
TReturnType HaveFullName(string fullname);
TReturnType HaveFullNameMatching(string pattern);
TReturnType HaveFullNameMatching(string pattern, bool useRegularExpressions = false);
TReturnType HaveNameStartingWith(string pattern);
TReturnType HaveNameEndingWith(string pattern);
TReturnType HaveNameContaining(string pattern);
Expand Down Expand Up @@ -130,9 +130,9 @@ public interface IObjectPredicates<out TReturnType, TRuleType> where TRuleType :
TReturnType DoNotHaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string,object)> attributeArguments);
TReturnType DoNotHaveAttributeWithNamedArguments(Type attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments);
TReturnType DoNotHaveName(string name);
TReturnType DoNotHaveNameMatching(string pattern);
TReturnType DoNotHaveNameMatching(string pattern, bool useRegularExpressions = false);
TReturnType DoNotHaveFullName(string fullname);
TReturnType DoNotHaveFullNameMatching(string pattern);
TReturnType DoNotHaveFullNameMatching(string pattern, bool useRegularExpressions = false);
TReturnType DoNotHaveNameStartingWith(string pattern);
TReturnType DoNotHaveNameEndingWith(string pattern);
TReturnType DoNotHaveNameContaining(string pattern);
Expand Down
24 changes: 12 additions & 12 deletions ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,11 +1569,11 @@ public static ICondition<TRuleType> HaveName(string name)
obj => obj.Name.Equals(name), obj => "does have name " + obj.Name, "have name \"" + name + "\"");
}

public static SimpleCondition<TRuleType> HaveNameMatching(string pattern)
public static SimpleCondition<TRuleType> HaveNameMatching(string pattern, bool useRegularExpressions = false)
{
return new SimpleCondition<TRuleType>(obj => obj.NameMatches(pattern),
return new SimpleCondition<TRuleType>(obj => obj.NameMatches(pattern, useRegularExpressions),
obj => "does have name " + obj.Name,
"have full name matching \"" + pattern + "\"");
"have full name " + (useRegularExpressions ? "matching" : "containing") + " \"" + pattern + "\"");
}


Expand All @@ -1584,11 +1584,11 @@ public static ICondition<TRuleType> HaveFullName(string fullname)
"have full name \"" + fullname + "\"");
}

public static ICondition<TRuleType> HaveFullNameMatching(string pattern)
public static ICondition<TRuleType> HaveFullNameMatching(string pattern, bool useRegularExpressions = false)
{
return new SimpleCondition<TRuleType>(obj => obj.FullNameMatches(pattern),
return new SimpleCondition<TRuleType>(obj => obj.FullNameMatches(pattern, useRegularExpressions),
obj => "does have full name " + obj.FullName,
"have full name matching \"" + pattern + "\"");
"have full name " + (useRegularExpressions ? "matching" : "containing") + " \"" + pattern + "\"");
}

public static ICondition<TRuleType> HaveNameStartingWith(string pattern)
Expand Down Expand Up @@ -2881,10 +2881,10 @@ public static ICondition<TRuleType> NotHaveName(string name)
"not have name \"" + name + "\"");
}

public static ICondition<TRuleType> NotHaveNameMatching(string pattern)
public static ICondition<TRuleType> NotHaveNameMatching(string pattern, bool useRegularExpressions = false)
{
return new SimpleCondition<TRuleType>(obj => !obj.NameMatches(pattern), obj => "does have name " + obj.Name,
"not have name matching \"" + pattern + "\"");
return new SimpleCondition<TRuleType>(obj => !obj.NameMatches(pattern, useRegularExpressions), obj => "does have name " + obj.Name,
"not have name " + (useRegularExpressions ? "matching" : "containing") + " \"" + pattern + "\"");
}

public static ICondition<TRuleType> NotHaveFullName(string fullname)
Expand All @@ -2893,11 +2893,11 @@ public static ICondition<TRuleType> NotHaveFullName(string fullname)
obj => "does have full name " + obj.FullName, "not have full name \"" + fullname + "\"");
}

public static ICondition<TRuleType> NotHaveFullNameMatching(string pattern)
public static ICondition<TRuleType> NotHaveFullNameMatching(string pattern, bool useRegularExpressions = false)
{
return new SimpleCondition<TRuleType>(obj => !obj.FullNameMatches(pattern),
return new SimpleCondition<TRuleType>(obj => !obj.FullNameMatches(pattern, useRegularExpressions),
obj => "does have full name " + obj.FullName,
"not have full name matching \"" + pattern + "\"");
"not have full name " + (useRegularExpressions ? "matching" : "containing") + " \"" + pattern + "\"");
}

public static ICondition<TRuleType> NotHaveNameStartingWith(string pattern)
Expand Down
23 changes: 12 additions & 11 deletions ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,20 +1113,21 @@ public static IPredicate<T> HaveName(string name)
return new SimplePredicate<T>(obj => obj.Name.Equals(name), "have name \"" + name + "\"");
}

public static IPredicate<T> HaveNameMatching(string pattern)
public static IPredicate<T> HaveNameMatching(string pattern, bool useRegularExpressions = false)
{
return new SimplePredicate<T>(obj => obj.NameMatches(pattern), "have name matching \"" + pattern + "\"");
return new SimplePredicate<T>(obj => obj.NameMatches(pattern, useRegularExpressions),
"have name " + (useRegularExpressions ? "matching" : "containing") + " \"" + pattern + "\"");
}

public static IPredicate<T> HaveFullName(string fullname)
{
return new SimplePredicate<T>(obj => obj.FullName.Equals(fullname), "have full name \"" + fullname + "\"");
}

public static IPredicate<T> HaveFullNameMatching(string pattern)
public static IPredicate<T> HaveFullNameMatching(string pattern, bool useRegularExpressions = false)
{
return new SimplePredicate<T>(obj => obj.FullNameMatches(pattern),
"have full name matching \"" + pattern + "\"");
return new SimplePredicate<T>(obj => obj.FullNameMatches(pattern, useRegularExpressions),
"have full name " + (useRegularExpressions ? "matching" : "containing") + " \"" + pattern + "\"");
}

public static IPredicate<T> HaveNameStartingWith(string pattern)
Expand Down Expand Up @@ -2062,10 +2063,10 @@ public static IPredicate<T> DoNotHaveName(string name)
return new SimplePredicate<T>(obj => !obj.Name.Equals(name), "do not have name \"" + name + "\"");
}

public static IPredicate<T> DoNotHaveNameMatching(string pattern)
public static IPredicate<T> DoNotHaveNameMatching(string pattern, bool useRegularExpressions = false)
{
return new SimplePredicate<T>(obj => !obj.NameMatches(pattern),
"do not have name matching \"" + pattern + "\"");
return new SimplePredicate<T>(obj => !obj.NameMatches(pattern, useRegularExpressions),
"do not have name " + (useRegularExpressions ? "matching" : "containing") + " \"" + pattern + "\"");
}

public static IPredicate<T> DoNotHaveFullName(string fullname)
Expand All @@ -2074,10 +2075,10 @@ public static IPredicate<T> DoNotHaveFullName(string fullname)
"do not have full name \"" + fullname + "\"");
}

public static IPredicate<T> DoNotHaveFullNameMatching(string pattern)
public static IPredicate<T> DoNotHaveFullNameMatching(string pattern, bool useRegularExpressions = false)
{
return new SimplePredicate<T>(obj => !obj.FullNameMatches(pattern),
"do not have full name matching \"" + pattern + "\"");
return new SimplePredicate<T>(obj => !obj.FullNameMatches(pattern, useRegularExpressions),
"do not have full name " + (useRegularExpressions ? "matching" : "containing") + " \"" + pattern + "\"");
}

public static IPredicate<T> DoNotHaveNameStartingWith(string pattern)
Expand Down
16 changes: 8 additions & 8 deletions ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ public TRuleTypeShouldConjunction HaveName(string name)
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction HaveNameMatching(string pattern)
public TRuleTypeShouldConjunction HaveNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.AddCondition(ObjectConditionsDefinition<TRuleType>.HaveNameMatching(pattern));
_ruleCreator.AddCondition(ObjectConditionsDefinition<TRuleType>.HaveNameMatching(pattern, useRegularExpressions));
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

Expand All @@ -456,9 +456,9 @@ public TRuleTypeShouldConjunction HaveFullName(string fullname)
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction HaveFullNameMatching(string pattern)
public TRuleTypeShouldConjunction HaveFullNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.AddCondition(ObjectConditionsDefinition<TRuleType>.HaveFullNameMatching(pattern));
_ruleCreator.AddCondition(ObjectConditionsDefinition<TRuleType>.HaveFullNameMatching(pattern, useRegularExpressions));
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

Expand Down Expand Up @@ -870,9 +870,9 @@ public TRuleTypeShouldConjunction NotHaveName(string name)
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction NotHaveNameMatching(string pattern)
public TRuleTypeShouldConjunction NotHaveNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.AddCondition(ObjectConditionsDefinition<TRuleType>.NotHaveNameMatching(pattern));
_ruleCreator.AddCondition(ObjectConditionsDefinition<TRuleType>.NotHaveNameMatching(pattern, useRegularExpressions));
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

Expand All @@ -882,9 +882,9 @@ public TRuleTypeShouldConjunction NotHaveFullName(string fullname)
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction NotHaveFullNameMatching(string pattern)
public TRuleTypeShouldConjunction NotHaveFullNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.AddCondition(ObjectConditionsDefinition<TRuleType>.NotHaveFullNameMatching(pattern));
_ruleCreator.AddCondition(ObjectConditionsDefinition<TRuleType>.NotHaveFullNameMatching(pattern, useRegularExpressions));
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

Expand Down
16 changes: 8 additions & 8 deletions ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,10 @@ public TRuleTypeShouldConjunction HaveName(string name)
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction HaveNameMatching(string pattern)
public TRuleTypeShouldConjunction HaveNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.ContinueComplexCondition(
ObjectPredicatesDefinition<TReferenceType>.HaveNameMatching(pattern));
ObjectPredicatesDefinition<TReferenceType>.HaveNameMatching(pattern, useRegularExpressions));
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

Expand All @@ -441,10 +441,10 @@ public TRuleTypeShouldConjunction HaveFullName(string fullname)
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction HaveFullNameMatching(string pattern)
public TRuleTypeShouldConjunction HaveFullNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.ContinueComplexCondition(
ObjectPredicatesDefinition<TReferenceType>.HaveFullNameMatching(pattern));
ObjectPredicatesDefinition<TReferenceType>.HaveFullNameMatching(pattern, useRegularExpressions));
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

Expand Down Expand Up @@ -811,10 +811,10 @@ public TRuleTypeShouldConjunction DoNotHaveName(string name)
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction DoNotHaveNameMatching(string pattern)
public TRuleTypeShouldConjunction DoNotHaveNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.ContinueComplexCondition(
ObjectPredicatesDefinition<TReferenceType>.DoNotHaveNameMatching(pattern));
ObjectPredicatesDefinition<TReferenceType>.DoNotHaveNameMatching(pattern, useRegularExpressions));
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

Expand All @@ -825,10 +825,10 @@ public TRuleTypeShouldConjunction DoNotHaveFullName(string fullname)
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction DoNotHaveFullNameMatching(string pattern)
public TRuleTypeShouldConjunction DoNotHaveFullNameMatching(string pattern, bool useRegularExpressions = false)
{
_ruleCreator.ContinueComplexCondition(
ObjectPredicatesDefinition<TReferenceType>.DoNotHaveFullNameMatching(pattern));
ObjectPredicatesDefinition<TReferenceType>.DoNotHaveFullNameMatching(pattern, useRegularExpressions));
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

Expand Down

0 comments on commit a3355d3

Please sign in to comment.