Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Unified Diff: pkg/intl/test/message_extraction/message_extraction_test.dart

Issue 12733003: Adds facilities for extracting Intl.message calls and generating code from translations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/intl/test/message_extraction/message_extraction_test.dart
diff --git a/pkg/intl/test/message_extraction/message_extraction_test.dart b/pkg/intl/test/message_extraction/message_extraction_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e7bb27b648b87eb33e7bfab0af9442bc6f47c41d
--- /dev/null
+++ b/pkg/intl/test/message_extraction/message_extraction_test.dart
@@ -0,0 +1,160 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library message_extraction_test;
+
+import 'package:scheduled_test/scheduled_test.dart';
+import 'dart:io';
+import 'package:pathos/path.dart' as path;
+import '../data_directory.dart';
+
+final dart = new Options().executable;
+
+dir([String s]) => path.join(intlDirectory, 'test', 'message_extraction', s);
+
+main() {
+ test("Test round trip message generation, printing, and ", () {
+ deleteGeneratedFiles();
+ schedule(extractMessages);
+ schedule(generateTranslationFiles);
+ schedule(generateCodeFromTranslation);
+ var results = schedule(runGeneratedCode);
+ results.then(verifyResult);
+ });
+}
+
+deleteGeneratedFiles() {
+ var files = [dir('intl_messages.json'), dir('translation_fr.json'),
+ dir('messages_fr.dart'), dir('message_de_DE.dart'),
+ dir('messages_all.dart')];
+ files.map((name) => new File(name)).forEach((x) {
+ if (x.existsSync()) x.deleteSync();});
+}
+
+
+/**
+ * Set an environment variable for where we want to put the output. In
+ * normal circumstances we expect that to be the working directory, but that
+ * doesn't work with the Dart test infrastructure, which always wants to run
+ * in the top-level dart directory. The other programs in this directory will
+ * check this variable and save their output there if it is set.
+ */
+final options = new ProcessOptions()..environment =
+ {"INTL_MESSAGE_OUTPUT" : dir()};
Emily Fortuna 2013/03/13 18:54:43 can this be a command line argument instead? (and
Alan Knight 2013/03/14 17:49:05 Done.
+
+/**
+ * Run the process with the given list of filenames, which we assume
+ * are in dir() and need to be qualified in case that's not our working
+ * directory.
+ */
+run(List<String> filenames) {
+ var filesInTheRightDirectory = filenames.map((x) => dir(x)).toList();
+ return Process.run(dart, filesInTheRightDirectory, options);
+}
+
+extractMessages() => run(
+ ['extract_to_json.dart', 'sample_with_messages.dart',
+ 'part_of_sample_with_messages.dart']);
+
+generateTranslationFiles() => run(
+ ['make_hardcoded_translation.dart', 'intl_messages.json']);
+
+generateCodeFromTranslation() => run(
+ ['generate_from_json.dart', 'sample_with_messages.dart',
+ 'part_of_sample_with_messages.dart', 'translation_fr.json',
+ 'translation_de_DE.json' ]);
+
+runGeneratedCode() => run(['sample_with_messages.dart']);
+
+verifyResult(results) {
+ var lineIterator;
+ verify(String s) {
+ lineIterator.moveNext();
+ var value = lineIterator.current;
+ expect(value, s);
+ }
+
+ var output = results.stdout;
+ var lines = output.split("\n");
+ lineIterator = lines.iterator..moveNext();
+ verify("Printing messages for en_US");
+ verify("This is a message");
+ verify("Another message with parameter hello");
+ verify("Characters that need escaping, e.g slashes \\ dollars \${ "
+"(curly braces are ok) and xml reserved characters <& and quotes \" parameters"
Emily Fortuna 2013/03/13 18:54:43 indentation
Alan Knight 2013/03/14 17:49:05 Done.
+" 1, 2, and 3");
+ verify("This string extends across multiple lines.");
+ verify("1, b, [c, d]");
+ verify('"So-called"');
+ verify("Cette chaîne est toujours traduit");
+ verify("Interpolation is tricky when it ends a sentence like this.");
+ verify("This comes from a method");
+ verify("This method is not a lambda");
+ verify("This comes from a static method");
+ verify("This is missing some translations");
+ verify("Ancient Greek hangman characters: 𐅆𐅇.");
+// verify("The thing is, well");
Emily Fortuna 2013/03/13 18:54:43 why are these commented out?
Alan Knight 2013/03/14 17:49:05 They test plurals and named arguments. I wrote the
+// verify("One of the tricky things is the plural form");
+// verify("One of the tricky things is plural forms");
+ verify("Escapable characters here: ");
+
+ var fr_lines = lines.skip(1).skipWhile(
+ (line) => !line.contains('----')).toList();
+ lineIterator = fr_lines.iterator..moveNext();
+ verify("Printing messages for fr");
+ verify("Il s'agit d'un message");
+ verify("Un autre message avec un seul paramètre hello");
+ verify(
+ "Caractères qui doivent être échapper, par exemple barres \\ "
+ "dollars \${ (les accolades sont ok), et xml/html réservés <& et "
+ "des citations \" "
+ "avec quelques paramètres ainsi 1, 2, et 3");
+ verify("Cette message prend plusiers lignes.");
+ verify("1, b, [c, d]");
+ verify('"Soi-disant"');
+ verify("Cette chaîne est toujours traduit");
+ verify(
+ "L'interpolation est délicate quand elle se termine une "
+ "phrase comme this.");
+ verify("Cela vient d'une méthode");
+ verify("Cette méthode n'est pas un lambda");
+ verify("Cela vient d'une méthode statique");
+ verify("Ce manque certaines traductions");
+ verify("Anciens caractères grecs jeux du pendu: 𐅆𐅇.");
+// verify("La chose est, well");
+// verify("Une des choses difficiles est la forme plurielle");
+// verify("Une des choses difficiles est les formes plurielles");
+ verify("Escapes: ");
+ verify("\r\f\b\t\v.");
+
+
+ var de_lines = fr_lines.skip(1).skipWhile(
+ (line) => !line.contains('----')).toList();
+ lineIterator = de_lines.iterator..moveNext();
+ verify("Printing messages for de_DE");
+ verify("Dies ist eine Nachricht");
+ verify("Eine weitere Meldung mit dem Parameter hello");
+ verify(
+ "Zeichen, die Flucht benötigen, zB Schrägstriche \\ Dollar "
+ "\${ (geschweiften Klammern sind ok) und xml reservierte Zeichen <& und "
+ "Zitate \" Parameter 1, 2 und 3");
+ verify("Dieser String erstreckt sich über mehrere "
+ "Zeilen erstrecken.");
+ verify("1, b, [c, d]");
+ verify('"Sogenannt"');
+ // This is correct, the message is forced to French, even in a German locale.
+ verify("Cette chaîne est toujours traduit");
+ verify(
+ "Interpolation ist schwierig, wenn es einen Satz wie dieser endet this.");
+ verify("Dies ergibt sich aus einer Methode");
+ verify("Diese Methode ist nicht eine Lambda");
+ verify("Dies ergibt sich aus einer statischen Methode");
+ verify("This is missing some translations");
+ verify("Antike griechische Galgenmännchen Zeichen: 𐅆𐅇");
+// verify("Die Sache ist, well");
+// expect("Einer der knifflige Dinge ist der Plural");
+// expect("Zu den kniffligen Dinge Pluralformen");
+ verify("Escapes: ");
+ verify("\r\f\b\t\v.");
+}

Powered by Google App Engine
This is Rietveld 408576698