Skip to content

Commit b1a776e

Browse files
committed
Added GetHashCode implementations and suppressed warnings in testcode. Made IRegularExpression public to use in the GUI
1 parent 2468245 commit b1a776e

File tree

5 files changed

+61
-9
lines changed

5 files changed

+61
-9
lines changed

Rubberduck.RegexAssistant/Atom.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public override bool Equals(object obj)
9494
}
9595
return false;
9696
}
97+
98+
public override int GetHashCode()
99+
{
100+
return _specifier.GetHashCode();
101+
}
97102
}
98103

99104
internal class Group : IAtom
@@ -138,6 +143,11 @@ public override bool Equals(object obj)
138143
}
139144
return false;
140145
}
146+
147+
public override int GetHashCode()
148+
{
149+
return _specifier.GetHashCode();
150+
}
141151
}
142152

143153
internal class Literal : IAtom
@@ -245,5 +255,10 @@ public override bool Equals(object obj)
245255
}
246256
return false;
247257
}
258+
259+
public override int GetHashCode()
260+
{
261+
return _specifier.GetHashCode();
262+
}
248263
}
249264
}

Rubberduck.RegexAssistant/IRegularExpression.cs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,28 @@
77

88
namespace Rubberduck.RegexAssistant
99
{
10-
internal interface IRegularExpression : IDescribable
10+
public interface IRegularExpression : IDescribable
1111
{
1212
Quantifier Quantifier { get; }
13+
IList<IRegularExpression> Subexpressions { get; }
1314
}
1415

1516
internal class ConcatenatedExpression : IRegularExpression
1617
{
1718
private readonly Quantifier _quantifier;
18-
internal readonly IList<IRegularExpression> Subexpressions;
19+
private readonly IList<IRegularExpression> _subexpressions;
1920

2021
public ConcatenatedExpression(IList<IRegularExpression> subexpressions)
2122
{
22-
Subexpressions = subexpressions;
23+
_subexpressions = subexpressions;
2324
_quantifier = new Quantifier(string.Empty); // these are always exactly once. Quantifying happens through groups
2425
}
2526

2627
public string Description
2728
{
2829
get
2930
{
30-
return string.Join(Environment.NewLine, Subexpressions.Select(exp => exp.Description));
31+
return string.Join(Environment.NewLine, _subexpressions.Select(exp => exp.Description));
3132
}
3233
}
3334

@@ -38,24 +39,32 @@ public Quantifier Quantifier
3839
return _quantifier;
3940
}
4041
}
42+
43+
public IList<IRegularExpression> Subexpressions
44+
{
45+
get
46+
{
47+
return _subexpressions;
48+
}
49+
}
4150
}
4251

4352
internal class AlternativesExpression : IRegularExpression
4453
{
4554
private readonly Quantifier _quantifier;
46-
internal readonly IList<IRegularExpression> Subexpressions;
55+
private readonly IList<IRegularExpression> _subexpressions;
4756

4857
public AlternativesExpression(IList<IRegularExpression> subexpressions)
4958
{
50-
Subexpressions = subexpressions;
59+
_subexpressions = subexpressions;
5160
_quantifier = new Quantifier(string.Empty); // these are always exactly once. Quantifying happens through groups
5261
}
5362

5463
public string Description
5564
{
5665
get
5766
{
58-
return AssistantResources.ExpressionDescription_AlternativesExpression + Environment.NewLine + string.Join(Environment.NewLine, Subexpressions.Select(exp => exp.Description));
67+
return AssistantResources.ExpressionDescription_AlternativesExpression + Environment.NewLine + string.Join(Environment.NewLine, _subexpressions.Select(exp => exp.Description));
5968
}
6069
}
6170

@@ -66,6 +75,14 @@ public Quantifier Quantifier
6675
return _quantifier;
6776
}
6877
}
78+
79+
public IList<IRegularExpression> Subexpressions
80+
{
81+
get
82+
{
83+
return _subexpressions;
84+
}
85+
}
6986
}
7087

7188
internal class SingleAtomExpression : IRegularExpression
@@ -95,6 +112,14 @@ public Quantifier Quantifier
95112
}
96113
}
97114

115+
public IList<IRegularExpression> Subexpressions
116+
{
117+
get
118+
{
119+
return new List<IRegularExpression>(Enumerable.Empty<IRegularExpression>());
120+
}
121+
}
122+
98123
public override bool Equals(object obj)
99124
{
100125
if (obj is SingleAtomExpression)
@@ -104,6 +129,12 @@ public override bool Equals(object obj)
104129
}
105130
return false;
106131
}
132+
133+
public override int GetHashCode()
134+
{
135+
return Atom.GetHashCode() ^ Quantifier.GetHashCode();
136+
}
137+
107138
}
108139

109140
internal static class RegularExpression

Rubberduck.RegexAssistant/Quantifier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Rubberduck.RegexAssistant
55
{
6-
internal class Quantifier
6+
public class Quantifier
77
{
88
public static readonly string Pattern = @"(?<quantifier>(?<!\\)[\?\*\+]|(?<!\\)\{(\d+)(,\d*)?(?<!\\)\})";
99
private static readonly Regex Matcher = new Regex(@"^\{(?<min>\d+)(?<max>,\d*)?\}$");
@@ -103,7 +103,7 @@ public override string ToString()
103103
}
104104
}
105105

106-
internal enum QuantifierKind
106+
public enum QuantifierKind
107107
{
108108
None, Expression, Wildcard
109109
}

Rubberduck.RegexAssistant/Tests/CharacterClassTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ public void IncorrectlyEscapedRangeTargetLiteralsBlowUp()
176176
{
177177
CharacterClass cut = new CharacterClass(string.Format("[F-{0}]", escapedLiteral));
178178
}
179+
#pragma warning disable CS0168 // Variable is declared but never used
179180
catch (ArgumentException ex)
181+
#pragma warning restore CS0168 // Variable is declared but never used
180182
{
181183
continue;
182184
}

Rubberduck.RegexAssistant/Tests/LiteralTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public void EverythingElseBlowsUp()
6363
{
6464
Literal cut = new Literal("a"+blowup);
6565
}
66+
#pragma warning disable CS0168 // Variable is declared but never used
6667
catch (ArgumentException ex)
68+
#pragma warning restore CS0168 // Variable is declared but never used
6769
{
6870
Assert.IsTrue(true); // Assert.Pass();
6971
continue;
@@ -82,7 +84,9 @@ public void SingleEscapedCharsAreNotParsedAsLiteral()
8284
{
8385
Literal cut = new Literal(escape);
8486
}
87+
#pragma warning disable CS0168 // Variable is declared but never used
8588
catch (ArgumentException ex)
89+
#pragma warning restore CS0168 // Variable is declared but never used
8690
{
8791
Assert.IsTrue(true); // Assert.Pass();
8892
continue;

0 commit comments

Comments
 (0)