How to use new method of Gherkin.Specs.CLI.PrintEventsArgs class

Best Gherkin-dotnet code snippet using Gherkin.Specs.CLI.PrintEventsArgs.new

Run Gherkin-dotnet automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Program.cs

Source: Program.cs Github

copy
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using Gherkin.CucumberMessages;
5using Gherkin.Specs.EventStubs;
6using Gherkin.Specs.Tokens;
7using Utf8Json.Resolvers;
8
9namespace Gherkin.Specs.CLI
10{
11    class Program
12    {
13        static int Main(string[] argv)
14        {
15            if (argv.Length == 0)
16            {
17                ShowUsage();
18                return 100;
19            }
20
21            switch (argv[0].ToLowerInvariant())
22            {
23                case "tokens":
24                    return PrintTokens(argv.Skip(1));
25                case "events":
26                    var printEventArgs = GetPrintEventsArgs(argv.Skip(1));
27                    return PrintEvents(printEventArgs);
28                default:
29                    ShowUsage();
30                    return 110;
31            }
32        }
33
34        private static void ShowUsage()
35        {
36            Console.WriteLine(@"Usage: 
37    dotnet Gherkin.Specs events [--no-source] [--no-ast] [--no-pickles] feature-file.feature
38    - or -
39    dotnet Gherkin.Specs tokens feature-file.feature
40");
41        }
42
43        class PrintEventsArgs
44        {
45            public bool PrintSource { get; set; } = true;
46            public bool PrintAst { get; set; } = true;
47            public bool PrintPickles { get; set; } = true;
48            public List<string> Paths { get; } = new();
49        }
50
51        private static PrintEventsArgs GetPrintEventsArgs(IEnumerable<string> args)
52        {
53            var result = new PrintEventsArgs();
54
55            foreach (string arg in args)
56            {
57                switch (arg)
58                {
59                    case "--no-source":
60                        result.PrintSource = false;
61                        break;
62                    case "--no-ast":
63                        result.PrintAst = false;
64                        break;
65                    case "--no-pickles":
66                        result.PrintPickles = false;
67                        break;
68                    default:
69                        result.Paths.Add(arg);
70                        break;
71                }
72            }
73
74            return result;
75        }
76
77        private static int PrintTokens(IEnumerable<string> paths)
78        {
79            foreach (var featureFilePath in paths)
80            {
81                try
82                {
83                    var tokensText = TokensGenerator.GenerateTokens(featureFilePath);
84                    Console.WriteLine(tokensText);
85                }
86                catch (Exception ex)
87                {
88                    Console.Error.WriteLine(ex.Message);
89                    return 1;
90                }
91            }
92
93            return 0;
94        }
95
96        private static int PrintEvents(PrintEventsArgs args)
97        {
98            var sourceProvider = new SourceProvider();
99            var sources = sourceProvider.GetSources(args.Paths);
100            var gherkinEventsProvider = new GherkinEventsProvider(args.PrintSource, args.PrintAst, args.PrintPickles, new IncrementingIdGenerator());
101            foreach (var sourceEventEvent in sources)
102            {
103                foreach (var evt in gherkinEventsProvider.GetEvents(sourceEventEvent))
104                {
105                    var jsonString = Utf8Json.JsonSerializer.ToJsonString((object)evt, StandardResolver.ExcludeNullCamelCase);
106                    Console.WriteLine(jsonString);
107                }
108            }
109            return 0;
110        }
111    }
112}
113
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in PrintEventsArgs

Trigger new code on LambdaTest Cloud Grid

Execute automation tests with new on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)