コード例 #1
0
        public void CanMergeObject_RecursiveMerging()
        {
            var hocon = @"
foo
{
  bar {
    a : 42
    b : 43 
  }
},
foo
{ 
  bar
  {
    b : 44
    c : 45
    baz
    {
      a : 9000
    }
  }
}
";

            var config = HoconParser.Parse(hocon);

            Assert.Equal(42, config.GetInt("foo.bar.a"));
            Assert.Equal(44, config.GetInt("foo.bar.b"));
            Assert.Equal(45, config.GetInt("foo.bar.c"));
            Assert.Equal(9000, config.GetInt("foo.bar.baz.a"));
        }
コード例 #2
0
        public void CanMixObjectMergeAndSubstitutions_Issue92()
        {
            var hocon =
                @"x={ q : 10 }
y=5

a=1
a.q.r.s=${b}
a=${y}
a=${x}
a={ c : 3 }

b=${x}
b=${y}

// nesting ConfigDelayed inside another one
c=${x}
c={ d : 600, e : ${a}, f : ${b} }";

            var config = HoconParser.Parse(hocon);

            _output.WriteLine(config.PrettyPrint(2));
            Assert.Equal(3, config.GetInt("a.c"));
            Assert.Equal(10, config.GetInt("a.q"));
            Assert.Equal(5, config.GetInt("b"));
            Assert.Equal(600, config.GetInt("c.d"));
            Assert.Equal(3, config.GetInt("c.e.c"));
            Assert.Equal(10, config.GetInt("c.e.q"));
            Assert.Equal(5, config.GetInt("c.f"));
            Assert.Equal(10, config.GetInt("c.q"));
            Assert.Equal(10, config.GetInt("x.q"));
            Assert.Equal(5, config.GetInt("y"));
        }
コード例 #3
0
        public void ShouldRemoveAllTrailingWhitespace()
        {
            var hocon  = $"a = literal value{Whitespace.Whitespaces}";
            var config = HoconParser.Parse(hocon);

            Assert.Equal("literal value", config.GetString("a"));
        }
コード例 #4
0
        public void CanConvertToObjectList()
        {
            var hocon  = @"
a: {
  0: {
    a: {
      foo: bar
    }
  }, 
  1:{
    a: larry
    b: moe
  }, 
  2:{
    a: ben
    b: jerry
  }, 
}";
            var config = HoconParser.Parse(hocon);

            var objectList = config.GetObjectList("a");

            Assert.Equal("bar", objectList[0]["a.foo"].GetString());
            Assert.Equal("larry", objectList[1]["a"].GetString());
            Assert.Equal("moe", objectList[1]["b"].GetString());
            Assert.Equal("ben", objectList[2]["a"].GetString());
            Assert.Equal("jerry", objectList[2]["b"].GetString());
        }
コード例 #5
0
        string spreedsheetId = "1axexxSserxmBHquH_SX8n2lEZyAhrhS4"; //Id de Data Sophia

        dynamic convertHoconToJson(string text)
        {
            var config = HoconParser.Parse(text);
            var json   = config.ToJToken().ToString();

            return(JsonConvert.DeserializeObject(json));
        }
コード例 #6
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void CanAssignValueToPathExpression()
        {
            var hocon  = @"a.b.c=1";
            var config = HoconParser.Parse(hocon);

            Assert.Equal(1L, config.GetLong("a.b.c"));
        }
コード例 #7
0
ファイル: OmitRootBraces.cs プロジェクト: nthanhcong0/HOCON
        public void CanParseJsonWithNoRootBraces()
        {
            var hocon  = @"
""root"" : {
  ""int"" : 1,
  ""string"" : ""foo"",
  ""object"" : {
    ""hasContent"" : true
  },
  ""array"" : [1,2,3],
  ""null"" : null,
  ""double"" : 1.23,
  ""bool"" : true
},
""root_2"" : 1234";
            var config = HoconParser.Parse(hocon);

            Assert.Equal("1", config.GetString("root.int"));
            Assert.Equal("1.23", config.GetString("root.double"));
            Assert.True(config.GetBoolean("root.bool"));
            Assert.True(config.GetBoolean("root.object.hasContent"));
            Assert.Null(config.GetString("root.null"));
            Assert.Equal("foo", config.GetString("root.string"));
            Assert.True(new[] { 1, 2, 3 }.SequenceEqual(HoconParser.Parse(hocon).GetIntList("root.array")));
            Assert.Equal("1234", config.GetString("root_2"));
        }
