Skip to content

Commit

Permalink
import Gherkin 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed Jun 15, 2010
1 parent 7b69438 commit 833613a
Show file tree
Hide file tree
Showing 24 changed files with 151 additions and 78 deletions.
1 change: 1 addition & 0 deletions Installer/ImportGherkinParser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private static void CreateSignedParser(string gherkinParserFullPath, Version ver
new Dictionary<string, string>()
{
{"se", "sv"},
{"lu", "lb-LU"},
};

private class KeywordTranslation
Expand Down
48 changes: 43 additions & 5 deletions Languages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,11 @@
<Scenario>Forgatókönyv</Scenario>
<ScenarioOutline>Forgatókönyv vázlat</ScenarioOutline>
<Examples>Példák</Examples>
<Given>Ha</Given>
<Given>Amennyiben</Given>
<Given>Adott</Given>
<When>Majd</When>
<When>Ha</When>
<When>Amikor</When>
<Then>Akkor</Then>
<And>És</And>
<But>De</But>
Expand Down Expand Up @@ -250,8 +253,11 @@
<Scenario>Forgatókönyv</Scenario>
<ScenarioOutline>Forgatókönyv vázlat</ScenarioOutline>
<Examples>Példák</Examples>
<Given>Ha</Given>
<Given>Amennyiben</Given>
<Given>Adott</Given>
<When>Majd</When>
<When>Ha</When>
<When>Amikor</When>
<Then>Akkor</Then>
<And>És</And>
<But>De</But>
Expand All @@ -262,8 +268,11 @@
<Scenario>Forgatókönyv</Scenario>
<ScenarioOutline>Forgatókönyv vázlat</ScenarioOutline>
<Examples>Példák</Examples>
<Given>Ha</Given>
<Given>Amennyiben</Given>
<Given>Adott</Given>
<When>Majd</When>
<When>Ha</When>
<When>Amikor</When>
<Then>Akkor</Then>
<And>És</And>
<But>De</But>
Expand Down Expand Up @@ -328,6 +337,20 @@
<And>Ir</And>
<But>Bet</But>
</Language>
<Language code="lb-LU" cultureInfo="lb-LU" compatibleGherkinCode="lu" englishName="Luxembourgish (Luxembourg)">
<Feature>Funktionalitéit</Feature>
<Background>Hannergrond</Background>
<Scenario>Szenario</Scenario>
<ScenarioOutline>Plang vum Szenario</ScenarioOutline>
<Examples>Beispiller</Examples>
<Given>ugeholl</Given>
<When>wann</When>
<Then>dann</Then>
<And>an</And>
<And>a</And>
<But>awer</But>
<But>mä</But>
</Language>
<Language code="lv" cultureInfo="lv" defaultSpecificCulture="lv-LV" englishName="Latvian">
<Feature>Funkcionalitāte</Feature>
<Feature>Fīča</Feature>
Expand Down Expand Up @@ -427,8 +450,12 @@
<ScenarioOutline>Структура сценария</ScenarioOutline>
<Examples>Значения</Examples>
<Given>Допустим</Given>
<Given>Дано</Given>
<Given>Пусть</Given>
<When>Если</When>
<When>Когда</When>
<Then>То</Then>
<Then>Тогда</Then>
<And>И</And>
<And>К тому же</And>
<But>Но</But>
Expand All @@ -452,8 +479,11 @@
<Scenario>Forgatókönyv</Scenario>
<ScenarioOutline>Forgatókönyv vázlat</ScenarioOutline>
<Examples>Példák</Examples>
<Given>Ha</Given>
<Given>Amennyiben</Given>
<Given>Adott</Given>
<When>Majd</When>
<When>Ha</When>
<When>Amikor</When>
<Then>Akkor</Then>
<And>És</And>
<But>De</But>
Expand All @@ -464,8 +494,11 @@
<Scenario>Forgatókönyv</Scenario>
<ScenarioOutline>Forgatókönyv vázlat</ScenarioOutline>
<Examples>Példák</Examples>
<Given>Ha</Given>
<Given>Amennyiben</Given>
<Given>Adott</Given>
<When>Majd</When>
<When>Ha</When>
<When>Amikor</When>
<Then>Akkor</Then>
<And>És</And>
<But>De</But>
Expand Down Expand Up @@ -504,9 +537,14 @@
<Given>Припустимо</Given>
<Given>Припустимо, що</Given>
<Given>Нехай</Given>
<Given>Дано</Given>
<When>Якщо</When>
<When>Коли</When>
<Then>То</Then>
<Then>Тоді</Then>
<And>І</And>
<And>А також</And>
<And>Та</And>
<But>Але</But>
</Language>
<Language code="uz" cultureInfo="uz" defaultSpecificCulture="uz-Cyrl-UZ" englishName="Uzbek">
Expand Down
4 changes: 2 additions & 2 deletions Parser/GherkinBuilder/BackgroundBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ internal class BackgroundBuilder : IStepProcessor
private readonly FilePosition position;
private readonly IList<StepBuilder> steps = new List<StepBuilder>();

public BackgroundBuilder(string text, FilePosition position)
public BackgroundBuilder(string name, string description, FilePosition position)
{
this.text = text;
this.text = TextHelper.GetText(name, description);
this.position = position;
}

Expand Down
4 changes: 2 additions & 2 deletions Parser/GherkinBuilder/ExampleBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ internal class ExampleBuilder : ITableProcessor
private readonly FilePosition position;
private readonly TableBuilder tableBuilder = new TableBuilder();

public ExampleBuilder(string text, FilePosition position)
public ExampleBuilder(string name, string description, FilePosition position)
{
this.text = text;
this.text = TextHelper.GetText(name, description);
this.position = position;
}

Expand Down
34 changes: 16 additions & 18 deletions Parser/GherkinBuilder/FeatureBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using TechTalk.SpecFlow.Parser.SyntaxElements;

namespace TechTalk.SpecFlow.Parser.GherkinBuilder
{
internal class FeatureBuilder
{
private readonly string text;
private readonly Tags tags;
private string title;
private string description;
private string sourceFilePath;
private Tags tags;
private readonly IList<IScenarioBuilder> scenarios = new List<IScenarioBuilder>();
private BackgroundBuilder background = null;

public FeatureBuilder(string text, Tags tags)
public string SourceFilePath
{
this.text = text;
this.tags = tags;
get { return sourceFilePath; }
set { sourceFilePath = value; }
}

private static readonly Regex firstLineRe = new Regex(@"^(?<firstline>[^\r\n]*)[\r\n]+(?<rest>.*)", RegexOptions.Singleline);
public void SetHeader(string title, string description, Tags tags)
{
this.title = title;
this.description = description;
this.tags = tags;
}

public Feature GetResult()
{
string title = text;
string description = null;

var match = firstLineRe.Match(text);
if (match.Success)
{
title = match.Groups["firstline"].Value;
description = match.Groups["rest"].Value;
}

return new Feature(
var feature = new Feature(
title,
tags,
description,
background == null ? null : background.GetResult(),
scenarios.Select(sb => sb.GetResult()).ToArray());
feature.SourceFile = sourceFilePath;
return feature;
}

public void AddScenario(IScenarioBuilder scenarioBuilder)
Expand Down
52 changes: 28 additions & 24 deletions Parser/GherkinBuilder/GherkinListener.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using gherkin;
using java.util;
Expand All @@ -13,7 +12,7 @@ internal class GherkinListener : Listener
{
public GherkinListener(I18n languageService)
{
_i18n = languageService;
i18n = languageService;
Errors = new List<ErrorDetail>();
}

Expand All @@ -32,7 +31,8 @@ public void RegisterError(ErrorDetail errorDetail)
Errors.Add(errorDetail);
}

private FeatureBuilder featureBuilder;
private readonly FeatureBuilder featureBuilder = new FeatureBuilder();

public Feature GetResult()
{
return featureBuilder.GetResult();
Expand All @@ -49,67 +49,72 @@ private Tags FlushTags()
private IStepProcessor stepProcessor;
private ITableProcessor tableProcessor;
private IExampleProcessor exampleProcessor;
private I18n _i18n;
private readonly I18n i18n;

public void tag(string name, int i)
{
string nameWithoutAt = name.Remove(0, 1);
tags.Add(new Tag(nameWithoutAt));
}

public void comment(string str, int i)
public void comment(string comment, int line)
{
}

public void location(string uri, int offset)
{
featureBuilder.SourceFilePath = uri;
}

public void feature(string keyword, string content, int line_number)
public void feature(string keyword, string name, string description, int line)
{
featureBuilder = new FeatureBuilder(content, FlushTags());
featureBuilder.SetHeader(name, description, FlushTags());
}

public void background(string keyword, string content, int line_number)
public void background(string keyword, string name, string description, int line)
{
var background = new BackgroundBuilder(content, new FilePosition(line_number, 1));
var background = new BackgroundBuilder(name, description, new FilePosition(line));
stepProcessor = background;
featureBuilder.AddBackground(background);
}

public void scenario(string keyword, string content, int line_number)
public void scenario(string keyword, string name, string description, int line)
{
var currentScenario = new ScenarioBuilder(content, FlushTags(), new FilePosition(line_number, 1));
var currentScenario = new ScenarioBuilder(name, description, FlushTags(), new FilePosition(line));
stepProcessor = currentScenario;
featureBuilder.AddScenario(currentScenario);
}

public void scenarioOutline(string keyword, string content, int line_number)
public void scenarioOutline(string keyword, string name, string description, int line)
{
var currentScenario = new ScenarioOutlineBuilder(content, FlushTags(), new FilePosition(line_number, 1));
var currentScenario = new ScenarioOutlineBuilder(name, description, FlushTags(), new FilePosition(line));
stepProcessor = currentScenario;
exampleProcessor = currentScenario;
featureBuilder.AddScenario(currentScenario);
}

public void examples(string keyword, string content, int line_number)
public void examples(string keyword, string name, string description, int line)
{
var exampleBuilder = new ExampleBuilder(content, new FilePosition(line_number, 1));
var exampleBuilder = new ExampleBuilder(name, description, new FilePosition(line));
tableProcessor = exampleBuilder;
exampleProcessor.ProcessExample(exampleBuilder);
}

public void step(string keyword, string content, int line_number)
public void step(string keyword, string text, int line)
{
stepBuilder = new StepBuilder(keyword, content, new FilePosition(line_number, 1), _i18n);
stepBuilder = new StepBuilder(keyword, text, new FilePosition(line), i18n);
tableProcessor = stepBuilder;
stepProcessor.ProcessStep(stepBuilder);
}

public void row(List list, int line_number)
public void row(List list, int line)
{
string[] rows = new string[list.size()];
list.toArray(rows);
tableProcessor.ProcessTableRow(rows, line_number);
tableProcessor.ProcessTableRow(rows, line);
}

public void pyString(string content, int line_number)
public void pyString(string content, int line)
{
stepBuilder.SetMultilineArg(content);
}
Expand All @@ -119,12 +124,11 @@ public void eof()

}

public void syntaxError(string str1, string str2, List l, int line_number)
public void syntaxError(string state, string eventName, List legalEvents, int line)
{
string message = "Parse error. Found " + str1 + " when expecting one of: " +
"TODO" + ". (Current state: " + str2 + ").";
string message = string.Format("Parser error on line {2}. State: {0}, Event: {1}", state, eventName, line);

RegisterError(line_number, null, message);
RegisterError(line, null, message);
}
}
}
8 changes: 4 additions & 4 deletions Parser/GherkinBuilder/ScenarioBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ namespace TechTalk.SpecFlow.Parser.GherkinBuilder
{
internal class ScenarioBuilder : IScenarioBuilder
{
private readonly string name;
private readonly string title;
private readonly FilePosition position;
private readonly Tags tags;
private readonly IList<StepBuilder> steps = new List<StepBuilder>();

public ScenarioBuilder(string name, Tags tags, FilePosition position)
public ScenarioBuilder(string name, string description, Tags tags, FilePosition position)
{
this.name = name;
this.title = TextHelper.GetText(name, description);
this.position = position;
this.tags = tags;
}
Expand All @@ -25,7 +25,7 @@ public void ProcessStep(StepBuilder step)

public Scenario GetResult()
{
return new Scenario(name, tags, new ScenarioSteps(steps.Select(s => s.GetResult()).ToArray())) { FilePosition = position };
return new Scenario(title, tags, new ScenarioSteps(steps.Select(s => s.GetResult()).ToArray())) { FilePosition = position };
}
}
}
8 changes: 4 additions & 4 deletions Parser/GherkinBuilder/ScenarioOutlineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace TechTalk.SpecFlow.Parser.GherkinBuilder
{
internal class ScenarioOutlineBuilder : IScenarioBuilder, IExampleProcessor
{
private readonly string name;
private readonly string title;
private readonly Tags tags;
private readonly FilePosition position;
private readonly IList<StepBuilder> steps = new List<StepBuilder>();
private readonly IList<ExampleBuilder> examples = new List<ExampleBuilder>();

public ScenarioOutlineBuilder(string name, Tags tags, FilePosition position)
public ScenarioOutlineBuilder(string name, string description, Tags tags, FilePosition position)
{
this.name = name;
this.title = TextHelper.GetText(name, description);
this.tags = tags;
this.position = position;
}
Expand All @@ -37,7 +37,7 @@ public Scenario GetResult()
});

return new ScenarioOutline(
name,
title,
tags,
new ScenarioSteps(steps.Select(step => step.GetResult()).ToArray()),
new Examples(examples.Select(example => example.GetResult()).ToArray())) { FilePosition = position };
Expand Down
Loading

0 comments on commit 833613a

Please sign in to comment.