Skip to content

Commit db11b9e

Browse files
committed
Fix bug in ClrTypeSpec2 re handling next character after nested. Add more tests.
1 parent a0d1b3e commit db11b9e

File tree

3 files changed

+166
-5
lines changed

3 files changed

+166
-5
lines changed

Clojure/Clojure/Lib/ClrTypeSpec2.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,9 @@ static ClrTypeSpec Parse(string name, ref int p, bool is_recurse, bool allow_aqn
723723
pos += 2; // skip "]+" to the start of the nested name
724724
var nested = Parse(name, ref pos, true, false, true);
725725
data.MergeNested(nested);
726-
if (is_recurse)
727-
// We are going to loop and increment pos, but we haven't yet dealt with the character that ended our nested.
728-
// Decrement pos so the loop increment will get us back to this place.
729-
--pos;
726+
// We are going to loop and increment pos, but we haven't yet dealt with the character that ended our nested.
727+
// Decrement pos so the loop increment will get us back to this place.
728+
--pos;
730729
}
731730
}
732731
else

Clojure/Csharp.Tests/TypeNameTests/TypeNameParsingTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ public void AssemblyName_ParsesCorrectly()
180180
spec = ClrTypeSpec.Parse("A+B, MyAssembly");
181181
cmp = TypeSpecComparer.Create("A").WithNested("B").WithAssembly("MyAssembly");
182182
Assert.That(cmp.SameAs(spec), Is.True);
183+
184+
spec = ClrTypeSpec.Parse("A[T][], AssemblyA");
185+
cmp = TypeSpecComparer.Create("A")
186+
.WithAssembly("AssemblyA")
187+
.WithGenericParams(TypeSpecComparer.Create("T"))
188+
.WithModifiers(new ClrArraySpec(1, false));
189+
Assert.That(cmp.SameAs(spec), Is.True);
183190
}
184191

185192
[Test]

Clojure/Csharp.Tests/TypeNameTests2/TypeNameParsingTests2.cs

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using clojure.lang.TypeName2;
22
using NUnit.Framework;
3+
using System;
34
using System.Collections.Generic;
45
using System.Linq;
56

@@ -330,7 +331,7 @@ public void GenericParams_ParsesCorrectly()
330331
[Test]
331332
public void SimpleNestedGeneric_ParsesCorrectly()
332333
{
333-
var spec = ClrTypeSpec.Parse("A[T]+B]");
334+
var spec = ClrTypeSpec.Parse("A[T]+B");
334335
var cmp = TypeSpecComparer.Create("A", 1)
335336
.WithNested("B")
336337
.WithGenericParams(
@@ -378,6 +379,13 @@ public void SimpleNestedGeneric_ParsesCorrectly()
378379
Assert.That(cmp.SameAs(spec), Is.True);
379380
}
380381

382+
[Test]
383+
public void NestedGenericProcessesTerminatingCharacter()
384+
{
385+
var exn = Assert.Throws<ArgumentException>(() => ClrTypeSpec.Parse("A[T]+B]"));
386+
Assert.That(exn.Message, Does.Contain("Unmatched ']'"));
387+
}
388+
381389

382390
[Test]
383391
public void NestedGenericWithModifiers_ParsesCorrectly()
@@ -448,6 +456,153 @@ public void NestedGenericAsGenericArg_ParsesCorrectly()
448456
Assert.That(cmp.SameAs(spec), Is.True);
449457
}
450458

