| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /// Test that poi.dart can serialize a scope. | |
| 6 | |
| 7 library trydart.serialize_test; | |
| 8 | |
| 9 import 'dart:io' show | |
| 10 Platform; | |
| 11 | |
| 12 import 'dart:async' show | |
| 13 Future; | |
| 14 | |
| 15 import 'dart:convert' show | |
| 16 JSON; | |
| 17 | |
| 18 import 'package:try/poi/poi.dart' as poi; | |
| 19 | |
| 20 import 'package:async_helper/async_helper.dart'; | |
| 21 | |
| 22 import 'package:expect/expect.dart'; | |
| 23 | |
| 24 import 'package:compiler/src/elements/elements.dart' show | |
| 25 Element; | |
| 26 | |
| 27 import 'package:compiler/src/source_file_provider.dart' show | |
| 28 FormattingDiagnosticHandler; | |
| 29 | |
| 30 Future testInteresting() { | |
| 31 poi.cachedCompiler = null; | |
| 32 Uri script = Platform.script.resolve('data/interesting.dart'); | |
| 33 FormattingDiagnosticHandler handler = new FormattingDiagnosticHandler(); | |
| 34 | |
| 35 int position = 263; | |
| 36 | |
| 37 Future future = poi.runPoi(script, position, handler.provider, handler); | |
| 38 return future.then((Element element) { | |
| 39 Uri foundScript = element.compilationUnit.script.resourceUri; | |
| 40 Expect.stringEquals('$script', '$foundScript'); | |
| 41 Expect.stringEquals('fisk', element.name); | |
| 42 | |
| 43 String scope = poi.scopeInformation(element, position); | |
| 44 Expect.stringEquals( | |
| 45 JSON.encode(expectedInteresting), JSON.encode(JSON.decode(scope)), | |
| 46 scope); | |
| 47 return testSubclass(handler); | |
| 48 }); | |
| 49 } | |
| 50 | |
| 51 Future testSubclass(FormattingDiagnosticHandler handler) { | |
| 52 poi.cachedCompiler = null; | |
| 53 int position = 506; | |
| 54 | |
| 55 Uri script = Platform.script.resolve('data/subclass.dart'); | |
| 56 | |
| 57 Future future = poi.runPoi(script, position, handler.provider, handler); | |
| 58 return future.then((Element element) { | |
| 59 Uri foundScript = element.compilationUnit.script.resourceUri; | |
| 60 Expect.stringEquals('$script', '$foundScript'); | |
| 61 Expect.stringEquals('instanceMethod2', element.name); | |
| 62 | |
| 63 String scope = poi.scopeInformation(element, position); | |
| 64 Expect.stringEquals( | |
| 65 JSON.encode(expectedSubclass), JSON.encode(JSON.decode(scope)), scope); | |
| 66 | |
| 67 return testAbstractField(handler); | |
| 68 }); | |
| 69 } | |
| 70 | |
| 71 Future testAbstractField(FormattingDiagnosticHandler handler) { | |
| 72 poi.cachedCompiler = null; | |
| 73 int position = 321; | |
| 74 | |
| 75 Uri script = Platform.script.resolve('data/abstract_field.dart'); | |
| 76 | |
| 77 Future future = poi.runPoi(script, position, handler.provider, handler); | |
| 78 return future.then((Element element) { | |
| 79 Uri foundScript = element.compilationUnit.script.resourceUri; | |
| 80 Expect.stringEquals('$script', '$foundScript'); | |
| 81 Expect.stringEquals('method', element.name); | |
| 82 | |
| 83 String scope = poi.scopeInformation(element, position); | |
| 84 Expect.stringEquals( | |
| 85 JSON.encode(expectedAbstractField), JSON.encode(JSON.decode(scope)), | |
| 86 scope); | |
| 87 }); | |
| 88 } | |
| 89 | |
| 90 void main() { | |
| 91 asyncTest(testInteresting); | |
| 92 } | |
| 93 | |
| 94 final expectedInteresting = { | |
| 95 "name": "fisk", | |
| 96 "kind": "function", | |
| 97 "type": "() -> dynamic", | |
| 98 "enclosing": { | |
| 99 "name": "Foo", | |
| 100 "kind": "class side", | |
| 101 "members": [ | |
| 102 { | |
| 103 "kind": "generative_constructor", | |
| 104 "type": "() -> Foo" | |
| 105 } | |
| 106 ], | |
| 107 "enclosing": { | |
| 108 "name": "Foo", | |
| 109 "kind": "instance side", | |
| 110 "members": [ | |
| 111 { | |
| 112 "name": "fisk", | |
| 113 "kind": "function", | |
| 114 "type": "() -> dynamic" | |
| 115 }, | |
| 116 { | |
| 117 "name": "hest", | |
| 118 "kind": "function", | |
| 119 "type": "() -> dynamic" | |
| 120 }, | |
| 121 ], | |
| 122 "enclosing": { | |
| 123 "name": "interesting", | |
| 124 "kind": "library", | |
| 125 "members": [ | |
| 126 { | |
| 127 "name": "Foo", | |
| 128 "kind": "class" | |
| 129 }, | |
| 130 { | |
| 131 "name": "main", | |
| 132 "kind": "function", | |
| 133 "type": "() -> dynamic" | |
| 134 } | |
| 135 ], | |
| 136 "enclosing": { | |
| 137 "kind": "imports", | |
| 138 "members": coreImports, | |
| 139 "enclosing": object, | |
| 140 } | |
| 141 } | |
| 142 } | |
| 143 } | |
| 144 }; | |
| 145 | |
| 146 final expectedSubclass = { | |
| 147 "name": "instanceMethod2", | |
| 148 "kind": "function", | |
| 149 "type": "() -> dynamic", | |
| 150 "enclosing": { | |
| 151 "name": "C", | |
| 152 "kind": "class side", | |
| 153 "members": [ | |
| 154 { | |
| 155 "name": "staticMethod1", | |
| 156 "kind": "function", | |
| 157 "type": "() -> dynamic" | |
| 158 }, | |
| 159 { | |
| 160 "name": "staticMethod2", | |
| 161 "kind": "function", | |
| 162 "type": "() -> dynamic" | |
| 163 }, | |
| 164 { | |
| 165 "kind": "generative_constructor", | |
| 166 "type": "() -> C" | |
| 167 } | |
| 168 ], | |
| 169 "enclosing": { | |
| 170 "name": "C", | |
| 171 "kind": "instance side", | |
| 172 "members": [ | |
| 173 { | |
| 174 "name": "instanceMethod1", | |
| 175 "kind": "function", | |
| 176 "type": "() -> dynamic" | |
| 177 }, | |
| 178 { | |
| 179 "name": "instanceMethod2", | |
| 180 "kind": "function", | |
| 181 "type": "() -> dynamic" | |
| 182 } | |
| 183 ], | |
| 184 "enclosing": { | |
| 185 "name": "subclass", | |
| 186 "kind": "library", | |
| 187 "members": [ | |
| 188 { | |
| 189 "name": "S", | |
| 190 "kind": "class" | |
| 191 }, | |
| 192 { | |
| 193 "name": "C", | |
| 194 "kind": "class" | |
| 195 }, | |
| 196 { | |
| 197 "name": "main", | |
| 198 "kind": "function", | |
| 199 "type": "() -> dynamic" | |
| 200 }, | |
| 201 { | |
| 202 "name": "p", | |
| 203 "kind": "prefix" | |
| 204 } | |
| 205 ], | |
| 206 "enclosing": { | |
| 207 "kind": "imports", | |
| 208 "members": [ | |
| 209 { | |
| 210 "name": "Foo", | |
| 211 "kind": "class" | |
| 212 }, | |
| 213 { | |
| 214 "name": "main", | |
| 215 "kind": "function", | |
| 216 "type": "() -> dynamic" | |
| 217 }, | |
| 218 ]..addAll(coreImports), | |
| 219 "enclosing": { | |
| 220 "name": "S", | |
| 221 "kind": "instance side", | |
| 222 "members": [ | |
| 223 { | |
| 224 "name": "superMethod1", | |
| 225 "kind": "function", | |
| 226 "type": "() -> dynamic" | |
| 227 }, | |
| 228 { | |
| 229 "name": "superMethod2", | |
| 230 "kind": "function", | |
| 231 "type": "() -> dynamic" | |
| 232 }, | |
| 233 ], | |
| 234 "enclosing": { | |
| 235 "name": "P", | |
| 236 "kind": "instance side", | |
| 237 "members": [ | |
| 238 { | |
| 239 "name": "pMethod1", | |
| 240 "kind": "function", | |
| 241 "type": "() -> dynamic" | |
| 242 }, | |
| 243 { | |
| 244 "name": "pMethod2", | |
| 245 "kind": "function", | |
| 246 "type": "() -> dynamic" | |
| 247 }, | |
| 248 { | |
| 249 "name": "_pMethod1", | |
| 250 "kind": "function", | |
| 251 "type": "() -> dynamic" | |
| 252 }, | |
| 253 { | |
| 254 "name": "_pMethod2", | |
| 255 "kind": "function", | |
| 256 "type": "() -> dynamic" | |
| 257 }, | |
| 258 ], | |
| 259 "enclosing": object, | |
| 260 } | |
| 261 } | |
| 262 } | |
| 263 } | |
| 264 } | |
| 265 } | |
| 266 }; | |
| 267 | |
| 268 final expectedAbstractField = { | |
| 269 "name": "method", | |
| 270 "kind": "function", | |
| 271 "type": "() -> dynamic", | |
| 272 "enclosing": { | |
| 273 "name": "A", | |
| 274 "kind": "class side", | |
| 275 "members": [ | |
| 276 { | |
| 277 "kind": "generative_constructor", | |
| 278 "type": "() -> A" | |
| 279 } | |
| 280 ], | |
| 281 "enclosing": { | |
| 282 "name": "A", | |
| 283 "kind": "instance side", | |
| 284 "members": [ | |
| 285 { | |
| 286 "name": "foo", | |
| 287 "kind": "getter" | |
| 288 }, | |
| 289 { | |
| 290 "name": "foo", | |
| 291 "kind": "setter" | |
| 292 }, | |
| 293 { | |
| 294 "name": "method", | |
| 295 "kind": "function", | |
| 296 "type": "() -> dynamic" | |
| 297 } | |
| 298 ], | |
| 299 "enclosing": { | |
| 300 "name": "abstract_field", | |
| 301 "kind": "library", | |
| 302 "members": [ | |
| 303 { | |
| 304 "name": "A", | |
| 305 "kind": "class" | |
| 306 }, | |
| 307 { | |
| 308 "name": "bar", | |
| 309 "kind": "getter" | |
| 310 }, | |
| 311 { | |
| 312 "name": "bar", | |
| 313 "kind": "getter" | |
| 314 }, | |
| 315 { | |
| 316 "name": "main", | |
| 317 "kind": "function", | |
| 318 "type": "() -> dynamic" | |
| 319 } | |
| 320 ], | |
| 321 "enclosing": { | |
| 322 "kind": "imports", | |
| 323 "members": coreImports, | |
| 324 "enclosing": object | |
| 325 }, | |
| 326 }, | |
| 327 }, | |
| 328 }, | |
| 329 }; | |
| 330 | |
| 331 final coreImports = [ | |
| 332 { | |
| 333 "name": "Deprecated", | |
| 334 "kind": "class" | |
| 335 }, | |
| 336 { | |
| 337 "name": "deprecated", | |
| 338 "kind": "field", | |
| 339 "type": "Deprecated" | |
| 340 }, | |
| 341 { | |
| 342 "name": "override", | |
| 343 "kind": "field", | |
| 344 "type": "Object" | |
| 345 }, | |
| 346 { | |
| 347 "name": "proxy", | |
| 348 "kind": "field", | |
| 349 "type": "Object" | |
| 350 }, | |
| 351 { | |
| 352 "name": "bool", | |
| 353 "kind": "class" | |
| 354 }, | |
| 355 { | |
| 356 "name": "Comparator", | |
| 357 "kind": "typedef" | |
| 358 }, | |
| 359 { | |
| 360 "name": "Comparable", | |
| 361 "kind": "class" | |
| 362 }, | |
| 363 { | |
| 364 "name": "DateTime", | |
| 365 "kind": "class" | |
| 366 }, | |
| 367 { | |
| 368 "name": "double", | |
| 369 "kind": "class" | |
| 370 }, | |
| 371 { | |
| 372 "name": "Duration", | |
| 373 "kind": "class" | |
| 374 }, | |
| 375 { | |
| 376 "name": "Error", | |
| 377 "kind": "class" | |
| 378 }, | |
| 379 { | |
| 380 "name": "AssertionError", | |
| 381 "kind": "class" | |
| 382 }, | |
| 383 { | |
| 384 "name": "TypeError", | |
| 385 "kind": "class" | |
| 386 }, | |
| 387 { | |
| 388 "name": "CastError", | |
| 389 "kind": "class" | |
| 390 }, | |
| 391 { | |
| 392 "name": "NullThrownError", | |
| 393 "kind": "class" | |
| 394 }, | |
| 395 { | |
| 396 "name": "ArgumentError", | |
| 397 "kind": "class" | |
| 398 }, | |
| 399 { | |
| 400 "name": "RangeError", | |
| 401 "kind": "class" | |
| 402 }, | |
| 403 { | |
| 404 "name": "IndexError", | |
| 405 "kind": "class" | |
| 406 }, | |
| 407 { | |
| 408 "name": "FallThroughError", | |
| 409 "kind": "class" | |
| 410 }, | |
| 411 { | |
| 412 "name": "AbstractClassInstantiationError", | |
| 413 "kind": "class" | |
| 414 }, | |
| 415 { | |
| 416 "name": "NoSuchMethodError", | |
| 417 "kind": "class" | |
| 418 }, | |
| 419 { | |
| 420 "name": "UnsupportedError", | |
| 421 "kind": "class" | |
| 422 }, | |
| 423 { | |
| 424 "name": "UnimplementedError", | |
| 425 "kind": "class" | |
| 426 }, | |
| 427 { | |
| 428 "name": "StateError", | |
| 429 "kind": "class" | |
| 430 }, | |
| 431 { | |
| 432 "name": "ConcurrentModificationError", | |
| 433 "kind": "class" | |
| 434 }, | |
| 435 { | |
| 436 "name": "OutOfMemoryError", | |
| 437 "kind": "class" | |
| 438 }, | |
| 439 { | |
| 440 "name": "StackOverflowError", | |
| 441 "kind": "class" | |
| 442 }, | |
| 443 { | |
| 444 "name": "CyclicInitializationError", | |
| 445 "kind": "class" | |
| 446 }, | |
| 447 { | |
| 448 "name": "Exception", | |
| 449 "kind": "class" | |
| 450 }, | |
| 451 { | |
| 452 "name": "FormatException", | |
| 453 "kind": "class" | |
| 454 }, | |
| 455 { | |
| 456 "name": "IntegerDivisionByZeroException", | |
| 457 "kind": "class" | |
| 458 }, | |
| 459 { | |
| 460 "name": "Expando", | |
| 461 "kind": "class" | |
| 462 }, | |
| 463 { | |
| 464 "name": "Function", | |
| 465 "kind": "class" | |
| 466 }, | |
| 467 { | |
| 468 "name": "identical", | |
| 469 "kind": "function", | |
| 470 "type": "(Object, Object) -> bool" | |
| 471 }, | |
| 472 { | |
| 473 "name": "identityHashCode", | |
| 474 "kind": "function", | |
| 475 "type": "(Object) -> int" | |
| 476 }, | |
| 477 { | |
| 478 "name": "int", | |
| 479 "kind": "class" | |
| 480 }, | |
| 481 { | |
| 482 "name": "Invocation", | |
| 483 "kind": "class" | |
| 484 }, | |
| 485 { | |
| 486 "name": "Iterable", | |
| 487 "kind": "class" | |
| 488 }, | |
| 489 { | |
| 490 "name": "BidirectionalIterator", | |
| 491 "kind": "class" | |
| 492 }, | |
| 493 { | |
| 494 "name": "Iterator", | |
| 495 "kind": "class" | |
| 496 }, | |
| 497 { | |
| 498 "name": "List", | |
| 499 "kind": "class" | |
| 500 }, | |
| 501 { | |
| 502 "name": "Map", | |
| 503 "kind": "class" | |
| 504 }, | |
| 505 { | |
| 506 "name": "Null", | |
| 507 "kind": "class" | |
| 508 }, | |
| 509 { | |
| 510 "name": "num", | |
| 511 "kind": "class" | |
| 512 }, | |
| 513 { | |
| 514 "name": "Object", | |
| 515 "kind": "class" | |
| 516 }, | |
| 517 { | |
| 518 "name": "Pattern", | |
| 519 "kind": "class" | |
| 520 }, | |
| 521 { | |
| 522 "name": "Match", | |
| 523 "kind": "class" | |
| 524 }, | |
| 525 { | |
| 526 "name": "print", | |
| 527 "kind": "function", | |
| 528 "type": "(Object) -> void" | |
| 529 }, | |
| 530 { | |
| 531 "name": "RegExp", | |
| 532 "kind": "class" | |
| 533 }, | |
| 534 { | |
| 535 "name": "Resource", | |
| 536 "kind": "class" | |
| 537 }, | |
| 538 { | |
| 539 "name": "Set", | |
| 540 "kind": "class" | |
| 541 }, | |
| 542 { | |
| 543 "name": "Sink", | |
| 544 "kind": "class" | |
| 545 }, | |
| 546 { | |
| 547 "name": "StackTrace", | |
| 548 "kind": "class" | |
| 549 }, | |
| 550 { | |
| 551 "name": "Stopwatch", | |
| 552 "kind": "class" | |
| 553 }, | |
| 554 { | |
| 555 "name": "String", | |
| 556 "kind": "class" | |
| 557 }, | |
| 558 { | |
| 559 "name": "Runes", | |
| 560 "kind": "class" | |
| 561 }, | |
| 562 { | |
| 563 "name": "RuneIterator", | |
| 564 "kind": "class" | |
| 565 }, | |
| 566 { | |
| 567 "name": "StringBuffer", | |
| 568 "kind": "class" | |
| 569 }, | |
| 570 { | |
| 571 "name": "StringSink", | |
| 572 "kind": "class" | |
| 573 }, | |
| 574 { | |
| 575 "name": "Symbol", | |
| 576 "kind": "class" | |
| 577 }, | |
| 578 { | |
| 579 "name": "Type", | |
| 580 "kind": "class" | |
| 581 }, | |
| 582 { | |
| 583 "name": "Uri", | |
| 584 "kind": "class" | |
| 585 }, | |
| 586 { | |
| 587 "name": "UriData", | |
| 588 "kind": "class" | |
| 589 } | |
| 590 ]; | |
| 591 | |
| 592 final object = { | |
| 593 "name": "Object", | |
| 594 "kind": "instance side", | |
| 595 "members": [ | |
| 596 { | |
| 597 "name": "==", | |
| 598 "kind": "function", | |
| 599 "type": "(dynamic) -> bool" | |
| 600 }, | |
| 601 { | |
| 602 "name": "hashCode", | |
| 603 "kind": "getter" | |
| 604 }, | |
| 605 { | |
| 606 "name": "toString", | |
| 607 "kind": "function", | |
| 608 "type": "() -> String" | |
| 609 }, | |
| 610 { | |
| 611 "name": "noSuchMethod", | |
| 612 "kind": "function", | |
| 613 "type": "(Invocation) -> dynamic" | |
| 614 }, | |
| 615 { | |
| 616 "name": "runtimeType", | |
| 617 "kind": "getter" | |
| 618 } | |
| 619 ] | |
| 620 }; | |
| OLD | NEW |