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

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

Issue 768233002: Extract DocumentationCommentToken with field. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Keep only last multi-line or continuous single-line documentation comments. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/scanner.dart ('k') | no next file » | 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.parser_test; 5 library engine.parser_test;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/error.dart'; 9 import 'package:analyzer/src/generated/error.dart';
10 import 'package:analyzer/src/generated/incremental_scanner.dart'; 10 import 'package:analyzer/src/generated/incremental_scanner.dart';
(...skipping 6724 matching lines...) Expand 10 before | Expand all | Expand 10 after
6735 SimpleIdentifier, 6735 SimpleIdentifier,
6736 reference.identifier); 6736 reference.identifier);
6737 expect(identifier, isNotNull); 6737 expect(identifier, isNotNull);
6738 expect(identifier.isSynthetic, isTrue); 6738 expect(identifier.isSynthetic, isTrue);
6739 expect(identifier.token, isNotNull); 6739 expect(identifier.token, isNotNull);
6740 expect(identifier.name, ""); 6740 expect(identifier.name, "");
6741 expect(identifier.offset, 5); 6741 expect(identifier.offset, 5);
6742 } 6742 }
6743 6743
6744 void test_parseCommentReferences_multiLine() { 6744 void test_parseCommentReferences_multiLine() {
6745 CommentToken token = new CommentToken( 6745 DocumentationCommentToken token = new DocumentationCommentToken(
6746 TokenType.MULTI_LINE_COMMENT, 6746 TokenType.MULTI_LINE_COMMENT,
6747 "/** xxx [a] yyy [bb] zzz */", 6747 "/** xxx [a] yyy [bb] zzz */",
6748 3); 6748 3);
6749 List<CommentToken> tokens = <CommentToken>[token]; 6749 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[token];
6750 List<CommentReference> references = 6750 List<CommentReference> references =
6751 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], ""); 6751 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], "");
6752 List<Token> tokenReferences = token.references; 6752 List<Token> tokenReferences = token.references;
6753 expect(references, hasLength(2)); 6753 expect(references, hasLength(2));
6754 expect(tokenReferences, hasLength(2)); 6754 expect(tokenReferences, hasLength(2));
6755 { 6755 {
6756 CommentReference reference = references[0]; 6756 CommentReference reference = references[0];
6757 expect(reference, isNotNull); 6757 expect(reference, isNotNull);
6758 expect(reference.identifier, isNotNull); 6758 expect(reference.identifier, isNotNull);
6759 expect(reference.offset, 12); 6759 expect(reference.offset, 12);
6760 // the reference is recorded in the comment token 6760 // the reference is recorded in the comment token
6761 Token referenceToken = tokenReferences[0]; 6761 Token referenceToken = tokenReferences[0];
6762 expect(referenceToken.offset, 12); 6762 expect(referenceToken.offset, 12);
6763 expect(referenceToken.lexeme, 'a'); 6763 expect(referenceToken.lexeme, 'a');
6764 } 6764 }
6765 { 6765 {
6766 CommentReference reference = references[1]; 6766 CommentReference reference = references[1];
6767 expect(reference, isNotNull); 6767 expect(reference, isNotNull);
6768 expect(reference.identifier, isNotNull); 6768 expect(reference.identifier, isNotNull);
6769 expect(reference.offset, 20); 6769 expect(reference.offset, 20);
6770 // the reference is recorded in the comment token 6770 // the reference is recorded in the comment token
6771 Token referenceToken = tokenReferences[1]; 6771 Token referenceToken = tokenReferences[1];
6772 expect(referenceToken.offset, 20); 6772 expect(referenceToken.offset, 20);
6773 expect(referenceToken.lexeme, 'bb'); 6773 expect(referenceToken.lexeme, 'bb');
6774 } 6774 }
6775 } 6775 }
6776 6776
6777 void test_parseCommentReferences_notClosed_noIdentifier() { 6777 void test_parseCommentReferences_notClosed_noIdentifier() {
6778 List<CommentToken> tokens = <CommentToken>[ 6778 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
6779 new CommentToken(TokenType.MULTI_LINE_COMMENT, "/** [ some text", 5)]; 6779 new DocumentationCommentToken(
6780 TokenType.MULTI_LINE_COMMENT,
6781 "/** [ some text",
6782 5)];
6780 List<CommentReference> references = 6783 List<CommentReference> references =
6781 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], ""); 6784 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], "");
6782 expect(references, hasLength(1)); 6785 expect(references, hasLength(1));
6783 CommentReference reference = references[0]; 6786 CommentReference reference = references[0];
6784 expect(reference, isNotNull); 6787 expect(reference, isNotNull);
6785 expect(reference.identifier, isNotNull); 6788 expect(reference.identifier, isNotNull);
6786 expect(reference.identifier.isSynthetic, isTrue); 6789 expect(reference.identifier.isSynthetic, isTrue);
6787 expect(reference.identifier.name, ""); 6790 expect(reference.identifier.name, "");
6788 } 6791 }
6789 6792
6790 void test_parseCommentReferences_notClosed_withIdentifier() { 6793 void test_parseCommentReferences_notClosed_withIdentifier() {
6791 List<CommentToken> tokens = <CommentToken>[ 6794 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
6792 new CommentToken(TokenType.MULTI_LINE_COMMENT, "/** [namePrefix some tex t", 5)]; 6795 new DocumentationCommentToken(
6796 TokenType.MULTI_LINE_COMMENT,
6797 "/** [namePrefix some text",
6798 5)];
6793 List<CommentReference> references = 6799 List<CommentReference> references =
6794 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], ""); 6800 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], "");
6795 expect(references, hasLength(1)); 6801 expect(references, hasLength(1));
6796 CommentReference reference = references[0]; 6802 CommentReference reference = references[0];
6797 expect(reference, isNotNull); 6803 expect(reference, isNotNull);
6798 expect(reference.identifier, isNotNull); 6804 expect(reference.identifier, isNotNull);
6799 expect(reference.identifier.isSynthetic, isFalse); 6805 expect(reference.identifier.isSynthetic, isFalse);
6800 expect(reference.identifier.name, "namePrefix"); 6806 expect(reference.identifier.name, "namePrefix");
6801 } 6807 }
6802 6808
6803 void test_parseCommentReferences_singleLine() { 6809 void test_parseCommentReferences_singleLine() {
6804 List<CommentToken> tokens = <CommentToken>[ 6810 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
6805 new CommentToken(TokenType.SINGLE_LINE_COMMENT, "/// xxx [a] yyy [b] zzz ", 3), 6811 new DocumentationCommentToken(
6806 new CommentToken(TokenType.SINGLE_LINE_COMMENT, "/// x [c]", 28)]; 6812 TokenType.SINGLE_LINE_COMMENT,
6813 "/// xxx [a] yyy [b] zzz",
6814 3),
6815 new DocumentationCommentToken(TokenType.SINGLE_LINE_COMMENT, "/// x [c]" , 28)];
6807 List<CommentReference> references = 6816 List<CommentReference> references =
6808 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], ""); 6817 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], "");
6809 expect(references, hasLength(3)); 6818 expect(references, hasLength(3));
6810 CommentReference reference = references[0]; 6819 CommentReference reference = references[0];
6811 expect(reference, isNotNull); 6820 expect(reference, isNotNull);
6812 expect(reference.identifier, isNotNull); 6821 expect(reference.identifier, isNotNull);
6813 expect(reference.offset, 12); 6822 expect(reference.offset, 12);
6814 reference = references[1]; 6823 reference = references[1];
6815 expect(reference, isNotNull); 6824 expect(reference, isNotNull);
6816 expect(reference.identifier, isNotNull); 6825 expect(reference.identifier, isNotNull);
6817 expect(reference.offset, 20); 6826 expect(reference.offset, 20);
6818 reference = references[2]; 6827 reference = references[2];
6819 expect(reference, isNotNull); 6828 expect(reference, isNotNull);
6820 expect(reference.identifier, isNotNull); 6829 expect(reference.identifier, isNotNull);
6821 expect(reference.offset, 35); 6830 expect(reference.offset, 35);
6822 } 6831 }
6823 6832
6824 void test_parseCommentReferences_skipCodeBlock_bracketed() { 6833 void test_parseCommentReferences_skipCodeBlock_bracketed() {
6825 List<CommentToken> tokens = <CommentToken>[ 6834 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
6826 new CommentToken( 6835 new DocumentationCommentToken(
6827 TokenType.MULTI_LINE_COMMENT, 6836 TokenType.MULTI_LINE_COMMENT,
6828 "/** [:xxx [a] yyy:] [b] zzz */", 6837 "/** [:xxx [a] yyy:] [b] zzz */",
6829 3)]; 6838 3)];
6830 List<CommentReference> references = 6839 List<CommentReference> references =
6831 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], ""); 6840 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], "");
6832 expect(references, hasLength(1)); 6841 expect(references, hasLength(1));
6833 CommentReference reference = references[0]; 6842 CommentReference reference = references[0];
6834 expect(reference, isNotNull); 6843 expect(reference, isNotNull);
6835 expect(reference.identifier, isNotNull); 6844 expect(reference.identifier, isNotNull);
6836 expect(reference.offset, 24); 6845 expect(reference.offset, 24);
6837 } 6846 }
6838 6847
6839 void test_parseCommentReferences_skipCodeBlock_spaces() { 6848 void test_parseCommentReferences_skipCodeBlock_spaces() {
6840 List<CommentToken> tokens = <CommentToken>[ 6849 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
6841 new CommentToken( 6850 new DocumentationCommentToken(
6842 TokenType.MULTI_LINE_COMMENT, 6851 TokenType.MULTI_LINE_COMMENT,
6843 "/**\n * a[i]\n * xxx [i] zzz\n */", 6852 "/**\n * a[i]\n * xxx [i] zzz\n */",
6844 3)]; 6853 3)];
6845 List<CommentReference> references = 6854 List<CommentReference> references =
6846 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], ""); 6855 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], "");
6847 expect(references, hasLength(1)); 6856 expect(references, hasLength(1));
6848 CommentReference reference = references[0]; 6857 CommentReference reference = references[0];
6849 expect(reference, isNotNull); 6858 expect(reference, isNotNull);
6850 expect(reference.identifier, isNotNull); 6859 expect(reference.identifier, isNotNull);
6851 expect(reference.offset, 27); 6860 expect(reference.offset, 27);
6852 } 6861 }
6853 6862
6854 void test_parseCommentReferences_skipLinkDefinition() { 6863 void test_parseCommentReferences_skipLinkDefinition() {
6855 List<CommentToken> tokens = <CommentToken>[ 6864 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
6856 new CommentToken( 6865 new DocumentationCommentToken(
6857 TokenType.MULTI_LINE_COMMENT, 6866 TokenType.MULTI_LINE_COMMENT,
6858 "/** [a]: http://www.google.com (Google) [b] zzz */", 6867 "/** [a]: http://www.google.com (Google) [b] zzz */",
6859 3)]; 6868 3)];
6860 List<CommentReference> references = 6869 List<CommentReference> references =
6861 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], ""); 6870 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], "");
6862 expect(references, hasLength(1)); 6871 expect(references, hasLength(1));
6863 CommentReference reference = references[0]; 6872 CommentReference reference = references[0];
6864 expect(reference, isNotNull); 6873 expect(reference, isNotNull);
6865 expect(reference.identifier, isNotNull); 6874 expect(reference.identifier, isNotNull);
6866 expect(reference.offset, 44); 6875 expect(reference.offset, 44);
6867 } 6876 }
6868 6877
6869 void test_parseCommentReferences_skipLinked() { 6878 void test_parseCommentReferences_skipLinked() {
6870 List<CommentToken> tokens = <CommentToken>[ 6879 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
6871 new CommentToken( 6880 new DocumentationCommentToken(
6872 TokenType.MULTI_LINE_COMMENT, 6881 TokenType.MULTI_LINE_COMMENT,
6873 "/** [a](http://www.google.com) [b] zzz */", 6882 "/** [a](http://www.google.com) [b] zzz */",
6874 3)]; 6883 3)];
6875 List<CommentReference> references = 6884 List<CommentReference> references =
6876 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], ""); 6885 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], "");
6877 expect(references, hasLength(1)); 6886 expect(references, hasLength(1));
6878 CommentReference reference = references[0]; 6887 CommentReference reference = references[0];
6879 expect(reference, isNotNull); 6888 expect(reference, isNotNull);
6880 expect(reference.identifier, isNotNull); 6889 expect(reference.identifier, isNotNull);
6881 expect(reference.offset, 35); 6890 expect(reference.offset, 35);
6882 } 6891 }
6883 6892
6884 void test_parseCommentReferences_skipReferenceLink() { 6893 void test_parseCommentReferences_skipReferenceLink() {
6885 List<CommentToken> tokens = <CommentToken>[ 6894 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
6886 new CommentToken(TokenType.MULTI_LINE_COMMENT, "/** [a][c] [b] zzz */", 3)]; 6895 new DocumentationCommentToken(
6896 TokenType.MULTI_LINE_COMMENT,
6897 "/** [a][c] [b] zzz */",
6898 3)];
6887 List<CommentReference> references = 6899 List<CommentReference> references =
6888 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], ""); 6900 ParserTestCase.parse("parseCommentReferences", <Object>[tokens], "");
6889 expect(references, hasLength(1)); 6901 expect(references, hasLength(1));
6890 CommentReference reference = references[0]; 6902 CommentReference reference = references[0];
6891 expect(reference, isNotNull); 6903 expect(reference, isNotNull);
6892 expect(reference.identifier, isNotNull); 6904 expect(reference.identifier, isNotNull);
6893 expect(reference.offset, 15); 6905 expect(reference.offset, 15);
6894 } 6906 }
6895 6907
6896 void test_parseCompilationUnit_abstractAsPrefix_parameterized() { 6908 void test_parseCompilationUnit_abstractAsPrefix_parameterized() {
(...skipping 4007 matching lines...) Expand 10 before | Expand all | Expand 10 after
10904 // Parse the source. 10916 // Parse the source.
10905 // 10917 //
10906 Parser parser = new Parser(null, listener); 10918 Parser parser = new Parser(null, listener);
10907 return invokeParserMethodImpl( 10919 return invokeParserMethodImpl(
10908 parser, 10920 parser,
10909 methodName, 10921 methodName,
10910 <Object>[tokenStream], 10922 <Object>[tokenStream],
10911 tokenStream) as Token; 10923 tokenStream) as Token;
10912 } 10924 }
10913 } 10925 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/scanner.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698