public void can_get_variables_by_regex()
        {
            var path = Path.GetTempFileName();

            File.WriteAllText(path, @"[foo]
  hello = first
  hell = second
  bar = none
  elle = third
");

            var doc = ConfigDocument.FromFile(path);

            Assert.Equal(3, doc.GetAll("el").Count());
            Assert.Single(doc.GetAll("el", "on"));
            Assert.Equal(2, doc.GetAll("!hel").Count());
            Assert.Single(doc.GetAll("!hel", "!on"));
        }
        public void set_variable_null_reads_as_null()
        {
            var path = Path.GetTempFileName();
            var doc  = ConfigDocument.FromFile(path);

            doc.Set("foo", "bar", "baz", "value")
            .Save()
            .Set("foo", "bar", "baz", null)
            .Save();

            var saved = ConfigDocument.FromFile(path);

            Assert.Single(saved);
            Assert.Equal("foo", saved.Single().Section);
            Assert.Equal("bar", saved.Single().Subsection);
            Assert.Equal("baz", saved.Single().Variable);
            Assert.Null(saved.Single().RawValue);
        }
        public void can_replace_existing_variable()
        {
            var path = Path.GetTempFileName();

            File.WriteAllText(path, @"[foo]
    bar = true # with a comment ; some # stuff """);

            ConfigDocument
            .FromFile(path)
            .Set("foo", null, "bar", "false")
            .Save();

            var saved = ConfigDocument.FromFile(path);

            Assert.Single(saved);
            Assert.Equal("foo", saved.Single().Section);
            Assert.Equal("bar", saved.Single().Variable);
            Assert.Equal("false", saved.Single().RawValue);
        }
        public void can_set_all_variables_matching_regex()
        {
            var path = Path.GetTempFileName();

            File.WriteAllText(path, @"[foo]
    source = github.com/kzu
    source = microsoft.com/kzu
    source = github.com/vga
    source = microsoft.com/vga");

            ConfigDocument
            .FromFile(path)
            .SetAll("foo", null, "source", "none", ValueMatcher.From("github\\.com"))
            .Save();

            var saved = ConfigDocument.FromFile(path);

            Assert.Equal(2, saved.Where(x => x.RawValue == "none").Count());
        }
        public void can_set_many_variables_section()
        {
            var path = Path.GetTempFileName();

            ConfigDocument
            .FromFile(path)
            .Set("foo", null, "bar", "false")
            .Save()
            .Set("foo", null, "baz", "true")
            .Save()
            .Set("foo", null, "weak")
            .Save();

            var saved = ConfigDocument.FromFile(path);

            Assert.Single(saved.Sections);
            Assert.Equal(3, saved.Variables.Count());
            Assert.Equal("weak", saved.Variables.Last().Variable);
        }
        public void can_set_new_variable_existing_section()
        {
            var path = Path.GetTempFileName();

            File.WriteAllText(path, @"[foo]
    bar = true");

            ConfigDocument
            .FromFile(path)
            .Set("foo", null, "baz", "false")
            .Save();

            var saved = ConfigDocument.FromFile(path);

            Assert.Single(saved.Skip(1));
            Assert.Equal("foo", saved.Skip(1).Single().Section);
            Assert.Equal("baz", saved.Skip(1).Single().Variable);
            Assert.Equal("false", saved.Skip(1).Single().RawValue);
        }