예제 #1
0
        public void TestBool()
        {
            var            p   = new CmdArgsParser <ConfBool>();
            Res <ConfBool> res = p.ParseCommandLine(new[] { "-a", "-b", "true" });

            Assert.AreEqual(expected: true, actual: res.Args.A);
            Assert.AreEqual(expected: true, actual: res.Args.B);
            Assert.AreEqual(expected: false, actual: res.Args.C);
            Assert.AreEqual(expected: null, actual: res.Args.D);
        }
예제 #2
0
        public void TestEmpty2()
        {
            var p = new CmdArgsParser <ConfEmpty>();

            p.UseOnlyEqualitySyntax    = true;
            p.AllowAdditionalArguments = true;
            Res <ConfEmpty> r = p.ParseCommandLine(new[] { "-a" });

            Assert.AreEqual("def", r.Args.A);
        }
예제 #3
0
        public void TestOne()
        {
            var p = new CmdArgsParser <ConfOne>();

            p.UseOnlyEqualitySyntax = true;
            Res <ConfOne> r = p.ParseCommandLine(new[] { "--Sec=qwer", "-a=uiop" });

            Assert.AreEqual("uiop", r.Args.A);
            Assert.AreEqual("qwer", r.Args.B);
        }
예제 #4
0
        public void TestValues()
        {
            var p = new CmdArgsParser <Conf> {
                AllowUnknownArguments = true
            };

            Res <Conf> rv = p.ParseCommandLine(new[] { "--unk", "val1", "val2" });

            Check(rv, s: false, d: false, unk: "unk", vals: new[] { "val1", "val2" });
        }
예제 #5
0
        public void TestLongname()
        {
            var p = new CmdArgsParser <Conf> {
                AllowUnknownArguments = true
            };

            Res <Conf> rv = p.ParseCommandLine(new[] { "--unk" });

            Check(rv, s: false, d: false, unk: "unk");
        }
예제 #6
0
        public void TestSimpleAfter()
        {
            var p = new CmdArgsParser <Conf>();

            Res <Conf> r = p.ParseCommandLine(new[] { "-d", ArgsConfFilepath, "-s=nm" });

            Assert.AreEqual("nm", r.Args.S);
            Assert.AreEqual("qwer", r.Args.T);
            Assert.AreEqual("uio 89", r.Args.U);
        }
예제 #7
0
        public void TestDirExists()
        {
            Assembly a  = Assembly.GetExecutingAssembly();
            var      fi = new FileInfo(a.Location);

            var             p   = new CmdArgsParser <ConfDirEx>();
            Res <ConfDirEx> res = p.ParseCommandLine(new[] { "-f", fi.DirectoryName });

            Assert.AreEqual(true, res.Args.Dir.Exists);
            Assert.AreEqual(fi.DirectoryName, res.Args.Dir.FullName);
        }
예제 #8
0
        public void TestDefarray()
        {
            var p = new CmdArgsParser <ConfDefarray>();
            Res <ConfDefarray> res = p.ParseCommandLine(new[] { "-p" });

            Assert.AreEqual(2, res.Args.P.Length);
            Assert.AreEqual(1, res.Args.P[0].A);
            Assert.AreEqual(3, res.Args.P[0].B);
            Assert.AreEqual(1, res.Args.P[1].A);
            Assert.AreEqual(4, res.Args.P[1].B);
        }
예제 #9
0
        public void TestUnknownOnlyAfter()
        {
            var p = new CmdArgsParser <Conf>();

            Res <Conf> r = p.ParseCommandLine(new[]
                                              { "-d", ArgsConfFilepath, "--unk" });

            Assert.AreEqual(1, r.UnknownArguments.Count);
            Assert.AreEqual("unk", r.UnknownArguments[0].Item1);
            Assert.IsEmpty(r.UnknownArguments[0].Item2);
        }
예제 #10
0
        public void TestAdditionalUnion()
        {
            var p = new CmdArgsParser <Conf>();

            Res <Conf> r = p.ParseCommandLine(new[]
                                              { "bef", "-d", ArgsConfAdditionalFilepath, "after" });

            Assert.IsTrue(
                new[] { "bef", "addit1", "addit2", "addit3", "after" }
                .SequenceEqual(r.AdditionalArguments));
        }
