From da5b2b0b8e6fe67d0c021efd7ce483510454485f Mon Sep 17 00:00:00 2001 From: Roman Kamyk Date: Fri, 16 May 2014 15:11:37 -0700 Subject: [PATCH] test: add test for template_cache_generator css rewriting It use simple sed script to showcase integration is working. Test runs only if sed is present on the running system. The test uses css with simple rules that are getting traslated for RTL locales. Closes #1052 --- test/io/template_cache_generator_spec.dart | 39 ++++++++++++++++++++++ test/io/test_files/cssUrls/four.css | 7 ++++ test/io/test_files/rewritter.sh | 3 ++ 3 files changed, 49 insertions(+) create mode 100644 test/io/test_files/cssUrls/four.css create mode 100755 test/io/test_files/rewritter.sh diff --git a/test/io/template_cache_generator_spec.dart b/test/io/template_cache_generator_spec.dart index 91c4748c2..93e2173b4 100644 --- a/test/io/template_cache_generator_spec.dart +++ b/test/io/template_cache_generator_spec.dart @@ -70,6 +70,45 @@ void main() { }); }); + if (new File("/bin/sed").existsSync()) { + it('should correctly use simple sed rewritter to fake css mirroring', () { + var tmpDir = Directory.systemTemp.createTempSync(); + Future flush; + try { + flush = generator.main([ + '--out=${tmpDir.path}/generated.dart', + '--url-rewrites=/test/io/test_files,rewritten', + '--css-rewriter=test/io/test_files/rewritter.sh', + 'test/io/test_files/cssUrls/main.dart', + 'generated']); + } catch(_) { + tmpDir.deleteSync(recursive: true); + rethrow; + } + return flush.then((_) { + expect(new File('${tmpDir.path}/generated.dart').readAsStringSync(), +'''// GENERATED, DO NOT EDIT! +library generated; +import 'package:angular/angular.dart'; + +primeTemplateCache(TemplateCache tc) { +tc.put("rewritten/cssUrls/four.css", new HttpResponse(200, r""".float-right { + float: right; +} +.right-margin { + margin-right: 20px; +} + +""")); +tc.put("rewritten/cssUrls/one.css", new HttpResponse(200, r"""body {}""")); +tc.put("rewritten/cssUrls/three.css", new HttpResponse(200, r"""body {}""")); +tc.put("rewritten/cssUrls/two.css", new HttpResponse(200, r"""body {}""")); +}'''); + }).whenComplete(() { + tmpDir.deleteSync(recursive: true); + }); + }); + } }); } diff --git a/test/io/test_files/cssUrls/four.css b/test/io/test_files/cssUrls/four.css new file mode 100644 index 000000000..2077038e2 --- /dev/null +++ b/test/io/test_files/cssUrls/four.css @@ -0,0 +1,7 @@ +.float-left { + float: left; +} +.left-margin { + margin-left: 20px; +} + diff --git a/test/io/test_files/rewritter.sh b/test/io/test_files/rewritter.sh new file mode 100755 index 000000000..44574dbd6 --- /dev/null +++ b/test/io/test_files/rewritter.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +/bin/sed 's/left/right/g'