From 9b7b8d8e03a275906d6806bef7587d60232fa27b Mon Sep 17 00:00:00 2001 From: Gaspar Nagy Date: Wed, 11 Nov 2009 16:18:16 +0100 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFfix=20usage=20feature=20language=20fro?= =?UTF-8?q?m=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Parser/SpecFlowGenerator.cs | 2 +- Parser/SpecFlowLangParser.cs | 12 +++--------- Reporting/ParserHelper.cs | 9 +++++---- Tests/ParserTests/SuccessfulGenerationTest.cs | 3 ++- Tests/ParserTests/SuccessfulParsingTest.cs | 3 ++- Tests/RuntimeTests/ExecutionTestBase.cs | 3 ++- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Parser/SpecFlowGenerator.cs b/Parser/SpecFlowGenerator.cs index e9e741dbf..5d06dc7df 100644 --- a/Parser/SpecFlowGenerator.cs +++ b/Parser/SpecFlowGenerator.cs @@ -24,7 +24,7 @@ public CodeCompileUnit GenerateTestFileCode(string featureFileName, string conte SpecFlowFeatureFile featureFile = GetFeatureFile(featureFileName); string targetNamespace = GetTargetNamespace(featureFile); - SpecFlowLangParser parser = new SpecFlowLangParser(); + SpecFlowLangParser parser = new SpecFlowLangParser(project.GeneratorConfiguration.FeatureLanguage); Feature feature = parser.Parse(new StringReader(content), featureFile.GetFullPath(project)); IUnitTestGeneratorProvider generatorProvider = CreateInstance(project.GeneratorConfiguration.GeneratorUnitTestProviderType); diff --git a/Parser/SpecFlowLangParser.cs b/Parser/SpecFlowLangParser.cs index 388179e23..21a18ef0d 100644 --- a/Parser/SpecFlowLangParser.cs +++ b/Parser/SpecFlowLangParser.cs @@ -2,9 +2,7 @@ using System.Globalization; using System.Linq; using System.Collections.Generic; -using System.Diagnostics; using System.IO; -using System.Text; using System.Text.RegularExpressions; using Antlr.Runtime; using Antlr.Runtime.Tree; @@ -15,11 +13,7 @@ namespace TechTalk.SpecFlow.Parser { public class SpecFlowLangParser { - private CultureInfo defaultLanguage; - - public SpecFlowLangParser() : this(new CultureInfo("en-US")) - { - } + private readonly CultureInfo defaultLanguage; public SpecFlowLangParser(CultureInfo defaultLanguage) { @@ -57,7 +51,7 @@ public Feature Parse(TextReader featureFileReader) throw new SpecFlowParserException("Invalid Gherkin file!", lexer.LexerErrors.Concat(parser.ParserErrors).ToArray()); } - var walker = new Grammar.SpecFlowLangWalker(new CommonTreeNodeStream(featureTree)); + var walker = new SpecFlowLangWalker(new CommonTreeNodeStream(featureTree)); Feature feature = walker.feature(); @@ -69,7 +63,7 @@ public Feature Parse(TextReader featureFileReader) return feature; } - static readonly Dictionary lexters = new Dictionary() + static readonly Dictionary lexters = new Dictionary { {new CultureInfo("en"), typeof(SpecFlowLangLexer_en)}, {new CultureInfo("de"), typeof(SpecFlowLangLexer_de)}, diff --git a/Reporting/ParserHelper.cs b/Reporting/ParserHelper.cs index 822c3eea8..43b3d6cad 100644 --- a/Reporting/ParserHelper.cs +++ b/Reporting/ParserHelper.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; -using System.Text; using TechTalk.SpecFlow.Parser; using TechTalk.SpecFlow.Parser.Configuration; using TechTalk.SpecFlow.Parser.SyntaxElements; @@ -13,15 +13,16 @@ static class ParserHelper { public static List GetParsedFeatures(SpecFlowProject specFlowProject) { - return GetParsedFeatures(specFlowProject.FeatureFiles.Select(ff => ff.GetFullPath(specFlowProject))); + return GetParsedFeatures(specFlowProject.FeatureFiles.Select(ff => ff.GetFullPath(specFlowProject)), + specFlowProject.GeneratorConfiguration.FeatureLanguage); } - public static List GetParsedFeatures(IEnumerable featureFiles) + public static List GetParsedFeatures(IEnumerable featureFiles, CultureInfo featureLanguage) { List parsedFeatures = new List(); foreach (var featureFile in featureFiles) { - SpecFlowLangParser parser = new SpecFlowLangParser(); + SpecFlowLangParser parser = new SpecFlowLangParser(featureLanguage); using (var reader = new StreamReader(featureFile)) { Feature feature = parser.Parse(reader, featureFile); diff --git a/Tests/ParserTests/SuccessfulGenerationTest.cs b/Tests/ParserTests/SuccessfulGenerationTest.cs index c1e4cbe03..69834bc4a 100644 --- a/Tests/ParserTests/SuccessfulGenerationTest.cs +++ b/Tests/ParserTests/SuccessfulGenerationTest.cs @@ -1,6 +1,7 @@ using System; using System.CodeDom.Compiler; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -128,7 +129,7 @@ public void CanGenerateMixedGWTFeature() public void CanGenerateFromFile(string fileName) { Console.WriteLine(fileName); - SpecFlowLangParser parser = new SpecFlowLangParser(); + SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo("en")); using (var reader = new StreamReader(fileName)) { Feature feature = parser.Parse(reader); diff --git a/Tests/ParserTests/SuccessfulParsingTest.cs b/Tests/ParserTests/SuccessfulParsingTest.cs index 51c36b1b9..d0b0f64b7 100644 --- a/Tests/ParserTests/SuccessfulParsingTest.cs +++ b/Tests/ParserTests/SuccessfulParsingTest.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.IO; using System.Linq; using System.Text; @@ -130,7 +131,7 @@ public void CanParseMixedGWTFeature() public void CanParseFile(string fileName) { Console.WriteLine(fileName); - SpecFlowLangParser parser = new SpecFlowLangParser(); + SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo("en")); using (var reader = new StreamReader(fileName)) { Feature feature = parser.Parse(reader); diff --git a/Tests/RuntimeTests/ExecutionTestBase.cs b/Tests/RuntimeTests/ExecutionTestBase.cs index f28690bbc..82212dea0 100644 --- a/Tests/RuntimeTests/ExecutionTestBase.cs +++ b/Tests/RuntimeTests/ExecutionTestBase.cs @@ -1,6 +1,7 @@ using System; using System.CodeDom.Compiler; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using Microsoft.CSharp; @@ -146,7 +147,7 @@ public void CanExecuteMixedGWTFeature() public void CanGenerateFromFile(string fileName) { Console.WriteLine(fileName); - SpecFlowLangParser parser = new SpecFlowLangParser(); + SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo("en")); using (var reader = new StreamReader(fileName)) { Feature feature = parser.Parse(reader);