Index: pkg/analyzer/test/src/task/html_test.dart |
diff --git a/pkg/analyzer/test/src/task/html_test.dart b/pkg/analyzer/test/src/task/html_test.dart |
index 89334103843d60cd473696ba0df511b031ee9219..e3413b7a49c9b19f3cec6f6c50c9a146c3e7d929 100644 |
--- a/pkg/analyzer/test/src/task/html_test.dart |
+++ b/pkg/analyzer/test/src/task/html_test.dart |
@@ -15,24 +15,23 @@ import '../context/abstract_context.dart'; |
main() { |
groupSep = ' | '; |
+ runReflectiveTests(DartScriptsTaskTest); |
runReflectiveTests(HtmlErrorsTaskTest); |
runReflectiveTests(ParseHtmlTaskTest); |
- runReflectiveTests(ReferencedLibrariesTaskTest); |
} |
@reflectiveTest |
-class HtmlErrorsTaskTest extends AbstractContextTest { |
+class DartScriptsTaskTest extends AbstractContextTest { |
test_buildInputs() { |
Source source = newSource('/test.html'); |
- Map<String, TaskInput> inputs = HtmlErrorsTask.buildInputs(source); |
+ Map<String, TaskInput> inputs = DartScriptsTask.buildInputs(source); |
expect(inputs, isNotNull); |
- expect( |
- inputs.keys, unorderedEquals([HtmlErrorsTask.DOCUMENT_ERRORS_INPUT])); |
+ expect(inputs.keys, unorderedEquals([DartScriptsTask.DOCUMENT_INPUT])); |
} |
test_constructor() { |
Source source = newSource('/test.html'); |
- HtmlErrorsTask task = new HtmlErrorsTask(context, source); |
+ DartScriptsTask task = new DartScriptsTask(context, source); |
expect(task, isNotNull); |
expect(task.context, context); |
expect(task.target, source); |
@@ -40,7 +39,7 @@ class HtmlErrorsTaskTest extends AbstractContextTest { |
test_createTask() { |
Source source = newSource('/test.html'); |
- HtmlErrorsTask task = HtmlErrorsTask.createTask(context, source); |
+ DartScriptsTask task = DartScriptsTask.createTask(context, source); |
expect(task, isNotNull); |
expect(task.context, context); |
expect(task.target, source); |
@@ -48,16 +47,87 @@ class HtmlErrorsTaskTest extends AbstractContextTest { |
test_description() { |
Source source = newSource('/test.html'); |
- HtmlErrorsTask task = new HtmlErrorsTask(null, source); |
+ DartScriptsTask task = new DartScriptsTask(null, source); |
expect(task.description, isNotNull); |
} |
test_descriptor() { |
- TaskDescriptor descriptor = HtmlErrorsTask.DESCRIPTOR; |
+ TaskDescriptor descriptor = DartScriptsTask.DESCRIPTOR; |
expect(descriptor, isNotNull); |
} |
- test_perform() { |
+ void test_perform_embedded_source() { |
+ String content = r''' |
+ void buttonPressed() {} |
+ '''; |
+ AnalysisTarget target = newSource('/test.html', ''' |
+<!DOCTYPE html> |
+<html> |
+<head> |
+ <script type='application/dart'>$content</script> |
+</head> |
+<body> |
+</body> |
+</html>'''); |
+ computeResult(target, REFERENCED_LIBRARIES); |
+ expect(task, new isInstanceOf<DartScriptsTask>()); |
+ expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
+ expect(outputs[DART_SCRIPTS], hasLength(1)); |
+ DartScript script = outputs[DART_SCRIPTS][0]; |
+ expect(script.fragments, hasLength(1)); |
+ ScriptFragment fragment = script.fragments[0]; |
+ expect(fragment.content, content); |
+ } |
+ |
+ void test_perform_empty_source_reference() { |
+ AnalysisTarget target = newSource('/test.html', r''' |
+<!DOCTYPE html> |
+<html> |
+<head> |
+ <script type='application/dart' src=''/> |
+</head> |
+<body> |
+</body> |
+</html>'''); |
+ computeResult(target, REFERENCED_LIBRARIES); |
+ expect(task, new isInstanceOf<DartScriptsTask>()); |
+ expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
+ expect(outputs[DART_SCRIPTS], hasLength(0)); |
+ } |
+ |
+ void test_perform_invalid_source_reference() { |
+ AnalysisTarget target = newSource('/test.html', r''' |
+<!DOCTYPE html> |
+<html> |
+<head> |
+ <script type='application/dart' src='an;invalid:[]uri'/> |
+</head> |
+<body> |
+</body> |
+</html>'''); |
+ computeResult(target, REFERENCED_LIBRARIES); |
+ expect(task, new isInstanceOf<DartScriptsTask>()); |
+ expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
+ expect(outputs[DART_SCRIPTS], hasLength(0)); |
+ } |
+ |
+ void test_perform_non_existing_source_reference() { |
+ AnalysisTarget target = newSource('/test.html', r''' |
+<!DOCTYPE html> |
+<html> |
+<head> |
+ <script type='application/dart' src='does/not/exist.dart'/> |
+</head> |
+<body> |
+</body> |
+</html>'''); |
+ computeResult(target, REFERENCED_LIBRARIES); |
+ expect(task, new isInstanceOf<DartScriptsTask>()); |
+ expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); |
+ expect(outputs[DART_SCRIPTS], hasLength(0)); |
+ } |
+ |
+ test_perform_none() { |
AnalysisTarget target = newSource('/test.html', r''' |
<!DOCTYPE html> |
<html> |
@@ -69,24 +139,44 @@ class HtmlErrorsTaskTest extends AbstractContextTest { |
</body> |
</html> |
'''); |
- computeResult(target, HTML_ERRORS); |
- expect(task, new isInstanceOf<HtmlErrorsTask>()); |
- expect(outputs[HTML_ERRORS], isEmpty); |
+ computeResult(target, REFERENCED_LIBRARIES); |
+ expect(task, new isInstanceOf<DartScriptsTask>()); |
+ expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
+ expect(outputs[DART_SCRIPTS], hasLength(0)); |
+ } |
+ |
+ void test_perform_referenced_source() { |
+ AnalysisTarget target = newSource('/test.html', r''' |
+<!DOCTYPE html> |
+<html> |
+<head> |
+ <script type='application/dart' src='test.dart'/> |
+</head> |
+<body> |
+</body> |
+</html>'''); |
+ computeResult(target, REFERENCED_LIBRARIES); |
+ expect(task, new isInstanceOf<DartScriptsTask>()); |
+ expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); |
+ expect(outputs[DART_SCRIPTS], hasLength(0)); |
} |
} |
@reflectiveTest |
-class ParseHtmlTaskTest extends AbstractContextTest { |
+class HtmlErrorsTaskTest extends AbstractContextTest { |
test_buildInputs() { |
Source source = newSource('/test.html'); |
- Map<String, TaskInput> inputs = ParseHtmlTask.buildInputs(source); |
+ Map<String, TaskInput> inputs = HtmlErrorsTask.buildInputs(source); |
expect(inputs, isNotNull); |
- expect(inputs.keys, unorderedEquals([ParseHtmlTask.CONTENT_INPUT_NAME])); |
+ expect(inputs.keys, unorderedEquals([ |
+ HtmlErrorsTask.DART_ERRORS_INPUT, |
+ HtmlErrorsTask.DOCUMENT_ERRORS_INPUT |
+ ])); |
} |
test_constructor() { |
Source source = newSource('/test.html'); |
- ParseHtmlTask task = new ParseHtmlTask(context, source); |
+ HtmlErrorsTask task = new HtmlErrorsTask(context, source); |
expect(task, isNotNull); |
expect(task.context, context); |
expect(task.target, source); |
@@ -94,7 +184,7 @@ class ParseHtmlTaskTest extends AbstractContextTest { |
test_createTask() { |
Source source = newSource('/test.html'); |
- ParseHtmlTask task = ParseHtmlTask.createTask(context, source); |
+ HtmlErrorsTask task = HtmlErrorsTask.createTask(context, source); |
expect(task, isNotNull); |
expect(task.context, context); |
expect(task.target, source); |
@@ -102,47 +192,79 @@ class ParseHtmlTaskTest extends AbstractContextTest { |
test_description() { |
Source source = newSource('/test.html'); |
- ParseHtmlTask task = new ParseHtmlTask(null, source); |
+ HtmlErrorsTask task = new HtmlErrorsTask(null, source); |
expect(task.description, isNotNull); |
} |
test_descriptor() { |
- TaskDescriptor descriptor = ParseHtmlTask.DESCRIPTOR; |
+ TaskDescriptor descriptor = HtmlErrorsTask.DESCRIPTOR; |
expect(descriptor, isNotNull); |
} |
- test_perform() { |
+ test_perform_dartErrors() { |
AnalysisTarget target = newSource('/test.html', r''' |
<!DOCTYPE html> |
<html> |
<head> |
<title>test page</title> |
+ <script type='application/dart'> |
+ void buttonPressed() { |
+ </script> |
+ </head> |
+ <body>Test</body> |
+</html> |
+'''); |
+ computeResult(target, HTML_ERRORS); |
+ expect(task, new isInstanceOf<HtmlErrorsTask>()); |
+ expect(outputs[HTML_ERRORS], hasLength(1)); |
+ } |
+ |
+ test_perform_htmlErrors() { |
+ AnalysisTarget target = newSource('/test.html', r''' |
+<html> |
+ <head> |
+ <title>test page</title> |
</head> |
<body> |
- <h1 Test> |
+ Test |
</body> |
</html> |
'''); |
- computeResult(target, HTML_DOCUMENT); |
- expect(task, new isInstanceOf<ParseHtmlTask>()); |
- expect(outputs[HTML_DOCUMENT], isNotNull); |
- expect(outputs[HTML_DOCUMENT_ERRORS], isNotEmpty); |
+ computeResult(target, HTML_ERRORS); |
+ expect(task, new isInstanceOf<HtmlErrorsTask>()); |
+ expect(outputs[HTML_ERRORS], hasLength(1)); |
+ } |
+ |
+ test_perform_noErrors() { |
+ AnalysisTarget target = newSource('/test.html', r''' |
+<!DOCTYPE html> |
+<html> |
+ <head> |
+ <title>test page</title> |
+ </head> |
+ <body> |
+ Test |
+ </body> |
+</html> |
+'''); |
+ computeResult(target, HTML_ERRORS); |
+ expect(task, new isInstanceOf<HtmlErrorsTask>()); |
+ expect(outputs[HTML_ERRORS], isEmpty); |
} |
} |
@reflectiveTest |
-class ReferencedLibrariesTaskTest extends AbstractContextTest { |
+class ParseHtmlTaskTest extends AbstractContextTest { |
test_buildInputs() { |
Source source = newSource('/test.html'); |
- Map<String, TaskInput> inputs = ReferencedLibrariesTask.buildInputs(source); |
+ Map<String, TaskInput> inputs = ParseHtmlTask.buildInputs(source); |
expect(inputs, isNotNull); |
- expect( |
- inputs.keys, unorderedEquals([ReferencedLibrariesTask.DOCUMENT_INPUT])); |
+ expect(inputs.keys, unorderedEquals([ParseHtmlTask.CONTENT_INPUT_NAME])); |
} |
test_constructor() { |
Source source = newSource('/test.html'); |
- ReferencedLibrariesTask task = new ReferencedLibrariesTask(context, source); |
+ ParseHtmlTask task = new ParseHtmlTask(context, source); |
expect(task, isNotNull); |
expect(task.context, context); |
expect(task.target, source); |
@@ -150,8 +272,7 @@ class ReferencedLibrariesTaskTest extends AbstractContextTest { |
test_createTask() { |
Source source = newSource('/test.html'); |
- ReferencedLibrariesTask task = |
- ReferencedLibrariesTask.createTask(context, source); |
+ ParseHtmlTask task = ParseHtmlTask.createTask(context, source); |
expect(task, isNotNull); |
expect(task.context, context); |
expect(task.target, source); |
@@ -159,78 +280,16 @@ class ReferencedLibrariesTaskTest extends AbstractContextTest { |
test_description() { |
Source source = newSource('/test.html'); |
- ReferencedLibrariesTask task = new ReferencedLibrariesTask(null, source); |
+ ParseHtmlTask task = new ParseHtmlTask(null, source); |
expect(task.description, isNotNull); |
} |
test_descriptor() { |
- TaskDescriptor descriptor = ReferencedLibrariesTask.DESCRIPTOR; |
+ TaskDescriptor descriptor = ParseHtmlTask.DESCRIPTOR; |
expect(descriptor, isNotNull); |
} |
- void test_perform_embedded_source() { |
- AnalysisTarget target = newSource('/test.html', r''' |
-<!DOCTYPE html> |
-<html> |
-<head> |
- <script type='application/dart'> |
- void buttonPressed() {} |
- </script> |
-</head> |
-<body> |
-</body> |
-</html>'''); |
- computeResult(target, REFERENCED_LIBRARIES); |
- expect(task, new isInstanceOf<ReferencedLibrariesTask>()); |
- expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
- } |
- |
- void test_perform_empty_source_reference() { |
- AnalysisTarget target = newSource('/test.html', r''' |
-<!DOCTYPE html> |
-<html> |
-<head> |
- <script type='application/dart' src=''/> |
-</head> |
-<body> |
-</body> |
-</html>'''); |
- computeResult(target, REFERENCED_LIBRARIES); |
- expect(task, new isInstanceOf<ReferencedLibrariesTask>()); |
- expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
- } |
- |
- void test_perform_invalid_source_reference() { |
- AnalysisTarget target = newSource('/test.html', r''' |
-<!DOCTYPE html> |
-<html> |
-<head> |
- <script type='application/dart' src='an;invalid:[]uri'/> |
-</head> |
-<body> |
-</body> |
-</html>'''); |
- computeResult(target, REFERENCED_LIBRARIES); |
- expect(task, new isInstanceOf<ReferencedLibrariesTask>()); |
- expect(outputs[REFERENCED_LIBRARIES], hasLength(0)); |
- } |
- |
- void test_perform_non_existing_source_reference() { |
- AnalysisTarget target = newSource('/test.html', r''' |
-<!DOCTYPE html> |
-<html> |
-<head> |
- <script type='application/dart' src='does/not/exist.dart'/> |
-</head> |
-<body> |
-</body> |
-</html>'''); |
- computeResult(target, REFERENCED_LIBRARIES); |
- expect(task, new isInstanceOf<ReferencedLibrariesTask>()); |
- expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); |
- } |
- |
- test_perform_none() { |
+ test_perform() { |
AnalysisTarget target = newSource('/test.html', r''' |
<!DOCTYPE html> |
<html> |
@@ -238,27 +297,13 @@ class ReferencedLibrariesTaskTest extends AbstractContextTest { |
<title>test page</title> |
</head> |
<body> |
- Test |
+ <h1 Test> |
</body> |
</html> |
'''); |
- computeResult(target, REFERENCED_LIBRARIES); |
- expect(task, new isInstanceOf<ReferencedLibrariesTask>()); |
- expect(outputs[REFERENCED_LIBRARIES], isEmpty); |
- } |
- |
- void test_perform_referenced_source() { |
- AnalysisTarget target = newSource('/test.html', r''' |
-<!DOCTYPE html> |
-<html> |
-<head> |
- <script type='application/dart' src='test.dart'/> |
-</head> |
-<body> |
-</body> |
-</html>'''); |
- computeResult(target, REFERENCED_LIBRARIES); |
- expect(task, new isInstanceOf<ReferencedLibrariesTask>()); |
- expect(outputs[REFERENCED_LIBRARIES], hasLength(1)); |
+ computeResult(target, HTML_DOCUMENT); |
+ expect(task, new isInstanceOf<ParseHtmlTask>()); |
+ expect(outputs[HTML_DOCUMENT], isNotNull); |
+ expect(outputs[HTML_DOCUMENT_ERRORS], isNotEmpty); |
} |
} |