예제 #11
0
        public void TestCollectionDefOk()
        {
            var p = new CmdArgsParser <ConfCollectionDef>();
            Res <ConfCollectionDef> res =
                p.ParseCommandLine(new[] { "-a", "-l" });

            Assert.IsTrue(new[] { 2 }.SequenceEqual(res.Args.Array));
            Assert.IsTrue(new[] { 2, 3 }.SequenceEqual(res.Args.Array1));
            Assert.IsTrue(new[] { 2 }.SequenceEqual(res.Args.List));
            Assert.IsTrue(new[] { 2, 3 }.SequenceEqual(res.Args.List1));
        }
예제 #12
0
        public void TestNullValue()
        {
            var p = new CmdArgsParser <ConfOkOne>();

            Res <ConfOkOne> r = p.ParseCommandLine(new[] { "--DEFINEname" });

            Assert.IsNotNull(r.Args.Uns);
            Assert.AreEqual(1, r.Args.Uns.Count);
            Assert.AreEqual("name", r.Args.Uns[0].Name);
            Assert.IsNull(r.Args.Uns[0].Value);
        }
예제 #13
0
        public void TestEmpty()
        {
            var p = new CmdArgsParser <ConfEmpty>();

            p.UseOnlyEqualitySyntax    = true;
            p.AllowAdditionalArguments = true;
            Res <ConfEmpty> r = p.ParseCommandLine(new[] { "-a=", "noval" });

            Assert.AreEqual("", r.Args.A);
            Assert.IsTrue(new[] { "noval" }.SequenceEqual(r.AdditionalArguments));
        }
예제 #14
0
        public void TestArray()
        {
            var             p   = new CmdArgsParser <ConfArray>();
            Res <ConfArray> res =
                p.ParseCommandLine(new[] { "-f", "./a.conf", "./b.conf" });
            var    fi   = new FileInfo("./a");
            string path = fi.DirectoryName;

            Assert.IsTrue(res.Args.Files.Select(x => x.FullName)
                          .SequenceEqual(new[] { Path.Combine(path, "a.conf"), Path.Combine(path, "b.conf") }));
        }
예제 #15
0
        public void TestFloatingRus()
        {
            var p = new CmdArgsParser <ConfFloating>(CultureInfo.GetCultureInfo("ru"));
            //var p = new CmdArgsParser();
            Res <ConfFloating> rv = p.ParseCommandLine(new[]
                                                       { "-s", "1,1", "--doub", "1,123", "--flo", "-123,4534" });

            Assert.AreEqual(actual: rv.Args.Dec, expected: 1.1m);
            Assert.AreEqual(actual: rv.Args.Doub, expected: 1.123d);
            Assert.AreEqual(actual: rv.Args.Flo, expected: -123.4534f);
        }
예제 #16
0
        public void TestMixed()
        {
            var p = new CmdArgsParser <ConfAdd>();

            p.UseOnlyEqualitySyntax = false;
            Res <ConfAdd> r = p.ParseCommandLine(new[]
                                                 { "-a=asdf", "-b", "jkli" });

            Assert.AreEqual("asdf", r.Args.A);
            Assert.AreEqual("jkli", r.Args.B);

            Assert.IsEmpty(r.AdditionalArguments);
        }
예제 #17
0
        public void Test4()
        {
            var p = new CmdArgsParser <FluidBaseConf>();
            Res <FluidBaseConf> r = p.ParseCommandLine(new[]
            {
                "--labels", "bus_data OR bus_longtime_data",
                "--contexts", "Light", "prod", "sync_prod", "sync",
                "--defaultsFile", "core/liquibase_CIS-DB.CIS_custom.properties",
                "update"
            });

            Check(r);
        }
