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

Side by Side Diff: pkg/analyzer/test/generated/all_the_rest_test.dart

Issue 1490233007: Remove the old task model (Closed) Base URL: https://github.com/dart-lang/sdk.git@analyzer-breaking-0.27
Patch Set: Created 5 years 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 unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/enum_test.dart ('k') | pkg/analyzer/test/generated/engine_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library engine.all_the_rest_test; 5 library engine.all_the_rest_test;
6 6
7 import 'package:analyzer/file_system/physical_file_system.dart'; 7 import 'package:analyzer/file_system/physical_file_system.dart';
8 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; 8 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator;
9 import 'package:analyzer/src/generated/constant.dart'; 9 import 'package:analyzer/src/generated/constant.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 runReflectiveTests(DirectoryBasedSourceContainerTest); 55 runReflectiveTests(DirectoryBasedSourceContainerTest);
56 runReflectiveTests(ElementBuilderTest); 56 runReflectiveTests(ElementBuilderTest);
57 runReflectiveTests(ElementLocatorTest); 57 runReflectiveTests(ElementLocatorTest);
58 runReflectiveTests(EnumMemberBuilderTest); 58 runReflectiveTests(EnumMemberBuilderTest);
59 runReflectiveTests(ErrorReporterTest); 59 runReflectiveTests(ErrorReporterTest);
60 runReflectiveTests(ErrorSeverityTest); 60 runReflectiveTests(ErrorSeverityTest);
61 runReflectiveTests(ExitDetectorTest); 61 runReflectiveTests(ExitDetectorTest);
62 runReflectiveTests(ExitDetectorTest2); 62 runReflectiveTests(ExitDetectorTest2);
63 runReflectiveTests(FileBasedSourceTest); 63 runReflectiveTests(FileBasedSourceTest);
64 runReflectiveTests(FileUriResolverTest); 64 runReflectiveTests(FileUriResolverTest);
65 if (!AnalysisEngine.instance.useTaskModel) {
66 runReflectiveTests(HtmlParserTest);
67 runReflectiveTests(HtmlTagInfoBuilderTest);
68 runReflectiveTests(HtmlUnitBuilderTest);
69 runReflectiveTests(HtmlWarningCodeTest);
70 }
71 runReflectiveTests(ReferenceFinderTest); 65 runReflectiveTests(ReferenceFinderTest);
72 runReflectiveTests(SDKLibrariesReaderTest); 66 runReflectiveTests(SDKLibrariesReaderTest);
73 runReflectiveTests(ToSourceVisitorTest); 67 runReflectiveTests(ToSourceVisitorTest);
74 runReflectiveTests(UriKindTest); 68 runReflectiveTests(UriKindTest);
75 runReflectiveTests(StringScannerTest); 69 runReflectiveTests(StringScannerTest);
76 } 70 }
77 71
78 abstract class AbstractScannerTest { 72 abstract class AbstractScannerTest {
79 ht.AbstractScanner newScanner(String input); 73 ht.AbstractScanner newScanner(String input);
80 74
(...skipping 1950 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 } 2025 }
2032 2026
2033 void test_instanceCreationExpression_symbol() { 2027 void test_instanceCreationExpression_symbol() {
2034 CompilationUnit compilationUnit = 2028 CompilationUnit compilationUnit =
2035 resolveSource("const foo = const Symbol('a');"); 2029 resolveSource("const foo = const Symbol('a');");
2036 EvaluationResultImpl evaluationResult = 2030 EvaluationResultImpl evaluationResult =
2037 _evaluateTopLevelVariable(compilationUnit, "foo"); 2031 _evaluateTopLevelVariable(compilationUnit, "foo");
2038 expect(evaluationResult.value, isNotNull); 2032 expect(evaluationResult.value, isNotNull);
2039 DartObjectImpl value = evaluationResult.value; 2033 DartObjectImpl value = evaluationResult.value;
2040 expect(value.type, typeProvider.symbolType); 2034 expect(value.type, typeProvider.symbolType);
2041 expect(value.value, "a"); 2035 expect(value.toSymbolValue(), "a");
2042 } 2036 }
2043 2037
2044 void test_instanceCreationExpression_withSupertypeParams_explicit() { 2038 void test_instanceCreationExpression_withSupertypeParams_explicit() {
2045 _checkInstanceCreation_withSupertypeParams(true); 2039 _checkInstanceCreation_withSupertypeParams(true);
2046 } 2040 }
2047 2041
2048 void test_instanceCreationExpression_withSupertypeParams_implicit() { 2042 void test_instanceCreationExpression_withSupertypeParams_implicit() {
2049 _checkInstanceCreation_withSupertypeParams(false); 2043 _checkInstanceCreation_withSupertypeParams(false);
2050 } 2044 }
2051 2045
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2142 2136
2143 void test_symbolLiteral_void() { 2137 void test_symbolLiteral_void() {
2144 CompilationUnit compilationUnit = 2138 CompilationUnit compilationUnit =
2145 resolveSource("const voidSymbol = #void;"); 2139 resolveSource("const voidSymbol = #void;");
2146 VariableDeclaration voidSymbol = 2140 VariableDeclaration voidSymbol =
2147 findTopLevelDeclaration(compilationUnit, "voidSymbol"); 2141 findTopLevelDeclaration(compilationUnit, "voidSymbol");
2148 EvaluationResultImpl voidSymbolResult = 2142 EvaluationResultImpl voidSymbolResult =
2149 (voidSymbol.element as VariableElementImpl).evaluationResult; 2143 (voidSymbol.element as VariableElementImpl).evaluationResult;
2150 DartObjectImpl value = voidSymbolResult.value; 2144 DartObjectImpl value = voidSymbolResult.value;
2151 expect(value.type, typeProvider.symbolType); 2145 expect(value.type, typeProvider.symbolType);
2152 expect(value.value, "void"); 2146 expect(value.toSymbolValue(), "void");
2153 } 2147 }
2154 2148
2155 Map<String, DartObjectImpl> _assertFieldType( 2149 Map<String, DartObjectImpl> _assertFieldType(
2156 Map<String, DartObjectImpl> fields, 2150 Map<String, DartObjectImpl> fields,
2157 String fieldName, 2151 String fieldName,
2158 String expectedType) { 2152 String expectedType) {
2159 DartObjectImpl field = fields[fieldName]; 2153 DartObjectImpl field = fields[fieldName];
2160 expect(field.type.displayName, expectedType); 2154 expect(field.type.displayName, expectedType);
2161 return field.fields; 2155 return field.fields;
2162 } 2156 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 void _assertValidNull(EvaluationResultImpl result) { 2207 void _assertValidNull(EvaluationResultImpl result) {
2214 expect(result.value, isNotNull); 2208 expect(result.value, isNotNull);
2215 DartObjectImpl value = result.value; 2209 DartObjectImpl value = result.value;
2216 expect(value.type, typeProvider.nullType); 2210 expect(value.type, typeProvider.nullType);
2217 } 2211 }
2218 2212
2219 String _assertValidString(EvaluationResultImpl result) { 2213 String _assertValidString(EvaluationResultImpl result) {
2220 expect(result.value, isNotNull); 2214 expect(result.value, isNotNull);
2221 DartObjectImpl value = result.value; 2215 DartObjectImpl value = result.value;
2222 expect(value.type, typeProvider.stringType); 2216 expect(value.type, typeProvider.stringType);
2223 return value.stringValue; 2217 return value.toStringValue();
2224 } 2218 }
2225 2219
2226 void _assertValidUnknown(EvaluationResultImpl result) { 2220 void _assertValidUnknown(EvaluationResultImpl result) {
2227 expect(result.value, isNotNull); 2221 expect(result.value, isNotNull);
2228 DartObjectImpl value = result.value; 2222 DartObjectImpl value = result.value;
2229 expect(value.isUnknown, isTrue); 2223 expect(value.isUnknown, isTrue);
2230 } 2224 }
2231 2225
2232 EvaluationResultImpl _check_fromEnvironment_bool( 2226 EvaluationResultImpl _check_fromEnvironment_bool(
2233 String valueInEnvironment, String defaultExpr) { 2227 String valueInEnvironment, String defaultExpr) {
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 errorListener.assertNoErrors(); 2469 errorListener.assertNoErrors();
2476 } 2470 }
2477 2471
2478 void test_visitSimpleIdentifier_className() { 2472 void test_visitSimpleIdentifier_className() {
2479 CompilationUnit compilationUnit = resolveSource(''' 2473 CompilationUnit compilationUnit = resolveSource('''
2480 const a = C; 2474 const a = C;
2481 class C {} 2475 class C {}
2482 '''); 2476 ''');
2483 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); 2477 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null);
2484 expect(result.type, typeProvider.typeType); 2478 expect(result.type, typeProvider.typeType);
2485 ClassElement element = result.value; 2479 expect(result.toTypeValue().name, 'C');
2486 expect(element.name, 'C');
2487 } 2480 }
2488 2481
2489 void test_visitSimpleIdentifier_dynamic() { 2482 void test_visitSimpleIdentifier_dynamic() {
2490 CompilationUnit compilationUnit = resolveSource(''' 2483 CompilationUnit compilationUnit = resolveSource('''
2491 const a = dynamic; 2484 const a = dynamic;
2492 '''); 2485 ''');
2493 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); 2486 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null);
2494 expect(result.type, typeProvider.typeType); 2487 expect(result.type, typeProvider.typeType);
2495 expect(result.value, typeProvider.dynamicType.element); 2488 expect(result.toTypeValue(), typeProvider.dynamicType);
2496 } 2489 }
2497 2490
2498 void test_visitSimpleIdentifier_inEnvironment() { 2491 void test_visitSimpleIdentifier_inEnvironment() {
2499 CompilationUnit compilationUnit = resolveSource(r''' 2492 CompilationUnit compilationUnit = resolveSource(r'''
2500 const a = b; 2493 const a = b;
2501 const b = 3;'''); 2494 const b = 3;''');
2502 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>(); 2495 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>();
2503 DartObjectImpl six = 2496 DartObjectImpl six =
2504 new DartObjectImpl(typeProvider.intType, new IntState(6)); 2497 new DartObjectImpl(typeProvider.intType, new IntState(6));
2505 environment["b"] = six; 2498 environment["b"] = six;
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
2924 2917
2925 void test_equals_symbol_false() { 2918 void test_equals_symbol_false() {
2926 expect(_symbolValue("a") == _symbolValue("b"), isFalse); 2919 expect(_symbolValue("a") == _symbolValue("b"), isFalse);
2927 } 2920 }
2928 2921
2929 void test_equals_symbol_true() { 2922 void test_equals_symbol_true() {
2930 expect(_symbolValue("a"), _symbolValue("a")); 2923 expect(_symbolValue("a"), _symbolValue("a"));
2931 } 2924 }
2932 2925
2933 void test_getValue_bool_false() { 2926 void test_getValue_bool_false() {
2934 expect(_boolValue(false).value, false); 2927 expect(_boolValue(false).toBoolValue(), false);
2935 } 2928 }
2936 2929
2937 void test_getValue_bool_true() { 2930 void test_getValue_bool_true() {
2938 expect(_boolValue(true).value, true); 2931 expect(_boolValue(true).toBoolValue(), true);
2939 } 2932 }
2940 2933
2941 void test_getValue_bool_unknown() { 2934 void test_getValue_bool_unknown() {
2942 expect(_boolValue(null).value, isNull); 2935 expect(_boolValue(null).toBoolValue(), isNull);
2943 } 2936 }
2944 2937
2945 void test_getValue_double_known() { 2938 void test_getValue_double_known() {
2946 double value = 2.3; 2939 double value = 2.3;
2947 expect(_doubleValue(value).value, value); 2940 expect(_doubleValue(value).toDoubleValue(), value);
2948 } 2941 }
2949 2942
2950 void test_getValue_double_unknown() { 2943 void test_getValue_double_unknown() {
2951 expect(_doubleValue(null).value, isNull); 2944 expect(_doubleValue(null).toDoubleValue(), isNull);
2952 } 2945 }
2953 2946
2954 void test_getValue_int_known() { 2947 void test_getValue_int_known() {
2955 int value = 23; 2948 int value = 23;
2956 expect(_intValue(value).value, value); 2949 expect(_intValue(value).toIntValue(), value);
2957 } 2950 }
2958 2951
2959 void test_getValue_int_unknown() { 2952 void test_getValue_int_unknown() {
2960 expect(_intValue(null).value, isNull); 2953 expect(_intValue(null).toIntValue(), isNull);
2961 } 2954 }
2962 2955
2963 void test_getValue_list_empty() { 2956 void test_getValue_list_empty() {
2964 Object result = _listValue().value; 2957 Object result = _listValue().toListValue();
2965 _assertInstanceOfObjectArray(result); 2958 _assertInstanceOfObjectArray(result);
2966 List<Object> array = result as List<Object>; 2959 List<Object> array = result as List<Object>;
2967 expect(array, hasLength(0)); 2960 expect(array, hasLength(0));
2968 } 2961 }
2969 2962
2970 void test_getValue_list_valid() { 2963 void test_getValue_list_valid() {
2971 Object result = _listValue([_intValue(23)]).value; 2964 Object result = _listValue([_intValue(23)]).toListValue();
2972 _assertInstanceOfObjectArray(result); 2965 _assertInstanceOfObjectArray(result);
2973 List<Object> array = result as List<Object>; 2966 List<Object> array = result as List<Object>;
2974 expect(array, hasLength(1)); 2967 expect(array, hasLength(1));
2975 } 2968 }
2976 2969
2977 void test_getValue_map_empty() { 2970 void test_getValue_map_empty() {
2978 Object result = _mapValue().value; 2971 Object result = _mapValue().toMapValue();
2979 EngineTestCase.assertInstanceOf((obj) => obj is Map, Map, result); 2972 EngineTestCase.assertInstanceOf((obj) => obj is Map, Map, result);
2980 Map map = result as Map; 2973 Map map = result as Map;
2981 expect(map, hasLength(0)); 2974 expect(map, hasLength(0));
2982 } 2975 }
2983 2976
2984 void test_getValue_map_valid() { 2977 void test_getValue_map_valid() {
2985 Object result = 2978 Object result =
2986 _mapValue([_stringValue("key"), _stringValue("value")]).value; 2979 _mapValue([_stringValue("key"), _stringValue("value")]).toMapValue();
2987 EngineTestCase.assertInstanceOf((obj) => obj is Map, Map, result); 2980 EngineTestCase.assertInstanceOf((obj) => obj is Map, Map, result);
2988 Map map = result as Map; 2981 Map map = result as Map;
2989 expect(map, hasLength(1)); 2982 expect(map, hasLength(1));
2990 } 2983 }
2991 2984
2992 void test_getValue_null() { 2985 void test_getValue_null() {
2993 expect(_nullValue().value, isNull); 2986 expect(_nullValue().isNull, isTrue);
2994 } 2987 }
2995 2988
2996 void test_getValue_string_known() { 2989 void test_getValue_string_known() {
2997 String value = "twenty-three"; 2990 String value = "twenty-three";
2998 expect(_stringValue(value).value, value); 2991 expect(_stringValue(value).toStringValue(), value);
2999 } 2992 }
3000 2993
3001 void test_getValue_string_unknown() { 2994 void test_getValue_string_unknown() {
3002 expect(_stringValue(null).value, isNull); 2995 expect(_stringValue(null).toStringValue(), isNull);
3003 } 2996 }
3004 2997
3005 void test_greaterThan_knownDouble_knownDouble_false() { 2998 void test_greaterThan_knownDouble_knownDouble_false() {
3006 _assertGreaterThan(_boolValue(false), _doubleValue(1.0), _doubleValue(2.0)); 2999 _assertGreaterThan(_boolValue(false), _doubleValue(1.0), _doubleValue(2.0));
3007 } 3000 }
3008 3001
3009 void test_greaterThan_knownDouble_knownDouble_true() { 3002 void test_greaterThan_knownDouble_knownDouble_true() {
3010 _assertGreaterThan(_boolValue(true), _doubleValue(2.0), _doubleValue(1.0)); 3003 _assertGreaterThan(_boolValue(true), _doubleValue(2.0), _doubleValue(1.0));
3011 } 3004 }
3012 3005
(...skipping 5381 matching lines...) Expand 10 before | Expand all | Expand 10 after
8394 Source source = resolver.resolveAbsolute(uri); 8387 Source source = resolver.resolveAbsolute(uri);
8395 expect(source, isNotNull); 8388 expect(source, isNotNull);
8396 expect(resolver.restoreAbsolute(source), uri); 8389 expect(resolver.restoreAbsolute(source), uri);
8397 expect( 8390 expect(
8398 resolver.restoreAbsolute( 8391 resolver.restoreAbsolute(
8399 new NonExistingSource(source.fullName, null, null)), 8392 new NonExistingSource(source.fullName, null, null)),
8400 uri); 8393 uri);
8401 } 8394 }
8402 } 8395 }
8403 8396
8404 @reflectiveTest
8405 class HtmlParserTest extends EngineTestCase {
8406 /**
8407 * The name of the 'script' tag in an HTML file.
8408 */
8409 static String _TAG_SCRIPT = "script";
8410 void fail_parse_scriptWithComment() {
8411 String scriptBody = r'''
8412 /**
8413 * <editable-label bind-value="dartAsignableValue">
8414 * </editable-label>
8415 */
8416 class Foo {}''';
8417 ht.HtmlUnit htmlUnit = parse("""
8418 <html>
8419 <body>
8420 <script type='application/dart'>
8421 $scriptBody
8422 </script>
8423 </body>
8424 </html>""");
8425 _validate(htmlUnit, [
8426 _t4("html", [
8427 _t4("body", [
8428 _t("script", _a(["type", "'application/dart'"]), scriptBody)
8429 ])
8430 ])
8431 ]);
8432 }
8433
8434 ht.HtmlUnit parse(String contents) {
8435 // TestSource source =
8436 // new TestSource.con1(FileUtilities2.createFile("/test.dart"), contents) ;
8437 ht.AbstractScanner scanner = new ht.StringScanner(null, contents);
8438 scanner.passThroughElements = <String>[_TAG_SCRIPT];
8439 ht.Token token = scanner.tokenize();
8440 LineInfo lineInfo = new LineInfo(scanner.lineStarts);
8441 GatheringErrorListener errorListener = new GatheringErrorListener();
8442 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
8443 ht.HtmlUnit unit =
8444 new ht.HtmlParser(null, errorListener, options).parse(token, lineInfo);
8445 errorListener.assertNoErrors();
8446 return unit;
8447 }
8448
8449 void test_parse_attribute() {
8450 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\"></body></html>");
8451 _validate(htmlUnit, [
8452 _t4("html", [
8453 _t("body", _a(["foo", "\"sdfsdf\""]), "")
8454 ])
8455 ]);
8456 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0];
8457 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0];
8458 expect(bodyNode.attributes[0].text, "sdfsdf");
8459 }
8460
8461 void test_parse_attribute_EOF() {
8462 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\"");
8463 _validate(htmlUnit, [
8464 _t4("html", [
8465 _t("body", _a(["foo", "\"sdfsdf\""]), "")
8466 ])
8467 ]);
8468 }
8469
8470 void test_parse_attribute_EOF_missing_quote() {
8471 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsd");
8472 _validate(htmlUnit, [
8473 _t4("html", [
8474 _t("body", _a(["foo", "\"sdfsd"]), "")
8475 ])
8476 ]);
8477 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0];
8478 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0];
8479 expect(bodyNode.attributes[0].text, "sdfsd");
8480 }
8481
8482 void test_parse_attribute_extra_quote() {
8483 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\"\"></body></html>");
8484 _validate(htmlUnit, [
8485 _t4("html", [
8486 _t("body", _a(["foo", "\"sdfsdf\""]), "")
8487 ])
8488 ]);
8489 }
8490
8491 void test_parse_attribute_single_quote() {
8492 ht.HtmlUnit htmlUnit = parse("<html><body foo='sdfsdf'></body></html>");
8493 _validate(htmlUnit, [
8494 _t4("html", [
8495 _t("body", _a(["foo", "'sdfsdf'"]), "")
8496 ])
8497 ]);
8498 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0];
8499 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0];
8500 expect(bodyNode.attributes[0].text, "sdfsdf");
8501 }
8502
8503 void test_parse_comment_embedded() {
8504 ht.HtmlUnit htmlUnit = parse("<html <!-- comment -->></html>");
8505 _validate(htmlUnit, [_t3("html", "")]);
8506 }
8507
8508 void test_parse_comment_first() {
8509 ht.HtmlUnit htmlUnit = parse("<!-- comment --><html></html>");
8510 _validate(htmlUnit, [_t3("html", "")]);
8511 }
8512
8513 void test_parse_comment_in_content() {
8514 ht.HtmlUnit htmlUnit = parse("<html><!-- comment --></html>");
8515 _validate(htmlUnit, [_t3("html", "<!-- comment -->")]);
8516 }
8517
8518 void test_parse_content() {
8519 ht.HtmlUnit htmlUnit = parse("<html>\n<p a=\"b\">blat \n </p>\n</html>");
8520 // ht.XmlTagNode.getContent() does not include whitespace
8521 // between '<' and '>' at this time
8522 _validate(htmlUnit, [
8523 _t3("html", "\n<pa=\"b\">blat \n </p>\n", [
8524 _t("p", _a(["a", "\"b\""]), "blat \n ")
8525 ])
8526 ]);
8527 }
8528
8529 void test_parse_content_none() {
8530 ht.HtmlUnit htmlUnit = parse("<html><p/>blat<p/></html>");
8531 _validate(htmlUnit, [
8532 _t3("html", "<p/>blat<p/>", [_t3("p", ""), _t3("p", "")])
8533 ]);
8534 }
8535
8536 void test_parse_declaration() {
8537 ht.HtmlUnit htmlUnit = parse("<!DOCTYPE html>\n\n<html><p></p></html>");
8538 _validate(htmlUnit, [
8539 _t4("html", [_t3("p", "")])
8540 ]);
8541 }
8542
8543 void test_parse_directive() {
8544 ht.HtmlUnit htmlUnit = parse("<?xml ?>\n\n<html><p></p></html>");
8545 _validate(htmlUnit, [
8546 _t4("html", [_t3("p", "")])
8547 ]);
8548 }
8549
8550 void test_parse_getAttribute() {
8551 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\"></body></html>");
8552 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0];
8553 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0];
8554 expect(bodyNode.getAttribute("foo").text, "sdfsdf");
8555 expect(bodyNode.getAttribute("bar"), null);
8556 expect(bodyNode.getAttribute(null), null);
8557 }
8558
8559 void test_parse_getAttributeText() {
8560 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\"></body></html>");
8561 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0];
8562 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0];
8563 expect(bodyNode.getAttributeText("foo"), "sdfsdf");
8564 expect(bodyNode.getAttributeText("bar"), null);
8565 expect(bodyNode.getAttributeText(null), null);
8566 }
8567
8568 void test_parse_headers() {
8569 String code = r'''
8570 <html>
8571 <body>
8572 <h2>000</h2>
8573 <div>
8574 111
8575 </div>
8576 </body>
8577 </html>''';
8578 ht.HtmlUnit htmlUnit = parse(code);
8579 _validate(htmlUnit, [
8580 _t4("html", [
8581 _t4("body", [_t3("h2", "000"), _t4("div")])
8582 ])
8583 ]);
8584 }
8585
8586 void test_parse_script() {
8587 ht.HtmlUnit htmlUnit =
8588 parse("<html><script >here is <p> some</script></html>");
8589 _validate(htmlUnit, [
8590 _t4("html", [_t3("script", "here is <p> some")])
8591 ]);
8592 }
8593
8594 void test_parse_self_closing() {
8595 ht.HtmlUnit htmlUnit = parse("<html>foo<br>bar</html>");
8596 _validate(htmlUnit, [
8597 _t3("html", "foo<br>bar", [_t3("br", "")])
8598 ]);
8599 }
8600
8601 void test_parse_self_closing_declaration() {
8602 ht.HtmlUnit htmlUnit = parse("<!DOCTYPE html><html>foo</html>");
8603 _validate(htmlUnit, [_t3("html", "foo")]);
8604 }
8605
8606 XmlValidator_Attributes _a(List<String> keyValuePairs) =>
8607 new XmlValidator_Attributes(keyValuePairs);
8608 XmlValidator_Tag _t(
8609 String tag, XmlValidator_Attributes attributes, String content,
8610 [List<XmlValidator_Tag> children = XmlValidator_Tag.EMPTY_LIST]) =>
8611 new XmlValidator_Tag(tag, attributes, content, children);
8612 XmlValidator_Tag _t3(String tag, String content,
8613 [List<XmlValidator_Tag> children = XmlValidator_Tag.EMPTY_LIST]) =>
8614 new XmlValidator_Tag(
8615 tag, new XmlValidator_Attributes(), content, children);
8616 XmlValidator_Tag _t4(String tag,
8617 [List<XmlValidator_Tag> children = XmlValidator_Tag.EMPTY_LIST]) =>
8618 new XmlValidator_Tag(tag, new XmlValidator_Attributes(), null, children);
8619 void _validate(ht.HtmlUnit htmlUnit, List<XmlValidator_Tag> expectedTags) {
8620 XmlValidator validator = new XmlValidator();
8621 validator.expectTags(expectedTags);
8622 htmlUnit.accept(validator);
8623 validator.assertValid();
8624 }
8625 }
8626
8627 @reflectiveTest
8628 class HtmlTagInfoBuilderTest extends HtmlParserTest {
8629 void test_builder() {
8630 HtmlTagInfoBuilder builder = new HtmlTagInfoBuilder();
8631 ht.HtmlUnit unit = parse(r'''
8632 <html>
8633 <body>
8634 <div id="x"></div>
8635 <p class='c'></p>
8636 <div class='c'></div>
8637 </body>
8638 </html>''');
8639 unit.accept(builder);
8640 HtmlTagInfo info = builder.getTagInfo();
8641 expect(info, isNotNull);
8642 List<String> allTags = info.allTags;
8643 expect(allTags, hasLength(4));
8644 expect(info.getTagWithId("x"), "div");
8645 List<String> tagsWithClass = info.getTagsWithClass("c");
8646 expect(tagsWithClass, hasLength(2));
8647 }
8648 }
8649
8650 @reflectiveTest
8651 class HtmlUnitBuilderTest {
8652 InternalAnalysisContext _context;
8653
8654 void setUp() {
8655 _context = AnalysisContextFactory.contextWithCore();
8656 }
8657
8658 void tearDown() {
8659 _context = null;
8660 }
8661
8662 void test_embedded_script() {
8663 HtmlElementImpl element = _build(r'''
8664 <html>
8665 <script type="application/dart">foo=2;</script>
8666 </html>''');
8667 _validate(element, [
8668 _s(_l([_v("foo")]))
8669 ]);
8670 }
8671
8672 void test_embedded_script_no_content() {
8673 HtmlElementImpl element = _build(r'''
8674 <html>
8675 <script type="application/dart"></script>
8676 </html>''');
8677 _validate(element, [_s(_l())]);
8678 }
8679
8680 void test_external_script() {
8681 HtmlElementImpl element = _build(r'''
8682 <html>
8683 <script type="application/dart" src="other.dart"/>
8684 </html>''');
8685 _validate(element, [_s2("other.dart")]);
8686 }
8687
8688 void test_external_script_no_source() {
8689 HtmlElementImpl element = _build(r'''
8690 <html>
8691 <script type="application/dart"/>
8692 </html>''');
8693 _validate(element, [_s2(null)]);
8694 }
8695
8696 void test_external_script_with_content() {
8697 HtmlElementImpl element = _build(r'''
8698 <html>
8699 <script type="application/dart" src="other.dart">blat=2;</script>
8700 </html>''');
8701 _validate(element, [_s2("other.dart")]);
8702 }
8703
8704 void test_no_scripts() {
8705 HtmlElementImpl element = _build(r'''
8706 <!DOCTYPE html>
8707 <html><p></p></html>''');
8708 _validate(element, []);
8709 }
8710
8711 void test_two_dart_scripts() {
8712 HtmlElementImpl element = _build(r'''
8713 <html>
8714 <script type="application/dart">bar=2;</script>
8715 <script type="application/dart" src="other.dart"/>
8716 <script src="dart.js"/>
8717 </html>''');
8718 _validate(element, [
8719 _s(_l([_v("bar")])),
8720 _s2("other.dart")
8721 ]);
8722 }
8723
8724 HtmlElementImpl _build(String contents) {
8725 TestSource source = new TestSource(
8726 FileUtilities2.createFile("/test.html").getAbsolutePath(), contents);
8727 ChangeSet changeSet = new ChangeSet();
8728 changeSet.addedSource(source);
8729 _context.applyChanges(changeSet);
8730 HtmlUnitBuilder builder = new HtmlUnitBuilder(_context);
8731 return builder.buildHtmlElement(source, _context.parseHtmlUnit(source));
8732 }
8733
8734 HtmlUnitBuilderTest_ExpectedLibrary _l(
8735 [List<HtmlUnitBuilderTest_ExpectedVariable> expectedVariables =
8736 HtmlUnitBuilderTest_ExpectedVariable.EMPTY_LIST]) =>
8737 new HtmlUnitBuilderTest_ExpectedLibrary(this, expectedVariables);
8738 _ExpectedScript _s(HtmlUnitBuilderTest_ExpectedLibrary expectedLibrary) =>
8739 new _ExpectedScript.con1(expectedLibrary);
8740 _ExpectedScript _s2(String scriptSourcePath) =>
8741 new _ExpectedScript.con2(scriptSourcePath);
8742 HtmlUnitBuilderTest_ExpectedVariable _v(String varName) =>
8743 new HtmlUnitBuilderTest_ExpectedVariable(varName);
8744 void _validate(
8745 HtmlElementImpl element, List<_ExpectedScript> expectedScripts) {
8746 expect(element.context, same(_context));
8747 List<HtmlScriptElement> scripts = element.scripts;
8748 expect(scripts, isNotNull);
8749 expect(scripts, hasLength(expectedScripts.length));
8750 for (int scriptIndex = 0; scriptIndex < scripts.length; scriptIndex++) {
8751 expectedScripts[scriptIndex]._validate(scriptIndex, scripts[scriptIndex]);
8752 }
8753 }
8754 }
8755
8756 class HtmlUnitBuilderTest_ExpectedLibrary {
8757 final HtmlUnitBuilderTest HtmlUnitBuilderTest_this;
8758 final List<HtmlUnitBuilderTest_ExpectedVariable> _expectedVariables;
8759 HtmlUnitBuilderTest_ExpectedLibrary(this.HtmlUnitBuilderTest_this,
8760 [this._expectedVariables =
8761 HtmlUnitBuilderTest_ExpectedVariable.EMPTY_LIST]);
8762 void _validate(int scriptIndex, EmbeddedHtmlScriptElementImpl script) {
8763 LibraryElement library = script.scriptLibrary;
8764 expect(library, isNotNull, reason: "script $scriptIndex");
8765 expect(script.context, same(HtmlUnitBuilderTest_this._context),
8766 reason: "script $scriptIndex");
8767 CompilationUnitElement unit = library.definingCompilationUnit;
8768 expect(unit, isNotNull, reason: "script $scriptIndex");
8769 List<TopLevelVariableElement> variables = unit.topLevelVariables;
8770 expect(variables, hasLength(_expectedVariables.length));
8771 for (int index = 0; index < variables.length; index++) {
8772 _expectedVariables[index].validate(scriptIndex, variables[index]);
8773 }
8774 expect(library.enclosingElement, same(script),
8775 reason: "script $scriptIndex");
8776 }
8777 }
8778
8779 class HtmlUnitBuilderTest_ExpectedVariable {
8780 static const List<HtmlUnitBuilderTest_ExpectedVariable> EMPTY_LIST =
8781 const <HtmlUnitBuilderTest_ExpectedVariable>[];
8782 final String _expectedName;
8783 HtmlUnitBuilderTest_ExpectedVariable(this._expectedName);
8784 void validate(int scriptIndex, TopLevelVariableElement variable) {
8785 expect(variable, isNotNull, reason: "script $scriptIndex");
8786 expect(variable.name, _expectedName, reason: "script $scriptIndex");
8787 }
8788 }
8789
8790 /**
8791 * Instances of the class `HtmlWarningCodeTest` test the generation of HTML warn ing codes.
8792 */
8793 @reflectiveTest
8794 class HtmlWarningCodeTest {
8795 /**
8796 * The analysis context used to resolve the HTML files.
8797 */
8798 InternalAnalysisContext _context;
8799
8800 /**
8801 * The contents of the 'test.html' file.
8802 */
8803 String _contents;
8804
8805 /**
8806 * The list of reported errors.
8807 */
8808 List<AnalysisError> _errors;
8809
8810 void setUp() {
8811 _context = AnalysisContextFactory.contextWithCore();
8812 }
8813
8814 void tearDown() {
8815 _context = null;
8816 _contents = null;
8817 _errors = null;
8818 }
8819
8820 void test_invalidUri() {
8821 _verify(
8822 r'''
8823 <html>
8824 <script type='application/dart' src='ht:'/>
8825 </html>''',
8826 [HtmlWarningCode.INVALID_URI]);
8827 _assertErrorLocation2(_errors[0], "ht:");
8828 }
8829
8830 void test_uriDoesNotExist() {
8831 _verify(
8832 r'''
8833 <html>
8834 <script type='application/dart' src='other.dart'/>
8835 </html>''',
8836 [HtmlWarningCode.URI_DOES_NOT_EXIST]);
8837 _assertErrorLocation2(_errors[0], "other.dart");
8838 }
8839
8840 void _assertErrorLocation(
8841 AnalysisError error, int expectedOffset, int expectedLength) {
8842 expect(error.offset, expectedOffset, reason: error.toString());
8843 expect(error.length, expectedLength, reason: error.toString());
8844 }
8845
8846 void _assertErrorLocation2(AnalysisError error, String expectedString) {
8847 _assertErrorLocation(
8848 error, _contents.indexOf(expectedString), expectedString.length);
8849 }
8850
8851 void _verify(String contents, List<ErrorCode> expectedErrorCodes) {
8852 this._contents = contents;
8853 TestSource source = new TestSource(
8854 FileUtilities2.createFile("/test.html").getAbsolutePath(), contents);
8855 ChangeSet changeSet = new ChangeSet();
8856 changeSet.addedSource(source);
8857 _context.applyChanges(changeSet);
8858 HtmlUnitBuilder builder = new HtmlUnitBuilder(_context);
8859 builder.buildHtmlElement(source, _context.parseHtmlUnit(source));
8860 GatheringErrorListener errorListener = new GatheringErrorListener();
8861 errorListener.addAll2(builder.errorListener);
8862 errorListener.assertErrorsWithCodes(expectedErrorCodes);
8863 _errors = errorListener.errors;
8864 }
8865 }
8866
8867 /** 8397 /**
8868 * Instances of the class `MockDartSdk` implement a [DartSdk]. 8398 * Instances of the class `MockDartSdk` implement a [DartSdk].
8869 */ 8399 */
8870 class MockDartSdk implements DartSdk { 8400 class MockDartSdk implements DartSdk {
8871 @override 8401 @override
8872 AnalysisContext get context => null; 8402 AnalysisContext get context => null;
8873 8403
8874 @override 8404 @override
8875 List<SdkLibrary> get sdkLibraries => null; 8405 List<SdkLibrary> get sdkLibraries => null;
8876 8406
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
9372 8902
9373 class XmlValidator_Tag { 8903 class XmlValidator_Tag {
9374 static const List<XmlValidator_Tag> EMPTY_LIST = const <XmlValidator_Tag>[]; 8904 static const List<XmlValidator_Tag> EMPTY_LIST = const <XmlValidator_Tag>[];
9375 final String _tag; 8905 final String _tag;
9376 final XmlValidator_Attributes _attributes; 8906 final XmlValidator_Attributes _attributes;
9377 final String _content; 8907 final String _content;
9378 final List<XmlValidator_Tag> _children; 8908 final List<XmlValidator_Tag> _children;
9379 XmlValidator_Tag(this._tag, this._attributes, this._content, 8909 XmlValidator_Tag(this._tag, this._attributes, this._content,
9380 [this._children = EMPTY_LIST]); 8910 [this._children = EMPTY_LIST]);
9381 } 8911 }
9382
9383 class _ExpectedScript {
9384 String _expectedExternalScriptName;
9385 HtmlUnitBuilderTest_ExpectedLibrary _expectedLibrary;
9386 _ExpectedScript.con1(HtmlUnitBuilderTest_ExpectedLibrary expectedLibrary) {
9387 this._expectedExternalScriptName = null;
9388 this._expectedLibrary = expectedLibrary;
9389 }
9390 _ExpectedScript.con2(String expectedExternalScriptPath) {
9391 this._expectedExternalScriptName = expectedExternalScriptPath;
9392 this._expectedLibrary = null;
9393 }
9394 void _validate(int scriptIndex, HtmlScriptElement script) {
9395 if (_expectedLibrary != null) {
9396 _validateEmbedded(scriptIndex, script);
9397 } else {
9398 _validateExternal(scriptIndex, script);
9399 }
9400 }
9401
9402 void _validateEmbedded(int scriptIndex, HtmlScriptElement script) {
9403 if (script is! EmbeddedHtmlScriptElementImpl) {
9404 fail(
9405 "Expected script $scriptIndex to be embedded, but found ${script != nu ll ? script.runtimeType : "null"}");
9406 }
9407 EmbeddedHtmlScriptElementImpl embeddedScript =
9408 script as EmbeddedHtmlScriptElementImpl;
9409 _expectedLibrary._validate(scriptIndex, embeddedScript);
9410 }
9411
9412 void _validateExternal(int scriptIndex, HtmlScriptElement script) {
9413 if (script is! ExternalHtmlScriptElementImpl) {
9414 fail(
9415 "Expected script $scriptIndex to be external with src=$_expectedExtern alScriptName but found ${script != null ? script.runtimeType : "null"}");
9416 }
9417 ExternalHtmlScriptElementImpl externalScript =
9418 script as ExternalHtmlScriptElementImpl;
9419 Source scriptSource = externalScript.scriptSource;
9420 if (_expectedExternalScriptName == null) {
9421 expect(scriptSource, isNull, reason: "script $scriptIndex");
9422 } else {
9423 expect(scriptSource, isNotNull, reason: "script $scriptIndex");
9424 String actualExternalScriptName = scriptSource.shortName;
9425 expect(actualExternalScriptName, _expectedExternalScriptName,
9426 reason: "script $scriptIndex");
9427 }
9428 }
9429 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/enum_test.dart ('k') | pkg/analyzer/test/generated/engine_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698