当前位置: 首页>>代码示例>>C#>>正文


C# Parser.Run方法代码示例

本文整理汇总了C#中Parser.Run方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.Run方法的具体用法?C# Parser.Run怎么用?C# Parser.Run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parser的用法示例。


在下文中一共展示了Parser.Run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MultiParser_Run_HappyFlow_1

        public void MultiParser_Run_HappyFlow_1()
        {
            var mock = new MethodInvokerMock();

            var called = false;

            mock.Action = (method, obj, parameters) =>
            {
                called = true;

                Assert.IsTrue(method.Name == "Print");
                Assert.IsTrue(method.DeclaringType == typeof(Sample_02));
                Assert.IsTrue(parameters.Contains(10));
                Assert.IsTrue(parameters.Contains("aaa"));
            };

            MethodInvoker.Invoker = mock;

            var p = new Parser<Sample_02, Sample_03>();

            p.Run(new[]
            {
                "sample_02.print",
                "-c=10",
                "-prefix=aaa",
            }, new Sample_02(), new Sample_03());

            Assert.IsTrue(called);
        }
开发者ID:serra,项目名称:CLAP,代码行数:29,代码来源:MultiParserTests.cs

示例2: Main

		static void Main(string[] args)
		{
			LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter();
			var parser = new Parser<BootstrapperConsole>();
			parser.Register.EmptyHelpHandler(HandleEmpty);
			parser.Register.ErrorHandler(HandleError);
			parser.Run(args, new BootstrapperConsole());
		}
开发者ID:artikh,项目名称:CouchDude.Bootstrapper,代码行数:8,代码来源:Program.cs

示例3: TestMatchPrimitives

 public void TestMatchPrimitives() {
     {
         var q = new LiteralAnyCharOf("0123456789");
         {
             var parser = new Parser(q, TextCursor.Create("7"));
             var r = parser.Run();
             Assert.IsNotNull(r);
             Assert.AreEqual(1, r.Cursor.Position);
             Assert.AreEqual('7', r.Value);
         }
         {
             var parser = new Parser(q, TextCursor.Create("78"));
             var r = parser.Run();
             Assert.IsNotNull(r);
             Assert.AreEqual(1, r.Cursor.Position);
             Assert.AreEqual('7', r.Value);
         }
     }
     {
         var q = new Literal('z');
         {
             var parser = new Parser(q, TextCursor.Create("z"));
             var r = parser.Run();
             Assert.IsNotNull(r);
             Assert.IsNull(parser.FailCursor);
             Assert.AreEqual(1, r.Cursor.Position);
             Assert.AreEqual('z', r.Value);
         }
         {
             var parser = new Parser(q, TextCursor.Create("0123"));
             var r = parser.Run();
             Assert.IsNull(r);
             Assert.IsNotNull(parser.FailCursor);
             Assert.AreEqual(0, parser.FailCursor.Position);
         }
     }
     {
         var q = new LiteralEOI();
         {
             var parser = new Parser(q, TextCursor.Create(""));
             var r = parser.Run();
             Assert.IsNotNull(r);
             Assert.IsNull(parser.FailCursor);
             Assert.AreEqual(0, r.Cursor.Position);
             Assert.IsTrue(!r.Cursor.CanPop());
             Assert.AreEqual(null, r.Value);
         }
         {
             var parser = new Parser(q, TextCursor.Create("0123"));
             var r = parser.Run();
             Assert.IsNull(r);
             Assert.IsNotNull(parser.FailCursor);
             Assert.AreEqual(0, parser.FailCursor.Position);
         }
     }
 }
开发者ID:kael-ip,项目名称:DyPa,代码行数:56,代码来源:Tests.cs

示例4: Main

        static void Main(string[] args)
        {
            Tracer.Initialize(new TracerManager());

            AppDomain.CurrentDomain.UnhandledException += OnDomainUnhandledException;
            System.Threading.Tasks.TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;

            var parser = new Parser<App>();
            parser.Register.ErrorHandler(e => Console.WriteLine(e.Exception.Message));

            parser.Run(args, new App());

            //Parser.Run(args, new App());

            #if DEBUG
            Console.ReadLine();
            #endif
        }
开发者ID:kzu,项目名称:OctoFlow,代码行数:18,代码来源:Program.cs

示例5: Execute_HandleError_Registered_UnhandledParameters

        public void Execute_HandleError_Registered_UnhandledParameters()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_02 { Printer = mock.Object };

            var p = new Parser<Sample_02>();

            var handled = false;

            p.Register.ErrorHandler(ex =>
            {
                handled = true;
            });

            p.Run(new[]
            {
                "-count:1",
                "-message:a",
                "-prefix:p",
                "-upper",
                "-what:x"
            }, sample);

            Expect(handled, Is.True);
        }
开发者ID:serra,项目名称:CLAP,代码行数:25,代码来源:Tests.cs