예제 #18
0
        public void TestAdd()
        {
            var p = new CmdArgsParser <ConfAdd>();

            p.UseOnlyEqualitySyntax    = true;
            p.AllowAdditionalArguments = true;
            Res <ConfAdd> r = p.ParseCommandLine(new[]
                                                 { "-a=asdf", "noval", "-b=qewr", "jkli", "-34" });

            Assert.AreEqual("asdf", r.Args.A);
            Assert.AreEqual("qewr", r.Args.B);

            Assert.IsTrue(new[] { "noval", "jkli", "-34" }.SequenceEqual(r.AdditionalArguments));
        }
예제 #19
0
        public void TestAdditional()
        {
            var p = new CmdArgsParser <ConfOkOne>();

            p.AllowAdditionalArguments = true;
            Res <ConfOkOne> r =
                p.ParseCommandLine(new[] { "-Dname=val", "additional", "--unknown" });

            Assert.IsNotNull(r.Args.Uns);
            Assert.AreEqual(1, r.Args.Uns.Count);
            Assert.AreEqual("name", r.Args.Uns[0].Name);
            Assert.AreEqual("val", r.Args.Uns[0].Value);

            Assert.IsTrue(new[] { "additional" }.SequenceEqual(r.AdditionalArguments));
        }
예제 #20
0
        public void TestUnstrictlyOnlyIn()
        {
            var p = new CmdArgsParser <ConfUnstrictly>();
            Res <ConfUnstrictly> r = p.ParseCommandLine(new[]
                                                        { "-d", ArgsConfUnstrictlyFilepath });

            Assert.IsNotNull(r.Args.Uns);
            Assert.AreEqual(2, r.Args.Uns.Count);
            Assert.AreEqual("name", r.Args.Uns[0].Name);
            Assert.AreEqual("val", r.Args.Uns[0].Value);
            Assert.AreEqual("nhy", r.Args.Uns[1].Name);
            Assert.AreEqual("bghtl", r.Args.Uns[1].Value);

            Assert.AreEqual("asdffs", r.Args.S);
            Assert.AreEqual("qwer", r.Args.T);
            Assert.AreEqual("uio 89", r.Args.U);
        }
예제 #21
0
        public void TestArray()
        {
            var p = new CmdArgsParser <ConfArray>();

            p.UseOnlyEqualitySyntax = true;
            Res <ConfArray> r = p.ParseCommandLine(new[]
                                                   { "-a=uiop,asdf", "--Sec=qwer;zxcv", "-c=\"gh df\"" });

            Assert.AreEqual(2, r.Args.A.Length);
            Assert.AreEqual("uiop", r.Args.A[0]);
            Assert.AreEqual("asdf", r.Args.A[1]);

            Assert.AreEqual(2, r.Args.B.Length);
            Assert.AreEqual("qwer", r.Args.B[0]);
            Assert.AreEqual("zxcv", r.Args.B[1]);

            Assert.AreEqual(2, r.Args.C.Length);
            Assert.AreEqual("\"gh", r.Args.C[0]);
            Assert.AreEqual("df\"", r.Args.C[1]);
        }
예제 #22
0
        public void TestUnknownOnlyIn()
        {
            var p = new CmdArgsParser <Conf>();

            Res <Conf> r = p.ParseCommandLine(new[] { "-d", ArgsConfUnknownFilepath });

            Assert.AreEqual(3, r.UnknownArguments.Count);
            Assert.AreEqual("unk1", r.UnknownArguments[0].Item1);
            Assert.AreEqual("unk2", r.UnknownArguments[1].Item1);
            Assert.AreEqual("unk3", r.UnknownArguments[2].Item1);

            Assert.IsEmpty(r.UnknownArguments[0].Item2);

            Assert.AreEqual(1, r.UnknownArguments[1].Item2.Length);
            Assert.AreEqual("var", r.UnknownArguments[1].Item2[0]);

            Assert.AreEqual(2, r.UnknownArguments[2].Item2.Length);
            Assert.AreEqual("var1", r.UnknownArguments[2].Item2[0]);
            Assert.AreEqual("var2", r.UnknownArguments[2].Item2[1]);
        }
