Beispiel #1
0
        public void Should_Return_Exception_Whern_Input_ErrorBool(string argsText)
        {
            string      schemaText = "l:bool p:int d:string";
            ArgsParser  argsArray  = ArgsTests.InitArgsParam(argsText, schemaText, out ArgsSchema argsSchema);
            SchemaInfo  info       = argsSchema.GetSchemaInfo("l");
            ObjectParse parse      = new BoolParse(info, argsArray, "l");

            Assert.Throws <ArgumentException>(() => parse.GetValue(), "-p:不是有效的bool类型!");
        }
Beispiel #2
0
        public void Should_Return_True_Whern_Input_Param(bool expectValue, string argsText)
        {
            string      schemaText = "l:bool p:int d:string";
            ArgsParser  argsArray  = ArgsTests.InitArgsParam(argsText, schemaText, out ArgsSchema argsSchema);
            SchemaInfo  info       = argsSchema.GetSchemaInfo("l");
            ObjectParse parse      = new BoolParse(info, argsArray, "l");

            Assert.AreEqual(expectValue, parse.GetValue());
        }
Beispiel #3
0
        public void Should_Return_Error_Whern_InitParse_By_StringSchema()
        {
            string      argsText   = "-l -p 8080 -d /usr/logs";
            string      schemaText = "l:bool p:int d:string";
            ArgsParser  argsArray  = ArgsTests.InitArgsParam(argsText, schemaText, out ArgsSchema argsSchema);
            SchemaInfo  info       = argsSchema.GetSchemaInfo("d");
            ObjectParse parse      = new IntParse(info, argsArray, "p");

            Assert.Throws <ArgumentException>(() => parse.GetValue(), "缺省值设置默认类型不是int类型");
        }
Beispiel #4
0
        public void Should_Return_IntList_Whern_Input_Param()
        {
            string      argsText    = "-g this,is,a,list -d 1,2,-3,5";
            string      schemaText  = "g:List<string> d:List<int>";
            ArgsParser  argsArray   = ArgsTests.InitArgsParam(argsText, schemaText, out ArgsSchema argsSchema);
            SchemaInfo  info        = argsSchema.GetSchemaInfo("d");
            ObjectParse parse       = new IntListParse(info, argsArray, "d");
            List <int>  expectValue = new List <int>()
            {
                1, 2, -3, 5
            };

            Assert.AreEqual(expectValue, parse.GetValue());
        }