public IEnumerable <Feature> LoadFiles(IEnumerable <string> files) { var textParser = new GherkinScenarioParser(configuration); var features = new List <Feature>(); Feature feature = null; textParser.FeatureEvent += (s, e) => { feature = e.EventInfo; features.Add(e.EventInfo); }; textParser.ScenarioEvent += (s, e) => { if (feature == null) { feature = e.EventInfo.Feature; features.Add(feature); } }; foreach (var file in files) { feature = null; textParser.Parse(file); } return(features); }
private Tuple <List <GherkinParseEvent>, List <Feature> > Parse(string content) { var features = new List <Feature>(); var nBehaveConfiguration = NBehaveConfiguration.New.DontIsolateInAppDomain().SetDryRun(true); var gherkinScenarioParser = new GherkinScenarioParser(nBehaveConfiguration); gherkinScenarioParser.FeatureEvent += (s, e) => features.Add(e.EventInfo); var gherkinEventListener = new GherkinEventListener(); IListener listener = new CompositeGherkinListener(gherkinEventListener, gherkinScenarioParser); var newEvents = new List <GherkinParseEvent>(); var parser = new Parser(listener); try { parser.Scan(content); } catch (Exception e) { var match = new Regex(@"^Line: (?<lineNumber>\d+). (\w+\s*)+ '(?<lineText>.*)'$").Match(e.Message); if (match.Success && (e is ParseException)) { var line = int.Parse(match.Groups["lineNumber"].Value); var lineInFile = new LineInFile(line - 1); var text = match.Groups["lineText"].Value; var token = new Token(text, lineInFile); var error = new Token(e.Message, lineInFile); newEvents.Add(new GherkinParseEvent(GherkinTokenType.SyntaxError, token, error)); } } finally { newEvents.AddRange(ToZeroBasedLines(gherkinEventListener).ToList()); } return(new Tuple <List <GherkinParseEvent>, List <Feature> >(newEvents, features)); }
private IEnumerable <Feature> ParseFeatures(IEnumerable <string> featureFiles, NBehaveConfiguration configuration) { var features = new List <Feature>(); EventHandler <EventArgs <Feature> > featureStarted = (s, e) => features.Add(e.EventInfo); var parser = new GherkinScenarioParser(configuration); parser.FeatureEvent += featureStarted; foreach (var featureFile in featureFiles) { try { parser.Parse(featureFile); } catch (ParseException) { } } parser.FeatureEvent -= featureStarted; return(features); }