diff --git a/RegExtract.Test/Usage.cs b/RegExtract.Test/Usage.cs index 11946d6..a38d66a 100644 --- a/RegExtract.Test/Usage.cs +++ b/RegExtract.Test/Usage.cs @@ -220,6 +220,25 @@ public void a012() Assert.Equivalent(("sxc", new List { new Conditional(new Condition('x', '>', 2414), new Workflow("jtp")), new Conditional(new Condition('s', '>', 954), new Reject()), new Conditional(new Condition('m', '>', 2406), new Accept()), new Absolute(new Workflow("xfz")) }), result); } + record triple(int a, int b, int c) { + public static triple Parse(string str) + { + return new triple(0,0,0); + } + } + + private Regex rxa013 = new(@"(\d+) (\d+) (\d+)"); + + [Fact] + public void a013() + { + var plan = CreateAndLogPlan(rxa013); + + var result = plan.Extract("123 456 789"); + + Assert.Equal(new triple(123,456,789), result); + } + [Fact] public void f001() { diff --git a/RegExtract/ExtractionPlan.cs b/RegExtract/ExtractionPlan.cs index cf7d8e1..7f37c2c 100644 --- a/RegExtract/ExtractionPlan.cs +++ b/RegExtract/ExtractionPlan.cs @@ -132,11 +132,11 @@ private ExtractionPlanNode AssignTypesToTree(RegexCaptureGroupNode tree, Extract List groups = new(); List namedgroups = new(); - if (type.IsDirectlyConstructable) + if (tree.children is [] or [{children: []}] && type.IsDirectlyConstructable) { // We're at a leaf in the type hierarchy, and all we need is a string. // If there's an inner capture group, use it to narrow the match. - if (tree.children.Count() == 1) + if (tree.children.Length == 1) { tree = tree.children.Single(); }