コード例 #8
0
        public void CanConcatenateObjectsWhenMerged_Issue89()
        {
            var hocon  = @"
a {
  aa: 1
  bb: ""2""
        }

        a {
            cc: 3.3
        }
";
            var config = HoconParser.Parse(hocon);

            Assert.Equal(1, config.GetInt("a.aa"));
            Assert.Equal("2", config.GetString("a.bb"));
            Assert.Equal(3.3, config.GetDouble("a.cc"));
            _output.WriteLine(config.PrettyPrint(2));
            Assert.Equal(
                string.Join(
                    Environment.NewLine,
                    "{",
                    "  a : {",
                    "    aa : 1,",
                    "    bb : \"2\",",
                    "    cc : 3.3",
                    "  }",
                    "}"),
                config.PrettyPrint(2));
        }
コード例 #9
0
        public void DotAndCommaInQuotedKeyShouldBePreserved_79()
        {
            const string hocon  = @"
akka {
  persistence {
    journal {
      plugin = ""akka.persistence.journal.sql - server""
      sql-server {
        class = ""Akka.Persistence.SqlServer.Journal.BatchingSqlServerJournal, Akka.Persistence.SqlServer""
        schema-name = dbo
        table-name = EventJournal
        auto-initialize = off
        event-adapters
        {
          json-adapter = ""Demo.EventAdapter, Demo""
        }
        event-adapter-bindings
        {
          ""Demo.IMyEvent, MyDemoAssembly"" = json-adapter #this line makes a invalid token exception
        }
      }
    }
  }
}";
            var          config = HoconParser.Parse(hocon);
            var          path   = HoconPath.Parse(
                "akka.persistence.journal.sql-server.event-adapter-bindings.\"Demo.IMyEvent, MyDemoAssembly\"");

            Assert.Equal("Demo.IMyEvent, MyDemoAssembly", path.Last());
            Assert.Equal("json-adapter", config.GetString(path));
        }
コード例 #10
0
        public void QuotedKeyShouldHandleInvalidCharacters()
        {
            var hoconString = @"this.""should[]"".work = true";
            var config      = HoconParser.Parse(hoconString);

            Assert.True(config.GetBoolean("this.\"should[]\".work"));
        }
コード例 #11
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void GettingArrayFromLiteralsShouldThrow()
        {
            var hocon = " literal : a b c";

            HoconParser.Parse(hocon).Invoking(c => c.GetStringList("literal")).Should()
            .Throw <HoconException>("Anything converted to array should throw instead");
        }
コード例 #12
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void Fix_substitutions_Issue123()
        {
            var hocon = @"
a: avalue

b {
  b1: ""0001-01-01Z""
  b2: 0
  b_alpha: ${a}/${c.c1}/${b.b3}/${b.b4}
  b_beta: ""[""${b.b_alpha}"",""${b.b1}"",""${b.b2}""]""
}

c {
  c1: c1value
}

b {
  b3: b4value
}

b {
  b4: b4value
}
";

            var config = HoconParser.Parse(hocon);

            config.GetString("b.b_alpha").Should().Be("avalue/c1value/b4value/b4value");
            config.GetString("b.b_beta").Should().Be("[avalue/c1value/b4value/b4value,0001-01-01Z,0]");
        }
