| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library message_extraction_test; | 5 library message_extraction_test; |
| 6 | 6 |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:convert'; | 10 import 'dart:convert'; |
| 11 import 'package:path/path.dart' as path; | 11 import 'package:path/path.dart' as path; |
| 12 import '../data_directory.dart'; | 12 import '../data_directory.dart'; |
| 13 import 'verify_messages.dart'; |
| 14 import 'sample_with_messages.dart' as sample; |
| 13 | 15 |
| 14 final dart = Platform.executable; | 16 final dart = Platform.executable; |
| 15 | 17 |
| 16 /** The VM arguments we were given, most important package-root. */ | 18 /** The VM arguments we were given, most important package-root. */ |
| 17 final vmArgs = Platform.executableArguments; | 19 final vmArgs = Platform.executableArguments; |
| 18 | 20 |
| 19 /** | 21 /** |
| 20 * Translate a file path into this test directory, regardless of the | 22 * Translate a file path into this test directory, regardless of the |
| 21 * working directory. | 23 * working directory. |
| 22 */ | 24 */ |
| 23 String dir([String s]) { | 25 String dir([String s]) { |
| 24 if (s != null && s.startsWith("--")) { // Don't touch command-line options. | 26 if (s != null && s.startsWith("--")) { // Don't touch command-line options. |
| 25 return s; | 27 return s; |
| 26 } else { | 28 } else { |
| 27 return path.join(intlDirectory, 'test', 'message_extraction', s); | 29 return path.join(intlDirectory, 'test', 'message_extraction', s); |
| 28 } | 30 } |
| 29 } | 31 } |
| 30 | 32 |
| 31 main() { | 33 main() { |
| 32 test("Test round trip message extraction, translation, code generation, " | 34 test("Test round trip message extraction, translation, code generation, " |
| 33 "and printing", () { | 35 "and printing", () { |
| 34 deleteGeneratedFiles(); | 36 deleteGeneratedFiles(); |
| 35 return extractMessages(null).then((result) { | 37 return extractMessages(null).then((result) { |
| 36 return generateTranslationFiles(result); | 38 return generateTranslationFiles(result); |
| 37 }).then((result) { | 39 }).then((result) { |
| 38 return generateCodeFromTranslation(result); | 40 return generateCodeFromTranslation(result); |
| 39 }).then((result) { | 41 }).then((_) => sample.main()) |
| 40 return runGeneratedCode(result); | 42 .then(verifyResult) |
| 41 }).then(verifyResult) | |
| 42 .whenComplete(deleteGeneratedFiles); | 43 .whenComplete(deleteGeneratedFiles); |
| 43 }); | 44 }); |
| 44 } | 45 } |
| 45 | 46 |
| 46 void deleteGeneratedFiles() { | 47 void deleteGeneratedFiles() { |
| 47 var files = [dir('intl_messages.json'), dir('translation_fr.json'), | 48 var files = [dir('intl_messages.json'), dir('translation_fr.json'), |
| 48 dir('foo_messages_fr.dart'), dir('foo_messages_de_DE.dart'), | 49 dir('translation_de_DE.json')]; |
| 49 dir('translation_de_DE.json'), dir('foo_messages_all.dart')]; | |
| 50 files.map((name) => new File(name)).forEach((x) { | 50 files.map((name) => new File(name)).forEach((x) { |
| 51 if (x.existsSync()) x.deleteSync();}); | 51 if (x.existsSync()) x.deleteSync();}); |
| 52 } | 52 } |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * Run the process with the given list of filenames, which we assume | 55 * Run the process with the given list of filenames, which we assume |
| 56 * are in dir() and need to be qualified in case that's not our working | 56 * are in dir() and need to be qualified in case that's not our working |
| 57 * directory. | 57 * directory. |
| 58 */ | 58 */ |
| 59 Future<ProcessResult> run(ProcessResult previousResult, List<String> filenames) | 59 Future<ProcessResult> run(ProcessResult previousResult, List<String> filenames) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 ['make_hardcoded_translation.dart', 'intl_messages.json']); | 91 ['make_hardcoded_translation.dart', 'intl_messages.json']); |
| 92 | 92 |
| 93 Future<ProcessResult> generateCodeFromTranslation(ProcessResult previousResult) | 93 Future<ProcessResult> generateCodeFromTranslation(ProcessResult previousResult) |
| 94 => run( | 94 => run( |
| 95 previousResult, | 95 previousResult, |
| 96 ['generate_from_json.dart', '--generated-file-prefix=foo_', | 96 ['generate_from_json.dart', '--generated-file-prefix=foo_', |
| 97 'sample_with_messages.dart', | 97 'sample_with_messages.dart', |
| 98 'part_of_sample_with_messages.dart', 'translation_fr.json', | 98 'part_of_sample_with_messages.dart', 'translation_fr.json', |
| 99 'translation_de_DE.json' ]); | 99 'translation_de_DE.json' ]); |
| 100 | 100 |
| 101 Future<ProcessResult> runGeneratedCode(ProcessResult previousResult) => | |
| 102 run(previousResult, ['sample_with_messages.dart']); | |
| 103 | |
| 104 verifyResult(results) { | |
| 105 var lineIterator; | |
| 106 verify(String s) { | |
| 107 lineIterator.moveNext(); | |
| 108 var value = lineIterator.current; | |
| 109 expect(value, s); | |
| 110 } | |
| 111 | |
| 112 var output = results.stdout; | |
| 113 var lines = output.split("\n"); | |
| 114 // If it looks like these are CRLF delimited, then use that. | |
| 115 if (lines.first.endsWith("\r")) { | |
| 116 lines = output.split("\r\n"); | |
| 117 } | |
| 118 lineIterator = lines.iterator..moveNext(); | |
| 119 verify("Printing messages for en_US"); | |
| 120 verify("This is a message"); | |
| 121 verify("Another message with parameter hello"); | |
| 122 verify("Characters that need escaping, e.g slashes \\ dollars \${ " | |
| 123 "(curly braces are ok) and xml reserved characters <& and " | |
| 124 "quotes \" parameters 1, 2, and 3"); | |
| 125 verify("This string extends across multiple lines."); | |
| 126 verify("1, b, [c, d]"); | |
| 127 verify('"So-called"'); | |
| 128 verify("Cette chaîne est toujours traduit"); | |
| 129 verify("Interpolation is tricky when it ends a sentence like this."); | |
| 130 verify("This comes from a method"); | |
| 131 verify("This method is not a lambda"); | |
| 132 verify("This comes from a static method"); | |
| 133 verify("This is missing some translations"); | |
| 134 verify("Ancient Greek hangman characters: 𐅆𐅇."); | |
| 135 verify("Escapable characters here: "); | |
| 136 | |
| 137 verify('Is zero plural?'); | |
| 138 verify('This is singular.'); | |
| 139 verify('This is plural (2).'); | |
| 140 verify('Alice went to her house'); | |
| 141 verify('Bob went to his house'); | |
| 142 verify('cat went to its litter box'); | |
| 143 verify('Alice, Bob sont allés au magasin'); | |
| 144 verify('Alice est allée au magasin'); | |
| 145 verify('Personne n\'est allé au magasin'); | |
| 146 verify('Bob, Bob sont allés au magasin'); | |
| 147 verify('Alice, Alice sont allées au magasin'); | |
| 148 verify('none'); | |
| 149 verify('one'); | |
| 150 verify('m'); | |
| 151 verify('f'); | |
| 152 verify('7 male'); | |
| 153 verify('7 Canadian dollars'); | |
| 154 verify('5 some currency or other.'); | |
| 155 verify('1 Canadian dollar'); | |
| 156 verify('2 Canadian dollars'); | |
| 157 | |
| 158 var fr_lines = lines.skip(1).skipWhile( | |
| 159 (line) => !line.contains('----')).toList(); | |
| 160 lineIterator = fr_lines.iterator..moveNext(); | |
| 161 verify("Printing messages for fr"); | |
| 162 verify("Il s'agit d'un message"); | |
| 163 verify("Un autre message avec un seul paramètre hello"); | |
| 164 verify( | |
| 165 "Caractères qui doivent être échapper, par exemple barres \\ " | |
| 166 "dollars \${ (les accolades sont ok), et xml/html réservés <& et " | |
| 167 "des citations \" " | |
| 168 "avec quelques paramètres ainsi 1, 2, et 3"); | |
| 169 verify("Cette message prend plusiers lignes."); | |
| 170 verify("1, b, [c, d]"); | |
| 171 verify('"Soi-disant"'); | |
| 172 verify("Cette chaîne est toujours traduit"); | |
| 173 verify( | |
| 174 "L'interpolation est délicate quand elle se termine une " | |
| 175 "phrase comme this."); | |
| 176 verify("Cela vient d'une méthode"); | |
| 177 verify("Cette méthode n'est pas un lambda"); | |
| 178 verify("Cela vient d'une méthode statique"); | |
| 179 verify("Ce manque certaines traductions"); | |
| 180 verify("Anciens caractères grecs jeux du pendu: 𐅆𐅇."); | |
| 181 verify("Escapes: "); | |
| 182 verify("\r\f\b\t\v."); | |
| 183 | |
| 184 verify('Est-ce que nulle est pluriel?'); | |
| 185 verify('C\'est singulier'); | |
| 186 verify('C\'est pluriel (2).'); | |
| 187 verify('Alice est allée à sa house'); | |
| 188 verify('Bob est allé à sa house'); | |
| 189 verify('cat est allé à sa litter box'); | |
| 190 verify('Alice, Bob étaient allés à la magasin'); | |
| 191 verify('Alice était allée à la magasin'); | |
| 192 verify('Personne n\'avait allé à la magasin'); | |
| 193 verify('Bob, Bob étaient allés à la magasin'); | |
| 194 verify('Alice, Alice étaient allées à la magasin'); | |
| 195 verify('rien'); | |
| 196 verify('un'); | |
| 197 verify('homme'); | |
| 198 verify('femme'); | |
| 199 verify('7 homme'); | |
| 200 verify('7 dollars Canadiens'); | |
| 201 verify('5 certaine devise ou autre.'); | |
| 202 verify('1 dollar Canadien'); | |
| 203 verify('2 dollars Canadiens'); | |
| 204 | |
| 205 var de_lines = fr_lines.skip(1).skipWhile( | |
| 206 (line) => !line.contains('----')).toList(); | |
| 207 lineIterator = de_lines.iterator..moveNext(); | |
| 208 verify("Printing messages for de_DE"); | |
| 209 verify("Dies ist eine Nachricht"); | |
| 210 verify("Eine weitere Meldung mit dem Parameter hello"); | |
| 211 verify( | |
| 212 "Zeichen, die Flucht benötigen, zB Schrägstriche \\ Dollar " | |
| 213 "\${ (geschweiften Klammern sind ok) und xml reservierte Zeichen <& und " | |
| 214 "Zitate \" Parameter 1, 2 und 3"); | |
| 215 verify("Dieser String erstreckt sich über mehrere " | |
| 216 "Zeilen erstrecken."); | |
| 217 verify("1, b, [c, d]"); | |
| 218 verify('"Sogenannt"'); | |
| 219 // This is correct, the message is forced to French, even in a German locale. | |
| 220 verify("Cette chaîne est toujours traduit"); | |
| 221 verify( | |
| 222 "Interpolation ist schwierig, wenn es einen Satz wie dieser endet this."); | |
| 223 verify("Dies ergibt sich aus einer Methode"); | |
| 224 verify("Diese Methode ist nicht eine Lambda"); | |
| 225 verify("Dies ergibt sich aus einer statischen Methode"); | |
| 226 verify("This is missing some translations"); | |
| 227 verify("Antike griechische Galgenmännchen Zeichen: 𐅆𐅇"); | |
| 228 verify("Escapes: "); | |
| 229 verify("\r\f\b\t\v."); | |
| 230 | |
| 231 verify('Ist Null Plural?'); | |
| 232 verify('Dies ist einmalig'); | |
| 233 verify('Dies ist Plural (2).'); | |
| 234 verify('Alice ging zu ihrem house'); | |
| 235 verify('Bob ging zu seinem house'); | |
| 236 verify('cat ging zu seinem litter box'); | |
| 237 verify('Alice, Bob gingen zum magasin'); | |
| 238 verify('Alice ging in dem magasin'); | |
| 239 verify('Niemand ging zu magasin'); | |
| 240 verify('Bob, Bob gingen zum magasin'); | |
| 241 verify('Alice, Alice gingen zum magasin'); | |
| 242 verify('Null'); | |
| 243 verify('ein'); | |
| 244 verify('Mann'); | |
| 245 verify('Frau'); | |
| 246 verify('7 Mann'); | |
| 247 verify('7 Kanadischen dollar'); | |
| 248 verify('5 einige Währung oder anderen.'); | |
| 249 verify('1 Kanadischer dollar'); | |
| 250 verify('2 Kanadischen dollar'); | |
| 251 } | |
| OLD | NEW |