Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library message_extraction_test; | |
| 6 | |
| 7 import 'package:scheduled_test/scheduled_test.dart'; | |
| 8 import 'dart:io'; | |
| 9 import 'package:pathos/path.dart' as path; | |
| 10 import '../data_directory.dart'; | |
| 11 | |
| 12 final dart = new Options().executable; | |
| 13 | |
| 14 dir([String s]) => path.join(intlDirectory, 'test', 'message_extraction', s); | |
| 15 | |
| 16 main() { | |
| 17 test("Test round trip message generation, printing, and ", () { | |
| 18 deleteGeneratedFiles(); | |
| 19 schedule(extractMessages); | |
| 20 schedule(generateTranslationFiles); | |
| 21 schedule(generateCodeFromTranslation); | |
| 22 var results = schedule(runGeneratedCode); | |
| 23 results.then(verifyResult); | |
| 24 }); | |
| 25 } | |
| 26 | |
| 27 deleteGeneratedFiles() { | |
| 28 var files = [dir('intl_messages.json'), dir('translation_fr.json'), | |
| 29 dir('messages_fr.dart'), dir('message_de_DE.dart'), | |
| 30 dir('messages_all.dart')]; | |
| 31 files.map((name) => new File(name)).forEach((x) { | |
| 32 if (x.existsSync()) x.deleteSync();}); | |
| 33 } | |
| 34 | |
| 35 | |
| 36 /** | |
| 37 * Set an environment variable for where we want to put the output. In | |
| 38 * normal circumstances we expect that to be the working directory, but that | |
| 39 * doesn't work with the Dart test infrastructure, which always wants to run | |
| 40 * in the top-level dart directory. The other programs in this directory will | |
| 41 * check this variable and save their output there if it is set. | |
| 42 */ | |
| 43 final options = new ProcessOptions()..environment = | |
| 44 {"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.
| |
| 45 | |
| 46 /** | |
| 47 * Run the process with the given list of filenames, which we assume | |
| 48 * are in dir() and need to be qualified in case that's not our working | |
| 49 * directory. | |
| 50 */ | |
| 51 run(List<String> filenames) { | |
| 52 var filesInTheRightDirectory = filenames.map((x) => dir(x)).toList(); | |
| 53 return Process.run(dart, filesInTheRightDirectory, options); | |
| 54 } | |
| 55 | |
| 56 extractMessages() => run( | |
| 57 ['extract_to_json.dart', 'sample_with_messages.dart', | |
| 58 'part_of_sample_with_messages.dart']); | |
| 59 | |
| 60 generateTranslationFiles() => run( | |
| 61 ['make_hardcoded_translation.dart', 'intl_messages.json']); | |
| 62 | |
| 63 generateCodeFromTranslation() => run( | |
| 64 ['generate_from_json.dart', 'sample_with_messages.dart', | |
| 65 'part_of_sample_with_messages.dart', 'translation_fr.json', | |
| 66 'translation_de_DE.json' ]); | |
| 67 | |
| 68 runGeneratedCode() => run(['sample_with_messages.dart']); | |
| 69 | |
| 70 verifyResult(results) { | |
| 71 var lineIterator; | |
| 72 verify(String s) { | |
| 73 lineIterator.moveNext(); | |
| 74 var value = lineIterator.current; | |
| 75 expect(value, s); | |
| 76 } | |
| 77 | |
| 78 var output = results.stdout; | |
| 79 var lines = output.split("\n"); | |
| 80 lineIterator = lines.iterator..moveNext(); | |
| 81 verify("Printing messages for en_US"); | |
| 82 verify("This is a message"); | |
| 83 verify("Another message with parameter hello"); | |
| 84 verify("Characters that need escaping, e.g slashes \\ dollars \${ " | |
| 85 "(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.
| |
| 86 " 1, 2, and 3"); | |
| 87 verify("This string extends across multiple lines."); | |
| 88 verify("1, b, [c, d]"); | |
| 89 verify('"So-called"'); | |
| 90 verify("Cette chaîne est toujours traduit"); | |
| 91 verify("Interpolation is tricky when it ends a sentence like this."); | |
| 92 verify("This comes from a method"); | |
| 93 verify("This method is not a lambda"); | |
| 94 verify("This comes from a static method"); | |
| 95 verify("This is missing some translations"); | |
| 96 verify("Ancient Greek hangman characters: 𐅆𐅇."); | |
| 97 // 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
| |
| 98 // verify("One of the tricky things is the plural form"); | |
| 99 // verify("One of the tricky things is plural forms"); | |
| 100 verify("Escapable characters here: "); | |
| 101 | |
| 102 var fr_lines = lines.skip(1).skipWhile( | |
| 103 (line) => !line.contains('----')).toList(); | |
| 104 lineIterator = fr_lines.iterator..moveNext(); | |
| 105 verify("Printing messages for fr"); | |
| 106 verify("Il s'agit d'un message"); | |
| 107 verify("Un autre message avec un seul paramètre hello"); | |
| 108 verify( | |
| 109 "Caractères qui doivent être échapper, par exemple barres \\ " | |
| 110 "dollars \${ (les accolades sont ok), et xml/html réservés <& et " | |
| 111 "des citations \" " | |
| 112 "avec quelques paramètres ainsi 1, 2, et 3"); | |
| 113 verify("Cette message prend plusiers lignes."); | |
| 114 verify("1, b, [c, d]"); | |
| 115 verify('"Soi-disant"'); | |
| 116 verify("Cette chaîne est toujours traduit"); | |
| 117 verify( | |
| 118 "L'interpolation est délicate quand elle se termine une " | |
| 119 "phrase comme this."); | |
| 120 verify("Cela vient d'une méthode"); | |
| 121 verify("Cette méthode n'est pas un lambda"); | |
| 122 verify("Cela vient d'une méthode statique"); | |
| 123 verify("Ce manque certaines traductions"); | |
| 124 verify("Anciens caractères grecs jeux du pendu: 𐅆𐅇."); | |
| 125 // verify("La chose est, well"); | |
| 126 // verify("Une des choses difficiles est la forme plurielle"); | |
| 127 // verify("Une des choses difficiles est les formes plurielles"); | |
| 128 verify("Escapes: "); | |
| 129 verify("\r\f\b\t\v."); | |
| 130 | |
| 131 | |
| 132 var de_lines = fr_lines.skip(1).skipWhile( | |
| 133 (line) => !line.contains('----')).toList(); | |
| 134 lineIterator = de_lines.iterator..moveNext(); | |
| 135 verify("Printing messages for de_DE"); | |
| 136 verify("Dies ist eine Nachricht"); | |
| 137 verify("Eine weitere Meldung mit dem Parameter hello"); | |
| 138 verify( | |
| 139 "Zeichen, die Flucht benötigen, zB Schrägstriche \\ Dollar " | |
| 140 "\${ (geschweiften Klammern sind ok) und xml reservierte Zeichen <& und " | |
| 141 "Zitate \" Parameter 1, 2 und 3"); | |
| 142 verify("Dieser String erstreckt sich über mehrere " | |
| 143 "Zeilen erstrecken."); | |
| 144 verify("1, b, [c, d]"); | |
| 145 verify('"Sogenannt"'); | |
| 146 // This is correct, the message is forced to French, even in a German locale. | |
| 147 verify("Cette chaîne est toujours traduit"); | |
| 148 verify( | |
| 149 "Interpolation ist schwierig, wenn es einen Satz wie dieser endet this."); | |
| 150 verify("Dies ergibt sich aus einer Methode"); | |
| 151 verify("Diese Methode ist nicht eine Lambda"); | |
| 152 verify("Dies ergibt sich aus einer statischen Methode"); | |
| 153 verify("This is missing some translations"); | |
| 154 verify("Antike griechische Galgenmännchen Zeichen: 𐅆𐅇"); | |
| 155 // verify("Die Sache ist, well"); | |
| 156 // expect("Einer der knifflige Dinge ist der Plural"); | |
| 157 // expect("Zu den kniffligen Dinge Pluralformen"); | |
| 158 verify("Escapes: "); | |
| 159 verify("\r\f\b\t\v."); | |
| 160 } | |
| OLD | NEW |