コード例 #13
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void Getter_failures_Should_include_bad_path()
        {
            var badConfig = HoconParser.Parse("{a.c: abc}");
            var badPath   = "a.c";

            badConfig.Invoking(c => c.GetInt(badPath)).Should().Throw <HoconValueException>().Which.FailPath.Should()
            .Be(badPath);
            badConfig.Invoking(c => c.GetDouble(badPath)).Should().Throw <HoconValueException>().Which.FailPath.Should()
            .Be(badPath);
            badConfig.Invoking(c => c.GetBooleanList(badPath)).Should().Throw <HoconValueException>().Which.FailPath
            .Should().Be(badPath);
            badConfig.Invoking(c => c.GetByteList(badPath)).Should().Throw <HoconValueException>().Which.FailPath
            .Should().Be(badPath);
            badConfig.Invoking(c => c.GetDecimalList(badPath)).Should().Throw <HoconValueException>().Which.FailPath
            .Should().Be(badPath);
            badConfig.Invoking(c => c.GetDoubleList(badPath)).Should().Throw <HoconValueException>().Which.FailPath
            .Should().Be(badPath);
            badConfig.Invoking(c => c.GetFloatList(badPath)).Should().Throw <HoconValueException>().Which.FailPath
            .Should().Be(badPath);
            badConfig.Invoking(c => c.GetIntList(badPath)).Should().Throw <HoconValueException>().Which.FailPath.Should()
            .Be(badPath);
            badConfig.Invoking(c => c.GetLongList(badPath)).Should().Throw <HoconValueException>().Which.FailPath
            .Should().Be(badPath);
            badConfig.Invoking(c => c.GetObjectList(badPath)).Should().Throw <HoconValueException>().Which.FailPath
            .Should().Be(badPath);
            badConfig.Invoking(c => c.GetStringList(badPath)).Should().Throw <HoconValueException>().Which.FailPath
            .Should().Be(badPath);
            badConfig.Invoking(c => c.GetInt(badPath)).Should().Throw <HoconValueException>().Which.FailPath.Should()
            .Be(badPath);
            badConfig.Invoking(c => c.GetInt(badPath)).Should().Throw <HoconValueException>().Which.FailPath.Should()
            .Be(badPath);
        }
コード例 #14
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void CanUnwrapSubConfig() //undefined behavior in spec, this does not behave the same as JVM hocon.
        {
            var hocon  = @"
a {
   b {
     c = 1
     d = true
   }
}";
            var config = HoconParser.Parse(hocon).Value.GetObject().Unwrapped;

            var a = config["a"] as IDictionary <string, object>;

            Assert.NotNull(a);
            Assert.IsType <Dictionary <string, object> >(a);
            Assert.Contains("b", a.Keys);
            Assert.IsType <Dictionary <string, object> >(a["b"]);

            var b = a["b"] as IDictionary <string, object>;

            Assert.NotNull(b);
            Assert.Contains("c", b.Keys);
            Assert.Contains("d", b.Keys);

            Assert.NotNull(b["c"]);
            Assert.IsType <HoconField>(b["c"]);
            Assert.Equal(1, ((HoconField)b["c"]).Value.GetInt());

            Assert.NotNull(b["d"]);
            Assert.IsType <HoconField>(b["d"]);
            Assert.True(((HoconField)b["d"]).Value.GetBoolean());
        }
コード例 #15
0
        public void ShouldPreserveWhitespacesInTheMiddle()
        {
            var hocon  = $"a = literal{Whitespace.Whitespaces}value";
            var config = HoconParser.Parse(hocon);

            Assert.Equal($"literal{Whitespace.Whitespaces}value", config.GetString("a"));
        }
コード例 #16
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void CanUsePathsAsKeys_FooBarBaz()
        {
            var hocon1 = @"foo.bar.baz : 42";
            var hocon2 = @"foo { bar { baz : 42 } }";

            Assert.Equal(HoconParser.Parse(hocon1).GetString("foo.bar.baz"),
                         HoconParser.Parse(hocon2).GetString("foo.bar.baz"));
        }
コード例 #17
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void GettingStringFromArrayShouldThrow()
        {
            var hocon = " array : [1,2,3]";

            HoconParser.Parse(hocon).Invoking(c => c.GetStringList("literal")).Should()
            .Throw <HoconException>("Anything converted to array should throw instead");
            //Assert.Null(HoconParser.Parse(hocon).GetString("array"));
        }
コード例 #18
0
        public void UndefinedQuestionMarkSubstitutionShouldResolveToEmptyArray()
        {
            var hocon = @"a {
  c = ${?a.b} [4,5,6]
}";

            Assert.True(new[] { 4, 5, 6 }.SequenceEqual(HoconParser.Parse(hocon).GetIntList("a.c")));
        }