예제 #23
0
        public void TestTwo()
        {
            var p = new CmdArgsParser <ConfTwo>();

            Res <ConfTwo> r = p.ParseCommandLine(new[]
                                                 { "-Dname=val", "-Mwe=34", "-Dzzxcv=gf", "--MANcv=123" });

            Assert.IsNotNull(r.Args.Uns);
            Assert.AreEqual(2, r.Args.Uns.Count);
            Assert.AreEqual("name", r.Args.Uns[0].Name);
            Assert.AreEqual("val", r.Args.Uns[0].Value);
            Assert.AreEqual("zzxcv", r.Args.Uns[1].Name);
            Assert.AreEqual("gf", r.Args.Uns[1].Value);

            Assert.IsNotNull(r.Args.Man);
            Assert.AreEqual(2, r.Args.Man.Count);
            Assert.AreEqual("we", r.Args.Man[0].Name);
            Assert.AreEqual("34", r.Args.Man[0].Value);
            Assert.AreEqual("cv", r.Args.Man[1].Name);
            Assert.AreEqual("123", r.Args.Man[1].Value);
        }
예제 #24
0
        public void TestArray()
        {
            var             p   = new CmdArgsParser <ConfArray>();
            Res <ConfArray> res = p.ParseCommandLine(new[]
                                                     { "-a", "23:64", "4:56", "-l", "59:84", "58:81" });

            Assert.AreEqual(2, res.Args.A.Length);
            Assert.AreEqual(2, res.Args.L.Count);

            Assert.AreEqual(23, res.Args.A[0].A);
            Assert.AreEqual(64, res.Args.A[0].B);

            Assert.AreEqual(4, res.Args.A[1].A);
            Assert.AreEqual(56, res.Args.A[1].B);

            Assert.AreEqual(59, res.Args.L[0].A);
            Assert.AreEqual(84, res.Args.L[0].B);

            Assert.AreEqual(58, res.Args.L[1].A);
            Assert.AreEqual(81, res.Args.L[1].B);
        }
예제 #25
0
        public void TestFull()
        {
            var p = new CmdArgsParser <FluidBaseConf>();
            Res <FluidBaseConf> r = p.ParseCommandLine(new[]
            {
                "--labels=bus_data OR bus_longtime_data",
                "--defaultsFile=core/liquibase_CIS-DB.CIS_custom.properties",
                "--contexts=Light,prod, sync_prod,sync",
                "--logLevel=info",
                "--ConnectionString=jdbc:sqlserver://test02;databaseName=CityExpressDB_ceapp_developers;integratedSecurity=true;applicationName=liquibase;",
                "--username=liquibaseuser",
                "--password=gfhjkm",
                "--changeLogFile=CityExpressDB/#db.changelog-master_OnlyScheme.xml",

                "-DSOURCE_SERVER.DB=TEST02.CityExpressDB_ceapp_developers",
                "-DSOURCE_SERVER.APP=192.168.54.26",

                "update"
            });

            CheckFull(r);
        }
        public void TestNotLetter()
        {
            var p = new CmdArgsParser <ConfNotLetter>();

            Assert.Throws <ConfException>(() => p.ParseCommandLine(new[] { "-s" }));
        }
        public void TestConfWrongShort()
        {
            var p = new CmdArgsParser <ConfManyShort>();

            Assert.Throws <ConfException>(() => p.ParseCommandLine(new[] { "-s" }));
        }
예제 #28
0
        public void TestAllowedNo()
        {
            var p = new CmdArgsParser <ConfAllowed>();

            Assert.Throws <CmdException>(() => p.ParseCommandLine(new[] { "-p", "1:5" }));
        }
예제 #29
0
        public void TestDefTypeNotMatch()
        {
            var p = new CmdArgsParser <ConfDefTypeNotMatch>();

            Assert.Throws <ConfException>(() => p.ParseCommandLine(new[] { "-s" }));
        }
예제 #30
0
        public void TestNoDefault()
        {
            var p = new CmdArgsParser <Conf>();

            Assert.Throws <CmdException>(() => p.ParseCommandLine(new[] { "-s" }));
        }