| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; | 5 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; |
| 6 import 'package:front_end/src/fasta/scanner/keyword.dart' as fasta; | |
| 7 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 6 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
| 8 import 'package:front_end/src/scanner/token.dart'; | 7 import 'package:front_end/src/scanner/token.dart'; |
| 9 import 'package:front_end/src/scanner/reader.dart' as analyzer; | 8 import 'package:front_end/src/scanner/reader.dart' as analyzer; |
| 10 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
| 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 12 import 'scanner_roundtrip_test.dart' show TestScanner; | 11 import 'scanner_roundtrip_test.dart' show TestScanner; |
| 13 | 12 |
| 14 main() { | 13 main() { |
| 15 defineReflectiveSuite(() { | 14 defineReflectiveSuite(() { |
| 16 defineReflectiveTests(TokenTest); | 15 defineReflectiveTests(TokenTest); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 147 } |
| 149 | 148 |
| 150 void test_matchesAny() { | 149 void test_matchesAny() { |
| 151 var scanner = new StringScanner('true', includeComments: true); | 150 var scanner = new StringScanner('true', includeComments: true); |
| 152 var token = scanner.tokenize(); | 151 var token = scanner.tokenize(); |
| 153 expect(token.matchesAny([TokenType.KEYWORD]), true); | 152 expect(token.matchesAny([TokenType.KEYWORD]), true); |
| 154 expect(token.matchesAny([TokenType.AMPERSAND, TokenType.KEYWORD]), true); | 153 expect(token.matchesAny([TokenType.AMPERSAND, TokenType.KEYWORD]), true); |
| 155 expect(token.matchesAny([TokenType.AMPERSAND]), false); | 154 expect(token.matchesAny([TokenType.AMPERSAND]), false); |
| 156 } | 155 } |
| 157 | 156 |
| 158 /// Return all fasta and all analyzer keywords | |
| 159 List<Keyword> get _allKeywords => | |
| 160 new List.from(Keyword.values)..addAll(fasta.Keyword.values); | |
| 161 | |
| 162 void test_all_keywords() { | |
| 163 var keywords = new Set<fasta.Keyword>.from(fasta.Keyword.values); | |
| 164 for (Keyword kw in Keyword.values) { | |
| 165 expect(keywords.remove(kw), isTrue, reason: kw.name); | |
| 166 } | |
| 167 expect(keywords, isEmpty); | |
| 168 } | |
| 169 | |
| 170 void test_built_in_keywords() { | 157 void test_built_in_keywords() { |
| 171 var builtInKeywords = new Set<Keyword>.from([ | 158 var builtInKeywords = new Set<Keyword>.from([ |
| 172 Keyword.ABSTRACT, | 159 Keyword.ABSTRACT, |
| 173 Keyword.AS, | 160 Keyword.AS, |
| 174 Keyword.COVARIANT, | 161 Keyword.COVARIANT, |
| 175 Keyword.DEFERRED, | 162 Keyword.DEFERRED, |
| 176 Keyword.DYNAMIC, | 163 Keyword.DYNAMIC, |
| 177 Keyword.EXPORT, | 164 Keyword.EXPORT, |
| 178 Keyword.EXTERNAL, | 165 Keyword.EXTERNAL, |
| 179 Keyword.FACTORY, | 166 Keyword.FACTORY, |
| 180 Keyword.GET, | 167 Keyword.GET, |
| 181 Keyword.IMPLEMENTS, | 168 Keyword.IMPLEMENTS, |
| 182 Keyword.IMPORT, | 169 Keyword.IMPORT, |
| 183 Keyword.LIBRARY, | 170 Keyword.LIBRARY, |
| 184 Keyword.OPERATOR, | 171 Keyword.OPERATOR, |
| 185 Keyword.PART, | 172 Keyword.PART, |
| 186 Keyword.SET, | 173 Keyword.SET, |
| 187 Keyword.STATIC, | 174 Keyword.STATIC, |
| 188 Keyword.TYPEDEF, | 175 Keyword.TYPEDEF, |
| 189 ]); | 176 ]); |
| 190 for (Keyword keyword in _allKeywords) { | 177 for (Keyword keyword in Keyword.values) { |
| 191 var isBuiltIn = builtInKeywords.contains(keyword); | 178 var isBuiltIn = builtInKeywords.contains(keyword); |
| 192 expect(keyword.isBuiltIn, isBuiltIn, reason: keyword.name); | 179 expect(keyword.isBuiltIn, isBuiltIn, reason: keyword.name); |
| 193 expect((keyword as fasta.Keyword).isBuiltIn, isBuiltIn, | 180 expect(keyword.isBuiltIn, isBuiltIn, reason: keyword.name); |
| 194 reason: keyword.name); | |
| 195 } | 181 } |
| 196 } | 182 } |
| 197 | 183 |
| 198 void test_pseudo_keywords() { | 184 void test_pseudo_keywords() { |
| 199 var pseudoKeywords = new Set<Keyword>.from([ | 185 var pseudoKeywords = new Set<Keyword>.from([ |
| 200 fasta.Keyword.ASYNC, | 186 Keyword.ASYNC, |
| 201 fasta.Keyword.AWAIT, | 187 Keyword.AWAIT, |
| 202 fasta.Keyword.FUNCTION, | 188 Keyword.FUNCTION, |
| 203 fasta.Keyword.HIDE, | 189 Keyword.HIDE, |
| 204 fasta.Keyword.NATIVE, | 190 Keyword.NATIVE, |
| 205 fasta.Keyword.OF, | 191 Keyword.OF, |
| 206 fasta.Keyword.ON, | 192 Keyword.ON, |
| 207 fasta.Keyword.PATCH, | 193 Keyword.PATCH, |
| 208 fasta.Keyword.SHOW, | 194 Keyword.SHOW, |
| 209 fasta.Keyword.SOURCE, | 195 Keyword.SOURCE, |
| 210 fasta.Keyword.SYNC, | 196 Keyword.SYNC, |
| 211 fasta.Keyword.YIELD, | 197 Keyword.YIELD, |
| 212 ]); | 198 ]); |
| 213 for (Keyword keyword in _allKeywords) { | 199 for (Keyword keyword in Keyword.values) { |
| 214 var isPseudo = pseudoKeywords.contains(keyword); | 200 var isPseudo = pseudoKeywords.contains(keyword); |
| 215 expect((keyword as fasta.Keyword).isPseudo, isPseudo, | 201 expect(keyword.isPseudo, isPseudo, reason: keyword.name); |
| 216 reason: keyword.name); | |
| 217 } | 202 } |
| 218 } | 203 } |
| 219 | 204 |
| 220 void test_value() { | 205 void test_value() { |
| 221 var scanner = new StringScanner('true & "home"', includeComments: true); | 206 var scanner = new StringScanner('true & "home"', includeComments: true); |
| 222 var token = scanner.tokenize(); | 207 var token = scanner.tokenize(); |
| 223 // Keywords | 208 // Keywords |
| 224 expect(token.lexeme, 'true'); | 209 expect(token.lexeme, 'true'); |
| 225 expect(token.value(), Keyword.TRUE); | 210 expect(token.value(), Keyword.TRUE); |
| 226 // General tokens | 211 // General tokens |
| 227 token = token.next; | 212 token = token.next; |
| 228 expect(token.lexeme, '&'); | 213 expect(token.lexeme, '&'); |
| 229 expect(token.value(), '&'); | 214 expect(token.value(), '&'); |
| 230 // String tokens | 215 // String tokens |
| 231 token = token.next; | 216 token = token.next; |
| 232 expect(token.lexeme, '"home"'); | 217 expect(token.lexeme, '"home"'); |
| 233 expect(token.value(), '"home"'); | 218 expect(token.value(), '"home"'); |
| 234 } | 219 } |
| 235 } | 220 } |
| OLD | NEW |