コード例 #19
0
ファイル: test_hocon.cs プロジェクト: doolb/dnf
    public override void _Ready()
    {
        var cfg = HoconParser.Parse(EditorDescription);

        //var cfg = HoconConfigurationFactory.ParseString(EditorDescription);
        cfg.ToString().log();
        //cfg.GetString("debug");
    }
コード例 #20
0
        public void ThrowsWhenArrayItemTypesAreDifferent(string hocon)
        {
            var ex = Record.Exception(() => HoconParser.Parse(hocon));

            Assert.NotNull(ex);
            Assert.IsType <HoconParserException>(ex);
            _output.WriteLine($"Exception message: {ex.Message}");
        }
コード例 #21
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void CanUsePathsAsKeys_3()
        {
            var hocon1 = @"3 : 42";
            var hocon2 = @"""3"" : 42";

            Assert.Equal(HoconParser.Parse(hocon1).GetString("3"),
                         HoconParser.Parse(hocon2).GetString("3"));
        }
コード例 #22
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void AtKey_Should_work()
        {
            var initial = HoconParser.Parse("a = 5");
            var config  = initial.GetValue("a").AtKey("b");

            config.GetInt("b").Should().Be(5);
            config.HasPath("a").Should().BeFalse();
        }
コード例 #23
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void CanUsePathsAsKeys_3_14()
        {
            var hocon1 = @"3.14 : 42";
            var hocon2 = @"3 { 14 : 42}";

            Assert.Equal(HoconParser.Parse(hocon1).GetString("3.14"),
                         HoconParser.Parse(hocon2).GetString("3.14"));
        }
コード例 #24
0
        public void UndefinedQuestionMarkShouldFailSilently()
        {
            var hocon = @"a {
  b = ${?a.c}
}";

            HoconParser.Parse(hocon);
        }
コード例 #25
0
        public void CanConcatenateObjectsViaValueConcatenation_1()
        {
            var hocon  = "a : { b : 1 } { c : 2 }";
            var config = HoconParser.Parse(hocon);

            Assert.Equal(1, config.GetInt("a.b"));
            Assert.Equal(2, config.GetInt("a.c"));
        }
コード例 #26
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void CanUsePathsAsKeys_A_B_C()
        {
            var hocon1 = @"a b c : 42";
            var hocon2 = @"""a b c"" : 42";

            Assert.Equal(HoconParser.Parse(hocon1).GetString("a b c"),
                         HoconParser.Parse(hocon2).GetString("a b c"));
        }
コード例 #27
0
ファイル: HoconTests.cs プロジェクト: nthanhcong0/HOCON
        public void CanUsePathsAsKeys_true()
        {
            var hocon1 = @"true : 42";
            var hocon2 = @"""true"" : 42";

            Assert.Equal(HoconParser.Parse(hocon1).GetString("true"),
                         HoconParser.Parse(hocon2).GetString("true"));
        }
コード例 #28
0
        public void WithEmptyOrNonPositiveIndicesShouldThrow(string hocon)
        {
            var config = HoconParser.Parse(hocon);
            var ex     = Assert.Throws <HoconValueException>(() => { config.GetObjectList("a"); });

            ex.GetBaseException().Should().BeOfType <HoconException>();
            ex.FailPath.Should().Be("a");
        }
コード例 #29
0
        public void ExtraCommaAtTheEndIgnored()
        {
            var hocon_1 = @"a:1, b:2, c:3,";
            var hocon_2 = @"a:1, b:2, c:3";

            Assert.True(
                HoconParser.Parse(hocon_1).AsEnumerable()
                .SequenceEqual(HoconParser.Parse(hocon_2).AsEnumerable()));
        }
コード例 #30
0
        public void ThrowsOnCyclicSubstitutionDetection(string hocon)
        {
            var ex = Record.Exception(() => HoconParser.Parse(hocon));

            Assert.NotNull(ex);
            Assert.IsType <HoconParserException>(ex);
            Assert.Contains("cyclic", ex.Message);
            _output.WriteLine($"Exception message: {ex.Message}");
        }