示例6: Empty_Defined_Static_TargetNotNull_Exception

        public void Empty_Defined_Static_TargetNotNull_Exception()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_14 { Printer = mock.Object };

            var p = new Parser<Sample_14>();

            Expect(() => p.Run(new string[] {}, sample),
                   Throws.InstanceOf<ParserExecutionTargetException>());
        }
开发者ID:serra,项目名称:CLAP,代码行数:10,代码来源:Tests.cs

示例7: EmptyHandler_NonStatic_CalledWhenNoArgs

        public void EmptyHandler_NonStatic_CalledWhenNoArgs()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_09 { Printer = mock.Object };

            var p = new Parser<Sample_09>();

            p.Run(new string[] { }, sample);

            mock.Verify(o => o.Print("a"));
        }
开发者ID:serra,项目名称:CLAP,代码行数:11,代码来源:Tests.cs

示例8: RegisterParameterHandler_CallsTheHandler_UseTheValue

        public void RegisterParameterHandler_CallsTheHandler_UseTheValue()
        {
            var printer = new Printer();
            var sample = new Sample_02 { Printer = printer };

            var debug = String.Empty;

            var p = new Parser<Sample_02>();
            p.Register.ParameterHandler<string>("debug", str => debug = str);

            p.Run("print /c=5 /msg=test /prefix=hello_ /debug=true".Split(' '), sample);

            Expect(debug, Is.EqualTo("true"));
        }
开发者ID:serra,项目名称:CLAP,代码行数:14,代码来源:Tests.cs

示例9: Interception_Registered_Called

        public void Interception_Registered_Called()
        {
            var printer = new Printer();
            var sample = new Sample_02 { Printer = printer };

            var p = new Parser<Sample_02>();

            var preInterceptorCalled = false;
            var postInterceptorCalled = false;

            p.Register.PreVerbInterceptor(c => preInterceptorCalled = true);
            p.Register.PostVerbInterceptor(c => postInterceptorCalled = true);

            p.Run(new[]
            {
                "print",
                "/c=5",
                "/msg=test",
                "/prefix=hello_",
            }, sample);

            Assert.AreEqual(5, printer.PrintedTexts.Count);
            Assert.IsTrue(printer.PrintedTexts.All(t => t.Equals("hello_test")));

            Assert.IsTrue(preInterceptorCalled);
            Assert.IsTrue(postInterceptorCalled);
        }
开发者ID:serra,项目名称:CLAP,代码行数:27,代码来源:Tests.cs

示例10: Help_Static_CalledWithTarget_Exception

        public void Help_Static_CalledWithTarget_Exception()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_22 { Printer = mock.Object };

            var p = new Parser<Sample_22>();

            p.Run(new[] { "-?" }, sample);
        }
开发者ID:serra,项目名称:CLAP,代码行数:9,代码来源:Tests.cs

示例11: Help_MoreThanOneParameter_Exception

        public void Help_MoreThanOneParameter_Exception()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_24 { Printer = mock.Object };

            var p = new Parser<Sample_24>();

            p.Run(new[] { "-?" }, sample);
        }
开发者ID:kurtaj,项目名称:CLAP,代码行数:9,代码来源:Tests.cs

示例12: Global_Defined_MoreThanOneParameter_Exception

        public void Global_Defined_MoreThanOneParameter_Exception()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_12 { Printer = mock.Object };

            var p = new Parser<Sample_12>();

            p.Run("print -foo".Split(' '), sample);
        }
开发者ID:kurtaj,项目名称:CLAP,代码行数:9,代码来源:Tests.cs

示例13: Global_Defined_BadConvertion

        public void Global_Defined_BadConvertion()
        {
            var mock = new Mock<IPrinter>();
            var sample = new Sample_10 { Printer = mock.Object };

            var p = new Parser<Sample_10>();

            p.Run("print -abra:cadabra".Split(' '), sample);
        }
开发者ID:kurtaj,项目名称:CLAP,代码行数:9,代码来源:Tests.cs

示例14: Execute_HandleError_Registered_Rethrow

        public void Execute_HandleError_Registered_Rethrow()
        {
            var p = new Parser<Sample_39>();
            var handled = false;

            p.RegisterErrorHandler(ex =>
            {
                handled = true;
            }, true);

            try
            {
                p.Run(new string[] { });

                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.IsTrue(handled);
            }
        }
开发者ID:kurtaj,项目名称:CLAP,代码行数:21,代码来源:Tests.cs

示例15: Execute_HandleError_Registered_NoRethrow

        public void Execute_HandleError_Registered_NoRethrow()
        {
            var p = new Parser<Sample_39>();
            var handled = false;

            p.RegisterErrorHandler(ex =>
            {
                handled = true;
            }, false);

            p.Run(new string[] { });

            Assert.IsTrue(handled);
        }
开发者ID:kurtaj,项目名称:CLAP,代码行数:14,代码来源:Tests.cs


注:本文中的Parser.Run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。