OLD | NEW |
(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 'package:csslib/parser.dart'; |
| 9 import 'package:csslib/visitor.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'); |
| 26 |
| 27 /** |
| 28 * Spin-up CSS parser in checked mode to detect any problematic CSS. Normally, |
| 29 * CSS will allow any property/value pairs regardless of validity; all of our |
| 30 * tests (by default) will ensure that the CSS is really valid. |
| 31 */ |
| 32 StyleSheet parseCss(String cssInput, |
| 33 {List<Message> errors, PreprocessorOptions opts}) => parse(cssInput, |
| 34 errors: errors, |
| 35 options: opts == null |
| 36 ? simpleOptionsWithCheckedAndWarningsAsErrors |
| 37 : opts); |
| 38 |
| 39 /** |
| 40 * Spin-up CSS parser in checked mode to detect any problematic CSS. Normally, |
| 41 * CSS will allow any property/value pairs regardless of validity; all of our |
| 42 * tests (by default) will ensure that the CSS is really valid. |
| 43 */ |
| 44 StyleSheet compileCss(String cssInput, {List<Message> errors, |
| 45 PreprocessorOptions opts, bool polyfill: false, |
| 46 List<StyleSheet> includes: null}) => compile(cssInput, |
| 47 errors: errors, |
| 48 options: opts == null |
| 49 ? simpleOptionsWithCheckedAndWarningsAsErrors |
| 50 : opts, |
| 51 polyfill: polyfill, |
| 52 includes: includes); |
| 53 |
| 54 StyleSheet polyFillCompileCss(input, |
| 55 {List<Message> errors, PreprocessorOptions opts}) => |
| 56 compileCss(input, errors: errors, polyfill: true, opts: opts); |
| 57 |
| 58 /** CSS emitter walks the style sheet tree and emits readable CSS. */ |
| 59 final _emitCss = new CssPrinter(); |
| 60 |
| 61 /** Simple Visitor does nothing but walk tree. */ |
| 62 final _cssVisitor = new Visitor(); |
| 63 |
| 64 /** Pretty printer for CSS. */ |
| 65 String prettyPrint(StyleSheet ss) { |
| 66 // Walk the tree testing basic Vistor class. |
| 67 walkTree(ss); |
| 68 return (_emitCss..visitTree(ss, pretty: true)).toString(); |
| 69 } |
| 70 |
| 71 /** |
| 72 * Helper function to emit compact (non-pretty printed) CSS for suite test |
| 73 * comparsions. Spaces, new lines, etc. are reduced for easier comparsions of |
| 74 * expected suite test results. |
| 75 */ |
| 76 String compactOuptut(StyleSheet ss) { |
| 77 walkTree(ss); |
| 78 return (_emitCss..visitTree(ss, pretty: false)).toString(); |
| 79 } |
| 80 |
| 81 /** Walks the style sheet tree does nothing; insures the basic walker works. */ |
| 82 void walkTree(StyleSheet ss) { |
| 83 _cssVisitor..visitTree(ss); |
| 84 } |
| 85 |
| 86 String dumpTree(StyleSheet ss) => treeToDebugString(ss); |
OLD | NEW |