public void MergedSubstitutionShouldAlwaysResolveToOlderValue() { var source = @" foo : { a : { c : 1 } } foo : ${foo.a} foo : { a : 2 }"; JsonPlusRoot root = null; var ex = Record.Exception(() => root = JsonPlusParser.Parse(source)); Assert.Null(ex); Assert.Equal(2, root.GetInt32("foo.a")); Assert.Equal(1, root.GetInt32("foo.c")); Assert.False(root.HasPath("foo.a.c")); }
public void SubstitutionToAnotherMemberOfTheSameObjectAreResolvedNormally() { var source = @" bar : { foo : 42, baz : ${bar.foo} } bar : { foo : 43 }"; JsonPlusRoot root = null; var ex = Record.Exception(() => root = JsonPlusParser.Parse(source)); Assert.Null(ex); Assert.Equal(43, root.GetInt32("bar.foo")); Assert.Equal(43, root.GetInt32("bar.baz")); }
public void MutuallyReferringObjectsAreResolvedNormally() { var source = @" // bar.a should end up as 4 bar : { a : ${foo.d}, b : 1 } bar.b = 3 // foo.c should end up as 3 foo : { c : ${bar.b}, d : 2 } foo.d = 4"; JsonPlusRoot root = null; var ex = Record.Exception(() => root = JsonPlusParser.Parse(source)); Assert.Null(ex); Assert.Equal(4, root.GetInt32("bar.a")); Assert.Equal(3, root.GetInt32("foo.c")); }
public void HiddenSubstitutionShouldNeverBeEvaluated() { var source = @" foo : ${does-not-exist} foo : 42"; JsonPlusRoot root = null; var ex = Record.Exception(() => root = JsonPlusParser.Parse(source)); Assert.Null(ex); Assert.Equal(42, root.GetInt32("foo")); }