<commit_before>﻿using System.Collections.Generic;
using DotKafka.Prototype.Common.Config;
using DotKafka.Prototype.Common.Config.Types;
using Xunit;

namespace DotKafka.Tests.Common.Config {
    public class ConfigDefTest {
        [Fact]
        public void TestBasicTypes() {
            var def = new ConfigDef().Define("a", ConfigDef.Type.Int, 5, ConfigDef.Range.Between(0, 14),
                ConfigDef.Importance.High, "docs")
                .Define("b", ConfigDef.Type.Long, ConfigDef.Importance.High, "docs")
                .Define("c", ConfigDef.Type.String, "hello", ConfigDef.Importance.High, "docs")
                .Define("d", ConfigDef.Type.List, ConfigDef.Importance.High, "docs")
                .Define("e", ConfigDef.Type.Double, ConfigDef.Importance.High, "docs")
                //.Define("f", ConfigDef.Type.Class, ConfigDef.Importance.High, "docs")
                .Define("g", ConfigDef.Type.Bool, ConfigDef.Importance.High, "docs")
                .Define("h", ConfigDef.Type.Bool, ConfigDef.Importance.High, "docs")
                .Define("i", ConfigDef.Type.Bool, ConfigDef.Importance.High, "docs")
                .Define("j", ConfigDef.Type.Password, ConfigDef.Importance.High, "docs");

            var props = new Dictionary<string, object>();
            props.Add("a", "1   ");
            props.Add("b", 2);
            props.Add("d", " a , b, c");
            props.Add("e", 42.5d);
            //props.Add("f", string.class.etName());
            props.Add("g", "true");
            props.Add("h", "FalSE");
            props.Add("i", "TRUE");
            props.Add("j", "password");

            var vals = def.Parse(props);

            Assert.Equal(1, vals["a"]);
            Assert.Equal(2L, vals["b"]);
            Assert.Equal("hello", vals["c"]);
            Assert.Equal(new List<string> { "a", "b", "c" }, vals["d"]);
            Assert.Equal(42.5d, vals["e"]);
            //Assert.Equal(String.class, vals.get("f"));
            Assert.Equal(true, vals["g"]);
            Assert.Equal(false, vals["h"]);
            Assert.Equal(true, vals["i"]);
            Assert.Equal(new Password("password"), vals["j"]);
            Assert.Equal(Password.Hidden, vals["j"].ToString());

        }
}
}<commit_msg>Adding more config tests<commit_after>﻿using System;
using System.Collections.Generic;
using DotKafka.Prototype.Common.Config;
using DotKafka.Prototype.Common.Config.Types;
using Xunit;

namespace DotKafka.Tests.Common.Config {
    public class ConfigDefTest {
        [Fact]
        public void TestBasicTypes() {
            var def = new ConfigDef().Define("a", ConfigDef.Type.Int, 5, ConfigDef.Range.Between(0, 14),
                ConfigDef.Importance.High, "docs")
                .Define("b", ConfigDef.Type.Long, ConfigDef.Importance.High, "docs")
                .Define("c", ConfigDef.Type.String, "hello", ConfigDef.Importance.High, "docs")
                .Define("d", ConfigDef.Type.List, ConfigDef.Importance.High, "docs")
                .Define("e", ConfigDef.Type.Double, ConfigDef.Importance.High, "docs")
                //.Define("f", ConfigDef.Type.Class, ConfigDef.Importance.High, "docs")
                .Define("g", ConfigDef.Type.Bool, ConfigDef.Importance.High, "docs")
                .Define("h", ConfigDef.Type.Bool, ConfigDef.Importance.High, "docs")
                .Define("i", ConfigDef.Type.Bool, ConfigDef.Importance.High, "docs")
                .Define("j", ConfigDef.Type.Password, ConfigDef.Importance.High, "docs");

            var props = new Dictionary<string, object>();
            props.Add("a", "1   ");
            props.Add("b", 2);
            props.Add("d", " a , b, c");
            props.Add("e", 42.5d);
            //props.Add("f", string.class.etName());
            props.Add("g", "true");
            props.Add("h", "FalSE");
            props.Add("i", "TRUE");
            props.Add("j", "password");

            var vals = def.Parse(props);

            Assert.Equal(1, vals["a"]);
            Assert.Equal(2L, vals["b"]);
            Assert.Equal("hello", vals["c"]);
            Assert.Equal(new List<string> {"a", "b", "c"}, vals["d"]);
            Assert.Equal(42.5d, vals["e"]);
            //Assert.Equal(String.class, vals.get("f"));
            Assert.Equal(true, vals["g"]);
            Assert.Equal(false, vals["h"]);
            Assert.Equal(true, vals["i"]);
            Assert.Equal(new Password("password"), vals["j"]);
            Assert.Equal(Password.Hidden, vals["j"].ToString());
        }

        [Fact]
        public void TestInvalidDefault() {
            try {
                new ConfigDef().Define("a", ConfigDef.Type.Int, "hello", ConfigDef.Importance.High, "docs");
            }
            catch (Exception x) {
                Assert.IsType(typeof (ConfigException), x);
            }
        }

        [Fact]
        public void TestNullDefault() {
            var def = new ConfigDef().Define("a", ConfigDef.Type.Int, null, null, ConfigDef.Importance.Medium, "docs");
            var vals = def.Parse(new Dictionary<string, object>());
            Assert.Equal(null, vals["a"]);
        }

        [Fact]
        public void TestMissingRequired() {
            try {
                new ConfigDef().Define("a", ConfigDef.Type.Int, ConfigDef.Importance.High, "docs").
                    Parse(new Dictionary<string, object>());
            }
            catch (Exception x) {
                Assert.IsType(typeof (ConfigException), x);
                Assert.Equal("Missing required configuration \"a\" which has no default value.", x.Message);
            }
        }

        [Fact]
        public void TestDefinedTwice() {
            try {
                new ConfigDef().Define("a", ConfigDef.Type.String, ConfigDef.Importance.High, "docs").
                    Define("a", ConfigDef.Type.Int, ConfigDef.Importance.High, "docs");
            }
            catch (Exception x) {
                Assert.IsType(typeof (ConfigException), x);
                Assert.Equal("Configuration a is defined twice.", x.Message);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.16669398459268972, 'fraction_numerical': 0.004589411571873463, 'mean_word_length': 2.032803180914513, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '815481', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1767, 'n_words': 335}