Tests: add tests for MoGenerator and MoParser

This commit is contained in:
Stephane Delcroix 2012-08-23 15:28:43 +02:00
Родитель 877da47eed
Коммит 84dc89beea
3 изменённых файлов: 30 добавлений и 8 удалений

Просмотреть файл

@ -37,7 +37,7 @@ namespace Vernacular.Test
[TestFixture]
public class CatalogTests
{
private Dictionary<string, ParserResourceCatalog> catalogs = new Dictionary<string, ParserResourceCatalog> ();
private List<Tuple<string, ResourceCatalog>> catalogs = new List<Tuple<string, ResourceCatalog>> ();
[TestFixtureSetUp]
public void SetUp ()
@ -46,7 +46,14 @@ namespace Vernacular.Test
var parser = new PoParser ();
parser.Add (path);
var lang = Path.GetFileNameWithoutExtension (path);
catalogs.Add (lang, new ParserResourceCatalog (parser) { CurrentIsoLanguageCode = lang });
catalogs.Add (new Tuple<string, ResourceCatalog> (lang, new ParserResourceCatalog (parser) { CurrentIsoLanguageCode = lang }));
}
(new GeneratorTests ()).TestMoGenerator ();
foreach (var path in Directory.GetFiles ("../../Catalog", "*.mo")) {
var lang = Path.GetFileNameWithoutExtension (path);
var catalog = new MoCatalog (File.Open (path, FileMode.Open)) { CurrentIsoLanguageCode = lang };
catalogs.Add(new Tuple<string, ResourceCatalog> (lang, catalog));
}
}
@ -65,8 +72,8 @@ namespace Vernacular.Test
private void ForEachCatalog (Action<string> action)
{
foreach (var catalog in catalogs) {
Catalog.Implementation = catalog.Value;
action (catalog.Key);
Catalog.Implementation = catalog.Item2;
action (catalog.Item1);
}
}

Просмотреть файл

@ -46,5 +46,15 @@ namespace Vernacular.Test
}
generator.Generate ("../../Catalog/en_US.pot");
}
[Test]
public void TestMoGenerator ()
{
var generator = new MoGenerator ();
foreach (var unit in ParserTests.ParsePo ("../../Catalog/ga.po") ) {
generator.Add (unit);
}
generator.Generate ("../../Catalog/ga.mo");
}
}
}

Просмотреть файл

@ -45,6 +45,13 @@ namespace Vernacular.Test
return new List<ILocalizationUnit> (asm_parser.Parse ());
}
public static List<ILocalizationUnit> ParsePo (string po_file)
{
var po_parser = new PoParser ();
po_parser.Add (po_file);
return new List<ILocalizationUnit> (po_parser.Parse ());
}
[Test]
public void TestParseAssembly ()
{
@ -54,9 +61,7 @@ namespace Vernacular.Test
[Test]
public void TestParsePo ()
{
var po_parser = new PoParser ();
po_parser.Add ("../../Catalog/en_US.pot");
AssertUnits (new List<ILocalizationUnit> (po_parser.Parse ()));
AssertUnits (ParsePo ("../../Catalog/en_US.pot"));
}
private void AssertUnits (List<ILocalizationUnit> units)
@ -133,4 +138,4 @@ namespace Vernacular.Test
Assert.AreEqual (1, gp_n_count, "gp_n_count");
}
}
}
}