459+
460+
[Test]
461+
public void NestedGenericWithAssembly_ParsesCorrectly()
462+
{
463+
var spec = ClrTypeSpec.Parse("A[T]+B, AssemblyA");
464+
var cmp = TypeSpecComparer.Create("A", 1)
465+
.WithAssembly("AssemblyA")
466+
.WithNested("B")
467+
.WithGenericParams(
468+
TypeSpecComparer.Create("T"));
469+
Assert.That(cmp.SameAs(spec), Is.True);
470+
471+
spec = ClrTypeSpec.Parse("A+B[T], AssemblyA");
472+
cmp = TypeSpecComparer.Create("A")
473+
.WithAssembly("AssemblyA")
474+
.WithNested(("B", 1))
475+
.WithGenericParams(
476+
TypeSpecComparer.Create("T"));
477+
Assert.That(cmp.SameAs(spec), Is.True);
478+
479+
spec = ClrTypeSpec.Parse("A+B[T]+C, AssemblyA");
480+
cmp = TypeSpecComparer.Create("A")
481+
.WithAssembly("AssemblyA")
482+
.WithNested(("B", 1), ("C", 0))
483+
.WithGenericParams(
484+
TypeSpecComparer.Create("T"));
485+
Assert.That(cmp.SameAs(spec), Is.True);
486+
487+
spec = ClrTypeSpec.Parse("A+B+C[T], AssemblyA");
488+
cmp = TypeSpecComparer.Create("A")
489+
.WithAssembly("AssemblyA")
490+
.WithNested(("B", 0), ("C", 1))
491+
.WithGenericParams(
492+
TypeSpecComparer.Create("T"));
493+
Assert.That(cmp.SameAs(spec), Is.True);
494+
495+
496+
spec = ClrTypeSpec.Parse("A+B[T]+C[U,V], AssemblyA");
497+
cmp = TypeSpecComparer.Create("A")
498+
.WithAssembly("AssemblyA")
499+
.WithNested(("B", 1), ("C", 2))
500+
.WithGenericParams(
501+
TypeSpecComparer.Create("T"),
502+
TypeSpecComparer.Create("U"),
503+
TypeSpecComparer.Create("V"));
504+
Assert.That(cmp.SameAs(spec), Is.True);
505+
506+
spec = ClrTypeSpec.Parse("A[T]+B+C+D[U,V]+E, AssemblyA");
507+
cmp = TypeSpecComparer.Create("A", 1)
508+
.WithAssembly("AssemblyA")
509+
.WithNested(("B", 0), ("C", 0), ("D", 2), ("E", 0))
510+
.WithGenericParams(
511+
TypeSpecComparer.Create("T"),
512+
TypeSpecComparer.Create("U"),
513+
TypeSpecComparer.Create("V"));
514+
Assert.That(cmp.SameAs(spec), Is.True);
515+
}
516+
517+
[Test]
518+
public void NestedGenericWithAssemblyWithModifiers_ParsesCorrectly()
519+
{
520+
var spec = ClrTypeSpec.Parse("A[T][], AssemblyA");
521+
var cmp = TypeSpecComparer.Create("A", 1)
522+
.WithAssembly("AssemblyA")
523+
.WithGenericParams(
524+
TypeSpecComparer.Create("T"))
525+
.WithModifiers(new ClrArraySpec(1, false));
526+
Assert.That(cmp.SameAs(spec), Is.True);
527+
528+
529+
spec = ClrTypeSpec.Parse("A[T]+B+C+D[U,V]+E[], AssemblyA");
530+
cmp = TypeSpecComparer.Create("A", 1)
531+
.WithAssembly("AssemblyA")
532+
.WithNested(("B", 0), ("C", 0), ("D", 2), ("E", 0))
533+
.WithGenericParams(
534+
TypeSpecComparer.Create("T"),
535+
TypeSpecComparer.Create("U"),
536+
TypeSpecComparer.Create("V"))
537+
.WithModifiers(new ClrArraySpec(1, false));
538+
Assert.That(cmp.SameAs(spec), Is.True);
539+
540+
spec = ClrTypeSpec.Parse("A[T]+B+C+D[U,V]+E[,]**&, AssemblyA");
541+
cmp = TypeSpecComparer.Create("A", 1)
542+
.WithAssembly("AssemblyA")
543+
.WithNested(("B", 0), ("C", 0), ("D", 2), ("E", 0))
544+
.WithGenericParams(
545+
TypeSpecComparer.Create("T"),
546+
TypeSpecComparer.Create("U"),
547+
TypeSpecComparer.Create("V"))
548+
.WithModifiers(new ClrArraySpec(2, false), new ClrPointerSpec(2))
549+
.SetIsByRef();
550+
Assert.That(cmp.SameAs(spec), Is.True);
551+
}
552+
553+
[Test]
554+
public void NestedGenericWithAseemblyAsGenericArg_ParsesCorrectly()
555+
{
556+
var spec = ClrTypeSpec.Parse("A[[B+C[T],AssemblyB]], AssemblyA");
557+
var cmp = TypeSpecComparer.Create("A", 1)
558+
.WithAssembly("AssemblyA")
559+
.WithGenericParams(
560+
TypeSpecComparer.Create("B").WithNested(("C", 1))
561+
.WithAssembly("AssemblyB")
562+
.WithGenericParams(
563+
TypeSpecComparer.Create("T")));
564+
Assert.That(cmp.SameAs(spec), Is.True);
565+
566+
567+
spec = ClrTypeSpec.Parse("A[[B+C[T]+D, AssemblyB]], AssemblyA");
568+
cmp = TypeSpecComparer.Create("A", 1)
569+
.WithAssembly("AssemblyA")
570+
.WithGenericParams(
571+
TypeSpecComparer.Create("B").WithNested(("C", 1), ("D", 0))
572+
.WithAssembly("AssemblyB")
573+
.WithGenericParams(
574+
TypeSpecComparer.Create("T")));
575+
Assert.That(cmp.SameAs(spec), Is.True);
576+
577+
578+
spec = ClrTypeSpec.Parse("A[[B+C[T], AssemblyB]]+D, AssemblyA");
579+
cmp = TypeSpecComparer.Create("A", 1)
580+
.WithAssembly("AssemblyA")
581+
.WithNested("D")
582+
.WithGenericParams(
583+
TypeSpecComparer.Create("B").WithNested(("C", 1))
584+
.WithAssembly("AssemblyB")
585+
.WithGenericParams(
586+
TypeSpecComparer.Create("T")));
587+
Assert.That(cmp.SameAs(spec), Is.True);
588+
589+
590+
spec = ClrTypeSpec.Parse("A[[B+C[T], AssemblyB],[D[U]+E, AssemblyD]]+F, AssemblyA");
591+
cmp = TypeSpecComparer.Create("A", 2)
592+
.WithAssembly("AssemblyA")
593+
.WithNested("F")
594+
.WithGenericParams(
595+
TypeSpecComparer.Create("B")
596+
.WithAssembly("AssemblyB")
597+
.WithNested(("C", 1))
598+
.WithGenericParams(TypeSpecComparer.Create("T")),
599+
TypeSpecComparer.Create("D", 1)
600+
.WithAssembly("AssemblyD")
601+
.WithNested("E")
602+
.WithGenericParams(TypeSpecComparer.Create("U")));
603+
Assert.That(cmp.SameAs(spec), Is.True);
604+
}
605+
451606
[Test]
452607
public void GenericArg_CannotBeByRef()
453608
{

0 commit comments

Comments
 (0)