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

Unified Diff: tests/html/element_classes_test.dart

Issue 1055363002: element_classes_test - move helper functions to top level (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/html/element_classes_test.dart
diff --git a/tests/html/element_classes_test.dart b/tests/html/element_classes_test.dart
index 851528716a6e5a3b592bd789e3e0a8b530470d95..14af4bdeba7a26727b7d73d66342f157cb7bbeb1 100644
--- a/tests/html/element_classes_test.dart
+++ b/tests/html/element_classes_test.dart
@@ -8,18 +8,14 @@ import 'package:unittest/html_config.dart';
import 'dart:collection';
import 'dart:html';
-main() {
- useHtmlConfiguration();
-
- Element makeElement() => new Element.tag('div');
+Element makeElement() => new Element.tag('div');
- Element makeElementWithChildren() =>
- new Element.html("<div><br/><img/><input/></div>");
-
- Element makeElementWithClasses() =>
+Element makeElementWithClasses() =>
new Element.html('<div class="foo bar baz"></div>');
- Element makeListElement() =>
+Set<String> makeClassSet() => makeElementWithClasses().classes;
+
+Element makeListElement() =>
new Element.html('<ul class="foo bar baz">'
'<li class="quux qux">'
'<li class="meta">'
@@ -27,20 +23,37 @@ main() {
'<li class="qux lassy">'
'</ul>');
- Set<String> makeClassSet() => makeElementWithClasses().classes;
+Element listElement;
+
+ElementList<Element> listElementSetup() {
+ listElement = makeListElement();
+ document.documentElement.children.add(listElement);
+ return document.querySelectorAll('li');
+}
+
+void listElementTearDown() {
+ if (listElement != null) {
+ document.documentElement.children.remove(listElement);
+ listElement = null;
+ }
+}
+
+/// Returns a canonical string for Set<String> and lists of Element's classes.
+String view(var e) {
+ if (e is Set) return '${e.toList()..sort()}';
+ if (e is Element) return view(e.classes);
+ if (e is Iterable) return '${e.map(view).toList()}';
+ throw new ArgumentError('Cannot make canonical view string for: $e}');
+}
+
+main() {
+ useHtmlConfiguration();
Set<String> extractClasses(Element el) {
final match = new RegExp('class="([^"]+)"').firstMatch(el.outerHtml);
return new LinkedHashSet.from(match[1].split(' '));
}
- /// Returns a canonical string for Set<String> and lists of Element's classes.
- String view(var e) {
- if (e is Set) return '${e.toList()..sort()}';
- if (e is Element) return view(e.classes);
- if (e is Iterable) return '${e.map(view).toList()}';
- throw new ArgumentError('Cannot make canonical view string for: $e}');
- }
test('affects the "class" attribute', () {
final el = makeElementWithClasses();
@@ -227,21 +240,7 @@ main() {
expect(classes, orderedEquals(['foo', 'bar', 'aardvark', 'baz']));
});
-
- Element listElement;
-
- ElementList<Element> listElementSetup() {
- listElement = makeListElement();
- document.documentElement.children.add(listElement);
- return document.querySelectorAll('li');
- }
-
- tearDown(() {
- if (listElement != null) {
- document.documentElement.children.remove(listElement);
- listElement = null;
- }
- });
+ tearDown(listElementTearDown);
test('list_view', () {
// Test that the 'view' helper function is behaving.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698