示例#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
        public void CanAssignValueToPathExpression()
        {
            var hocon  = @"a.b.c=1";
            var config = HoconParser.Parse(hocon);

            Assert.Equal(1L, config.GetLong("a.b.c"));
        }
示例#7
0
        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
        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
        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
        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
        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
        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
        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
        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
        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
        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
        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
        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()));
        }
        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}");
        }