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 |
| 12 useMockMessages() { |
| 13 messages = new Messages(printHandler: (message) {}); |
| 14 } |
| 15 |
| 16 /** |
| 17 * 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 |
| 19 * tests (by default) will ensure that the CSS is really valid. |
| 20 */ |
| 21 StyleSheet parseCss(String cssInput, {List errors, List opts}) => |
| 22 parse(cssInput, errors: errors, options: opts == null ? |
| 23 ['--no-colors', '--checked', '--warnings_as_errors', 'memory'] : opts); |
| 24 |
| 25 /** |
| 26 * Spin-up CSS parser in checked mode to detect any problematic CSS. Normally, |
| 27 * CSS will allow any property/value pairs regardless of validity; all of our |
| 28 * tests (by default) will ensure that the CSS is really valid. |
| 29 */ |
| 30 StyleSheet compileCss(String cssInput, {List errors, List opts}) => |
| 31 compile(cssInput, errors: errors, options: opts == null ? |
| 32 ['--no-colors', '--checked', '--warnings_as_errors', 'memory'] : opts); |
| 33 |
| 34 /** CSS emitter walks the style sheet tree and emits readable CSS. */ |
| 35 var _emitCss = new CssPrinter(); |
| 36 |
| 37 /** Simple Visitor does nothing but walk tree. */ |
| 38 var _cssVisitor = new Visitor(); |
| 39 |
| 40 /** Pretty printer for CSS. */ |
| 41 String prettyPrint(StyleSheet ss) { |
| 42 // Walk the tree testing basic Vistor class. |
| 43 walkTree(ss); |
| 44 return (_emitCss..visitTree(ss, pretty: true)).toString(); |
| 45 } |
| 46 |
| 47 /** |
| 48 * Helper function to emit compact (non-pretty printed) CSS for suite test |
| 49 * comparsions. Spaces, new lines, etc. are reduced for easier comparsions of |
| 50 * expected suite test results. |
| 51 */ |
| 52 String compactOuptut(StyleSheet ss) { |
| 53 walkTree(ss); |
| 54 return (_emitCss..visitTree(ss, pretty: false)).toString(); |
| 55 } |
| 56 |
| 57 /** Walks the style sheet tree does nothing; insures the basic walker works. */ |
| 58 void walkTree(StyleSheet ss) { |
| 59 _cssVisitor..visitTree(ss); |
| 60 } |
| 61 |
| 62 String dumpTree(StyleSheet ss) => treeToDebugString(ss); |
| 63 |
| 64 |
OLD | NEW |