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

Side by Side Diff: pkg/polymer/test/testing.dart

Issue 23224003: move polymer.dart into dart svn (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add --deploy to todomvc sample Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/polymer/test/run_all.dart ('k') | pkg/polymer/test/utils_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 /** Common definitions used for setting up the test environment. */
6 library testing;
7
8 import 'dart:async';
9 import 'dart:io';
10
11 import 'package:csslib/visitor.dart';
12 import 'package:html5lib/dom.dart';
13 import 'package:html5lib/parser.dart';
14 import 'package:polymer/src/analyzer.dart';
15 import 'package:polymer/src/compiler.dart';
16 import 'package:polymer/src/file_system.dart';
17 import 'package:polymer/src/info.dart';
18 import 'package:polymer/src/messages.dart';
19 import 'package:polymer/src/compiler_options.dart';
20 import 'package:polymer/src/files.dart';
21 import 'package:polymer/src/utils.dart';
22
23
24 Document parseDocument(String html) => parse(html);
25
26 Element parseSubtree(String html) => parseFragment(html).nodes[0];
27
28 FileInfo analyzeDefinitionsInTree(Document doc, Messages messages,
29 {String packageRoot: 'packages'}) {
30
31 return analyzeDefinitions(new GlobalInfo(), new UrlInfo('', '', null),
32 doc, packageRoot, messages);
33 }
34
35 /** Parses files in [fileContents], with [mainHtmlFile] being the main file. */
36 List<SourceFile> parseFiles(Map<String, String> fileContents,
37 [String mainHtmlFile = 'index.html']) {
38
39 var result = <SourceFile>[];
40 fileContents.forEach((filename, contents) {
41 var src = new SourceFile(filename);
42 src.document = parse(contents);
43 result.add(src);
44 });
45
46 return result;
47 }
48
49 /** Analyze all files. */
50 Map<String, FileInfo> analyzeFiles(List<SourceFile> files,
51 {Messages messages, String packageRoot: 'packages'}) {
52 messages = messages == null ? new Messages.silent() : messages;
53 var result = new Map<String, FileInfo>();
54
55 // analyze definitions
56 var global = new GlobalInfo();
57 for (var file in files) {
58 var path = file.path;
59 result[path] = analyzeDefinitions(global, new UrlInfo(path, path, null),
60 file.document, packageRoot, messages);
61 }
62
63 // analyze file contents
64 var uniqueIds = new IntIterator();
65 var pseudoElements = new Map();
66 for (var file in files) {
67 analyzeFile(file, result, uniqueIds, pseudoElements, messages, true);
68 }
69 return result;
70 }
71
72 Compiler createCompiler(Map files, Messages messages, {bool errors: false,
73 bool scopedCss: false}) {
74 List baseOptions = ['--no-colors', '-o', 'out', '--deploy', 'index.html'];
75 if (errors) baseOptions.insert(0, '--warnings_as_errors');
76 if (scopedCss) baseOptions.insert(0, '--scoped-css');
77 var options = CompilerOptions.parse(baseOptions);
78 var fs = new MockFileSystem(files);
79 return new Compiler(fs, options, messages);
80 }
81
82 String prettyPrintCss(StyleSheet styleSheet) =>
83 ((new CssPrinter())..visitTree(styleSheet)).toString();
84
85 /**
86 * Abstraction around file system access to work in a variety of different
87 * environments.
88 */
89 class MockFileSystem extends FileSystem {
90 final Map _files;
91 final Map readCount = {};
92
93 MockFileSystem(this._files);
94
95 Future readTextOrBytes(String filename) => readText(filename);
96
97 Future<String> readText(String path) {
98 readCount[path] = readCount.putIfAbsent(path, () => 0) + 1;
99 var file = _files[path];
100 if (file != null) {
101 return new Future.value(file);
102 } else {
103 return new Future.error(
104 new FileException('MockFileSystem: $path not found'));
105 }
106 }
107
108 // Compiler doesn't call these
109 void writeString(String outfile, String text) {}
110 Future flush() {}
111 }
OLDNEW
« no previous file with comments | « pkg/polymer/test/run_all.dart ('k') | pkg/polymer/test/utils_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698