File tree 3 files changed +41
-1
lines changed
3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 10
10
using System . Linq ;
11
11
using System . Text ;
12
12
using System . Threading . Tasks ;
13
+ using FluentAssertions ;
13
14
using Xunit ;
14
15
using Xunit . Abstractions ;
15
16
@@ -147,6 +148,27 @@ public void ObjectCanMixBraceAndDotSyntax()
147
148
Assert . Equal ( 32 , config . GetInt ( "foo.z" ) ) ;
148
149
}
149
150
151
+ // Fix for https://github.com/akkadotnet/HOCON/issues/137
152
+ [ Fact ]
153
+ public void ObjectsWithArraysShouldMergeCorrectly ( )
154
+ {
155
+ var hocon = @"
156
+ c: {
157
+ a: [2, 5]
158
+ a: [6]
159
+ }
160
+ " ;
161
+ var hocon2 = @"
162
+ c: {
163
+ a: [2, 5] [6]
164
+ }
165
+ " ;
166
+ var config = Parser . Parse ( hocon ) ;
167
+ config . GetIntList ( "c.a" ) . Should ( ) . Equal ( new [ ] { 6 } ) ;
168
+ config = Parser . Parse ( hocon2 ) ;
169
+ config . GetIntList ( "c.a" ) . Should ( ) . Equal ( new [ ] { 2 , 5 , 6 } ) ;
170
+ }
171
+
150
172
[ Fact ]
151
173
public void CanMixObjectMergeAndSubstitutions_Issue92 ( )
152
174
{
Original file line number Diff line number Diff line change 12
12
</ItemGroup >
13
13
14
14
<ItemGroup >
15
+ <PackageReference Include =" FluentAssertions" Version =" 5.9.0" />
15
16
<PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" $(TestSdkVersion)" />
16
17
<PackageReference Include =" xunit" Version =" $(XunitVersion)" />
17
18
<DotNetCliToolReference Include =" dotnet-xunit" Version =" $(XunitCliVersion)" />
Original file line number Diff line number Diff line change @@ -690,6 +690,11 @@ private HoconValue ParseValue(IHoconElement owner)
690
690
case TokenType . StartOfArray :
691
691
if ( value == null )
692
692
value = GetHoconValueFromParentElement ( owner , _tokens . Current . Type ) ;
693
+
694
+ // If this array is already initialized, we are going to overwrite it
695
+ if ( value . Type == HoconType . Array && value . Count > 0 )
696
+ value . Clear ( ) ;
697
+
693
698
value . Add ( ParseArray ( value ) ) ;
694
699
break ;
695
700
@@ -902,7 +907,19 @@ private HoconArray ParseArray(IHoconElement owner)
902
907
903
908
case TokenType . EndOfArray :
904
909
valueWasParsed = false ;
905
- parsing = false ;
910
+
911
+ // If there is a next array on the same like - let's move to it's first element
912
+ if ( _tokens . ForwardMatch ( TokenType . StartOfArray ) )
913
+ {
914
+ _tokens . ToNextSignificant ( ) ;
915
+ _tokens . Next ( ) ;
916
+ }
917
+ else
918
+ {
919
+ // Otherwise, array value is fully loaded and nothing to do here
920
+ parsing = false ;
921
+ }
922
+
906
923
break ;
907
924
908
925
case TokenType . Comment :
You can’t perform that action at this time.
0 commit comments