OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 /** Common definitions used for setting up the test environment. */ | 5 /** Common definitions used for setting up the test environment. */ |
6 library testing; | 6 library testing; |
7 | 7 |
8 import 'package:csslib/parser.dart'; | 8 import 'package:csslib/parser.dart'; |
9 import 'package:csslib/visitor.dart'; | 9 import 'package:csslib/visitor.dart'; |
10 import 'package:csslib/src/messages.dart'; | 10 import 'package:csslib/src/messages.dart'; |
| 11 import 'package:csslib/src/options.dart'; |
| 12 |
| 13 export 'package:csslib/src/options.dart'; |
| 14 |
| 15 const simpleOptionsWithCheckedAndWarningsAsErrors = const PreprocessorOptions( |
| 16 useColors: false, |
| 17 checked: true, |
| 18 warningsAsErrors: true, |
| 19 inputFile: 'memory'); |
| 20 |
| 21 const simpleOptions = |
| 22 const PreprocessorOptions(useColors: false, inputFile: 'memory'); |
| 23 |
| 24 const options = const PreprocessorOptions( |
| 25 useColors: false, warningsAsErrors: true, inputFile: 'memory'); |
11 | 26 |
12 void useMockMessages() { | 27 void useMockMessages() { |
13 messages = new Messages(printHandler: (message) {}); | 28 messages = new Messages(printHandler: (message) {}); |
14 } | 29 } |
15 | 30 |
16 /** | 31 /** |
17 * Spin-up CSS parser in checked mode to detect any problematic CSS. Normally, | 32 * Spin-up CSS parser in checked mode to detect any problematic CSS. Normally, |
18 * CSS will allow any property/value pairs regardless of validity; all of our | 33 * CSS will allow any property/value pairs regardless of validity; all of our |
19 * tests (by default) will ensure that the CSS is really valid. | 34 * tests (by default) will ensure that the CSS is really valid. |
20 */ | 35 */ |
21 StyleSheet parseCss(String cssInput, | 36 StyleSheet parseCss(String cssInput, |
22 {List<Message> errors, List<String> opts}) => parse(cssInput, | 37 {List<Message> errors, PreprocessorOptions opts}) => parse(cssInput, |
23 errors: errors, | 38 errors: errors, |
24 options: opts == null | 39 options: opts == null |
25 ? ['--no-colors', '--checked', '--warnings_as_errors', 'memory'] | 40 ? simpleOptionsWithCheckedAndWarningsAsErrors |
26 : opts); | 41 : opts); |
27 | 42 |
28 /** | 43 /** |
29 * Spin-up CSS parser in checked mode to detect any problematic CSS. Normally, | 44 * Spin-up CSS parser in checked mode to detect any problematic CSS. Normally, |
30 * CSS will allow any property/value pairs regardless of validity; all of our | 45 * CSS will allow any property/value pairs regardless of validity; all of our |
31 * tests (by default) will ensure that the CSS is really valid. | 46 * tests (by default) will ensure that the CSS is really valid. |
32 */ | 47 */ |
33 StyleSheet compileCss(String cssInput, {List<Message> errors, List<String> opts, | 48 StyleSheet compileCss(String cssInput, {List<Message> errors, |
34 bool polyfill: false, List<StyleSheet> includes: null}) => compile(cssInput, | 49 PreprocessorOptions opts, bool polyfill: false, |
| 50 List<StyleSheet> includes: null}) => compile(cssInput, |
35 errors: errors, | 51 errors: errors, |
36 options: opts == null | 52 options: opts == null |
37 ? ['--no-colors', '--checked', '--warnings_as_errors', 'memory'] | 53 ? simpleOptionsWithCheckedAndWarningsAsErrors |
38 : opts, | 54 : opts, |
39 polyfill: polyfill, | 55 polyfill: polyfill, |
40 includes: includes); | 56 includes: includes); |
41 | 57 |
42 StyleSheet polyFillCompileCss(input, | 58 StyleSheet polyFillCompileCss(input, |
43 {List<Message> errors, List<String> opts}) => | 59 {List<Message> errors, PreprocessorOptions opts}) => |
44 compileCss(input, errors: errors, polyfill: true, opts: opts); | 60 compileCss(input, errors: errors, polyfill: true, opts: opts); |
45 | 61 |
46 /** CSS emitter walks the style sheet tree and emits readable CSS. */ | 62 /** CSS emitter walks the style sheet tree and emits readable CSS. */ |
47 final _emitCss = new CssPrinter(); | 63 final _emitCss = new CssPrinter(); |
48 | 64 |
49 /** Simple Visitor does nothing but walk tree. */ | 65 /** Simple Visitor does nothing but walk tree. */ |
50 final _cssVisitor = new Visitor(); | 66 final _cssVisitor = new Visitor(); |
51 | 67 |
52 /** Pretty printer for CSS. */ | 68 /** Pretty printer for CSS. */ |
53 String prettyPrint(StyleSheet ss) { | 69 String prettyPrint(StyleSheet ss) { |
(...skipping 11 matching lines...) Expand all Loading... |
65 walkTree(ss); | 81 walkTree(ss); |
66 return (_emitCss..visitTree(ss, pretty: false)).toString(); | 82 return (_emitCss..visitTree(ss, pretty: false)).toString(); |
67 } | 83 } |
68 | 84 |
69 /** Walks the style sheet tree does nothing; insures the basic walker works. */ | 85 /** Walks the style sheet tree does nothing; insures the basic walker works. */ |
70 void walkTree(StyleSheet ss) { | 86 void walkTree(StyleSheet ss) { |
71 _cssVisitor..visitTree(ss); | 87 _cssVisitor..visitTree(ss); |
72 } | 88 } |
73 | 89 |
74 String dumpTree(StyleSheet ss) => treeToDebugString(ss); | 90 String dumpTree(StyleSheet ss) => treeToDebugString(ss); |
OLD | NEW |