private void AddFeature(string formattedLine, string label) { if (MakePreviousScenarioHookAFeatureHookHack) { MakePreviousScenarioHookAFeatureHook(); // undo previous scenario hook in scenarioHooks MakePreviousScenarioHookAFeatureHookHack = false; } // else no need to undo previous scenario hook lastFeature = new NodeFeature(GherkinParser.ParseNameWithLabel(formattedLine, label), featureHooks); features.Add(lastFeature); }
private void AddHook(string formattedLine) { hooksToAdd = GherkinParser.GetHooks(formattedLine); if (features.Count == 0) { AddDistinctHooksByName(featureHooks, hooksToAdd); AddDistinctHooksByName(scenarioHooks, hooksToAdd); } else { AddDistinctHooksByName(scenarioHooks, hooksToAdd); MakePreviousScenarioHookAFeatureHookHack = true; } }
private void AddStep(string formattedLine) { var tokens = GherkinParser.ParseOutStepAndParameters(formattedLine); if (tokens == null) // invalid gherkin step { lastStep = null; // so that any tables don't get added to the last valid step } else { lastStep = new NodeStep(tokens); lastScenario.Steps.Add(lastStep); } }
public List <NodeFeature> Load(string[] contents) { bool isBuildingExampleTable = false; bool isHeaderRow = false; // since we read top to bottom, sometimes we don't know if a hook is for the next scenario or a new feature foreach (string line in contents) { string formattedLine = line.Trim(); string label = GherkinParser.DetermineLabel(formattedLine); if (label != EnumNames.slim) { isBuildingExampleTable = false; // reset at start of new label other than slims } switch (label) { case EnumNames.hook: AddHook(formattedLine); break; case EnumNames.Feature: AddFeature(formattedLine, label); break; case EnumNames.Scenario: lastScenario = new NodeScenario(GherkinParser.ParseNameWithLabel(formattedLine, label), scenarioHooks); AddScenario(lastScenario); break; case EnumNames.ScenarioOutline: lastScenario = new NodeScenarioOutline(GherkinParser.ParseNameWithLabel(formattedLine, label), scenarioHooks); AddScenario(lastScenario); break; case EnumNames.Examples: isBuildingExampleTable = true; isHeaderRow = true; break; case EnumNames.Given: case EnumNames.When: case EnumNames.Then: case EnumNames.And: AddStep(formattedLine); break; case EnumNames.slim: if (isHeaderRow) { formattedLine = GherkinParser.RemoveWhiteSpace(formattedLine); } if (isBuildingExampleTable) { AddExampleRow(formattedLine); } else { AddTableRow(formattedLine); } isHeaderRow = false; break; default: // do nothing break; } } return(features); }