Exemplo n.º 1
0
        public void Parses_ULong_Argument()
        {
            var app = new Application("Test")
                      .Argument(new ValueArgument(typeof(ulong))
                                .SetShort("-n")
                                .SetName("number"));

            var result = app.Parse(new[] { "-n", "6" });

            Assert.IsTrue(result.number == 6UL);
            Assert.IsTrue(result.number.GetType() == typeof(ulong));
        }
Exemplo n.º 2
0
        public void Parses_String_Argument()
        {
            var app = new Application("Test")
                      .Argument(new ValueArgument(typeof(string))
                                .SetShort("-s")
                                .SetName("str"));

            var result = app.Parse(new[] { "-s", "test" });

            Assert.IsTrue(result.str == "test");
            Assert.IsTrue(result.str.GetType() == typeof(string));
        }
Exemplo n.º 3
0
        public void Parses_Guid_Argument()
        {
            var app = new Application("Test")
                      .Argument(new ValueArgument(typeof(Guid))
                                .SetShort("-g")
                                .SetName("guid"));

            var result = app.Parse(new[] { "-g", "25e5a2c8-a0ea-452c-809c-df288a4c444c" });

            Assert.IsTrue(result.guid == new Guid("25e5a2c8-a0ea-452c-809c-df288a4c444c"));
            Assert.IsTrue(result.guid.GetType() == typeof(Guid));
        }
Exemplo n.º 4
0
        public void Parses_Switch()
        {
            var app = new Application("Test")
                      .Argument(new Switch()
                                .SetShort("-k")
                                .SetName("kay"));

            var result = app.Parse(new[] { "-k" });

            Assert.IsTrue(result.kay == true);
            Assert.IsTrue(result.kay.GetType() == typeof(bool));
        }
Exemplo n.º 5
0
        public void Parses_SByte_Argument()
        {
            var app = new Application("Test")
                      .Argument(new ValueArgument(typeof(sbyte))
                                .SetShort("-b")
                                .SetName("byt"));

            var result = app.Parse(new[] { "-b", "6" });

            Assert.IsTrue(result.byt == (sbyte)6);
            Assert.IsTrue(result.byt.GetType() == typeof(sbyte));
        }
Exemplo n.º 6
0
        public void Parses_Char_Argument()
        {
            var app = new Application("Test")
                      .Argument(new ValueArgument(typeof(char))
                                .SetShort("-c")
                                .SetName("ch"));

            var result = app.Parse(new[] { "-c", "t" });

            Assert.IsTrue(result.ch == 't');
            Assert.IsTrue(result.ch.GetType() == typeof(char));
        }
Exemplo n.º 7
0
        public void Parses_Bool_Argument()
        {
            // I don't know why you would do this instead of a switch, but it should probably be handled.
            var app = new Application("Test")
                      .Argument(new ValueArgument(typeof(bool))
                                .SetShort("-b")
                                .SetName("boolean"));

            var result = app.Parse(new[] { "-b", "true" });

            Assert.IsTrue(result.boolean == true);
            Assert.IsTrue(result.boolean.GetType() == typeof(bool));
        }
Exemplo n.º 8
0
        public void Parses_DateTime_Argument()
        {
            // Uses the .NET DateTime.Parse method. Does not give a particular culture, so it should use the machine's culture.
            // This will probably go into the configuration object at some point so that it can be injected, so the test can pass in other cultures.
            var app = new Application("Test")
                      .Argument(new ValueArgument(typeof(DateTime))
                                .SetShort("-d")
                                .SetName("date"));

            var result = app.Parse(new[] { "-d", "11/9/2018" });

            Assert.IsTrue(result.date == new DateTime(2018, 11, 9));
            Assert.IsTrue(result.date.GetType() == typeof(DateTime));
        }
Exemplo n.º 9
0
        public void Parses_Multiple_Arguments_In_Order()
        {
            var app = new Application("Test")
                      .Argument(new ValueArgument(typeof(int))
                                .SetShort("-n")
                                .SetName("number"))
                      .Argument(new ValueArgument(typeof(double))
                                .SetShort("-d")
                                .SetName("dub"));

            var result = app.Parse(new[] { "-n", "6", "-d", "2.0" });

            Assert.IsTrue(result.number == 6);
            Assert.IsTrue(result.dub == 2.0);
        }
Exemplo n.º 10
0
        public void Parses_Two_Switches_With_One_Not_Passed()
        {
            var app = new Application("Test")
                      .Argument(new Switch()
                                .SetShort("-k")
                                .SetName("kay"))
                      .Argument(new Switch()
                                .SetShort("-t")
                                .SetName("tee"));

            var result = app.Parse(new[] { "-k" });

            Assert.IsTrue(result.kay == true);
            Assert.IsTrue(result.tee == false);
        }
Exemplo n.º 11
0
        public void Parses_Multiple_Arguments_With_Only_One_Passed()
        {
            var app = new Application("Test")
                      .Argument(new ValueArgument(typeof(int))
                                .SetShort("-n")
                                .SetName("number"))
                      .Argument(new ValueArgument(typeof(double))
                                .SetShort("-d")
                                .SetName("dub"));

            var result = app.Parse(new[] { "-n", "6" });

            Assert.IsTrue(result.number == 6);
            Assert.IsTrue(result.dub == default(double));
        }