Skip to content

Commit 8af11ee

Browse files
committed
Add a _lot_ of tests for ClrTypeSpec.
1 parent 4fe880e commit 8af11ee

4 files changed

Lines changed: 700 additions & 174 deletions

File tree

Clojure/Clojure/Lib/ClrTypeSpec.cs

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace clojure.lang;
3636
// The correct way to take a TypeName apart is to feed its
3737
// DisplayName to TypeSpec.Parse()
3838
//
39-
internal interface IClrTypeName : System.IEquatable<IClrTypeName>
39+
public interface IClrTypeName : System.IEquatable<IClrTypeName>
4040
{
4141
string DisplayName { get; }
4242

@@ -47,7 +47,7 @@ internal interface IClrTypeName : System.IEquatable<IClrTypeName>
4747
// A type identifier is a single component of a type name.
4848
// Unlike a general typename, a type identifier can be be
4949
// converted to internal form without loss of information.
50-
internal interface IClrTypeIdentifier : IClrTypeName
50+
public interface IClrTypeIdentifier : IClrTypeName
5151
{
5252
string InternalName { get; }
5353
}
@@ -147,25 +147,38 @@ public override IClrTypeName NestedName(IClrTypeIdentifier innerName)
147147
}
148148
}
149149

150-
internal interface IClrModifierSpec
150+
public interface IClrModifierSpec
151151
{
152152
Type Resolve(Type type);
153153
StringBuilder Append(StringBuilder sb);
154154
}
155155

156-
internal class ClrArraySpec : IClrModifierSpec
156+
public class ClrArraySpec : IClrModifierSpec
157157
{
158158

159159
// dimensions == 1 and bound, or dimensions > 1 and !bound
160160
private readonly int _dimensions;
161161
private readonly bool _isBound;
162162

163-
internal ClrArraySpec(int dimensions, bool bound)
163+
public ClrArraySpec(int dimensions, bool bound)
164164
{
165165
this._dimensions = dimensions;
166166
this._isBound = bound;
167167
}
168168

169+
public override bool Equals(object obj)
170+
{
171+
var o = obj as ClrArraySpec;
172+
if (o == null)
173+
return false;
174+
return o._dimensions == _dimensions && o._isBound == _isBound;
175+
}
176+
177+
public override int GetHashCode()
178+
{
179+
return 37 * _dimensions.GetHashCode() + IsBound.GetHashCode();
180+
}
181+
169182
public Type Resolve(Type type)
170183
{
171184
if (_isBound)
@@ -189,17 +202,29 @@ public StringBuilder Append(StringBuilder sb)
189202
public int Rank => _dimensions;
190203

191204
public bool IsBound => _isBound;
205+
206+
192207
}
193208

194-
internal class PointerSpec : IClrModifierSpec
209+
public class ClrPointerSpec : IClrModifierSpec
195210
{
196211
int pointer_level;
197212

198-
internal PointerSpec(int pointer_level)
213+
public ClrPointerSpec(int pointer_level)
199214
{
200215
this.pointer_level = pointer_level;
201216
}
202217

218+
public override bool Equals(object obj)
219+
{
220+
var o = obj as ClrPointerSpec;
221+
if (o == null)
222+
return false;
223+
return o.pointer_level == pointer_level;
224+
}
225+
226+
override public int GetHashCode() => pointer_level.GetHashCode();
227+
203228
public Type Resolve(Type type)
204229
{
205230
for (int i = 0; i < pointer_level; ++i)
@@ -229,12 +254,13 @@ public class ClrTypeSpec
229254

230255
#region Accessors
231256

232-
internal bool HasModifiers => _modifierSpec is not null;
233-
internal bool IsNested => _nested is not null && _nested.Count > 0;
234-
internal bool IsByRef => _isByRef;
235-
internal IClrTypeName Name => _name;
257+
public bool HasModifiers => _modifierSpec is not null;
258+
public bool IsNested => _nested is not null && _nested.Count > 0;
259+
public bool IsByRef => _isByRef;
260+
public IClrTypeName Name => _name;
261+
public string AssemblyName => _assemblyName;
236262

237-
internal IEnumerable<IClrTypeName> Nested
263+
public IEnumerable<IClrTypeName> Nested
238264
{
239265
get
240266
{
@@ -245,7 +271,7 @@ internal IEnumerable<IClrTypeName> Nested
245271
}
246272
}
247273

248-
internal IEnumerable<IClrModifierSpec> Modifiers
274+
public IEnumerable<IClrModifierSpec> Modifiers
249275
{
250276
get
251277
{
@@ -256,6 +282,17 @@ internal IEnumerable<IClrModifierSpec> Modifiers
256282
}
257283
}
258284

285+
public IEnumerable<ClrTypeSpec> GenericParams
286+
{
287+
get
288+
{
289+
if (_genericParams != null)
290+
return _genericParams;
291+
else
292+
return Array.Empty<ClrTypeSpec>();
293+
}
294+
}
295+
259296
#endregion
260297

261298
#region Display name-related
@@ -268,12 +305,12 @@ internal enum DisplayNameFormat
268305
NO_MODIFIERS = 0x2,
269306
}
270307

271-
#if DEBUG
308+
//#if DEBUG
272309
public override string ToString()
273310
{
274311
return GetDisplayFullName(DisplayNameFormat.WANT_ASSEMBLY);
275312
}
276-
#endif
313+
//#endif
277314

278315
string GetDisplayFullName(DisplayNameFormat flags)
279316
{
@@ -447,7 +484,7 @@ static IClrTypeIdentifier ParsedTypeIdentifier(string displayName)
447484

448485
#region Parsing
449486

450-
internal static ClrTypeSpec Parse(string typeName)
487+
public static ClrTypeSpec Parse(string typeName)
451488
{
452489
int pos = 0;
453490
if (typeName == null)
@@ -545,7 +582,7 @@ static ClrTypeSpec Parse(string name, ref int p, bool is_recurse, bool allow_aqn
545582
++pos;
546583
++pointer_level;
547584
}
548-
data.AddModifier(new PointerSpec(pointer_level));
585+
data.AddModifier(new ClrPointerSpec(pointer_level));
549586
break;
550587
case ',':
551588
if (is_recurse && allow_aqn)
@@ -597,7 +634,7 @@ static ClrTypeSpec Parse(string name, ref int p, bool is_recurse, bool allow_aqn
597634
if (name[pos] == ']')
598635
++pos;
599636
else
600-
throw new ArgumentException("Unclosed assembly-qualified type name at " + name[pos], "typeName");
637+
throw new ArgumentException("Unclosed assembly-qualified type name at " + name[pos], "typeName"); // Is this possible? AQN Ends with ] pending.
601638
BoundCheck(pos, name);
602639
}
603640

Clojure/Csharp.Tests/TypeNameParsingTests.cs

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

0 commit comments

Comments
 (0)