| OLD | NEW | 
|---|
| 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 single_library_test; | 5 library native_extensions_test; | 
| 6 | 6 | 
| 7 import 'dart:io'; | 7 import 'dart:io'; | 
| 8 | 8 | 
| 9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; | 
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; | 
| 11 | 11 | 
| 12 import '../lib/src/exports/mirrors_util.dart' as dart2js_util; | 12 import '../lib/src/exports/mirrors_util.dart' as dart2js_util; | 
| 13 import '../lib/docgen.dart'; | 13 import '../lib/docgen.dart'; | 
| 14 | 14 | 
| 15 const String DART_LIBRARY = ''' | 15 const String DART_LIBRARY = ''' | 
| 16   library test; | 16   library sample_synchronous_extension; | 
| 17   /** |  | 
| 18    * Doc comment for class [A]. |  | 
| 19    * |  | 
| 20    * Multiline Test |  | 
| 21    */ |  | 
| 22   /* |  | 
| 23    * Normal comment for class A. |  | 
| 24    */ |  | 
| 25   class A { |  | 
| 26 | 17 | 
| 27     int _someNumber; | 18   import 'dart-ext:sample_extension'; | 
| 28 | 19 | 
| 29     A() { | 20   // The simplest way to call native code: top-level functions. | 
| 30       _someNumber = 12; | 21   int systemRand() native "SystemRand"; | 
| 31     } | 22   bool systemSrand(int seed) native "SystemSrand"; | 
| 32 | 23 | 
| 33     /** | 24   void main() { | 
| 34      * Test for linking to parameter [A] | 25     systemRand(); | 
| 35      */ | 26     systemSrand(4); | 
| 36     void doThis(int A) { |  | 
| 37       print(A); |  | 
| 38     } |  | 
| 39   } |  | 
| 40 |  | 
| 41   main() { |  | 
| 42     A a = new A(); |  | 
| 43     a.doThis(5); |  | 
| 44   } | 27   } | 
| 45 '''; | 28 '''; | 
| 46 | 29 | 
| 47 main() { | 30 main() { | 
| 48   group('Generate docs for', () { | 31   group('Generate docs for', () { | 
| 49     test('one simple file.', () { | 32     test('file with native extensions.', () { | 
| 50       var temporaryDir = Directory.systemTemp.createTempSync('single_library_'); | 33       var temporaryDir = Directory.systemTemp.createTempSync('native_ext_'); | 
| 51       var fileName = path.join(temporaryDir.path, 'temp.dart'); | 34       var fileName = path.join(temporaryDir.path, 'temp.dart'); | 
| 52       var file = new File(fileName); | 35       var file = new File(fileName); | 
| 53       file.writeAsStringSync(DART_LIBRARY); | 36       file.writeAsStringSync(DART_LIBRARY); | 
| 54 | 37 | 
| 55       return getMirrorSystem([new Uri.file(fileName)], false) | 38       return getMirrorSystem([new Uri.file(fileName)], false) | 
| 56         .then((mirrorSystem) { | 39         .then((mirrorSystem) { | 
| 57           var testLibraryUri = new Uri.file(path.absolute(fileName), | 40           var testLibraryUri = new Uri.file(path.absolute(fileName), | 
| 58                                             windows: Platform.isWindows); | 41                                             windows: Platform.isWindows); | 
| 59           var library = new Library(mirrorSystem.libraries[testLibraryUri]); | 42           var library = new Library(mirrorSystem.libraries[testLibraryUri]); | 
| 60           expect(library is Library, isTrue); | 43           expect(library is Library, isTrue); | 
| 61 | 44 | 
| 62           var classTypes = library.classes; | 45           var classTypes = library.classes; | 
| 63           var classes = []; | 46           var classes = []; | 
| 64           classes.addAll(classTypes.values); | 47           classes.addAll(classTypes.values); | 
| 65           classes.addAll(library.errors.values); | 48           classes.addAll(library.errors.values); | 
| 66           expect(classes.every((e) => e is Class), isTrue); | 49           expect(classes.every((e) => e is Class), isTrue); | 
| 67 | 50 | 
| 68           expect(library.typedefs.values.every((e) => e is Typedef), isTrue); | 51           expect(library.typedefs.values.every((e) => e is Typedef), isTrue); | 
| 69 | 52 | 
| 70           var classMethodTypes = []; | 53           var classMethodTypes = []; | 
| 71           classes.forEach((e) { | 54           classes.forEach((e) { | 
| 72             classMethodTypes.add(e.methods); | 55             classMethodTypes.add(e.methods); | 
| 73             classMethodTypes.add(e.inheritedMethods); | 56             classMethodTypes.add(e.inheritedMethods); | 
| 74           }); | 57           }); | 
| 75           expect(classMethodTypes.every((e) => e is Map<String, Method>), isTrue
     ); | 58           expect(classMethodTypes.every((e) => e is Map<String, Method>), | 
|  | 59                  isTrue); | 
| 76 | 60 | 
| 77           var classMethods = []; | 61           var classMethods = []; | 
| 78           classMethodTypes.forEach((e) { | 62           classMethodTypes.forEach((e) { | 
| 79             classMethods.addAll(e.values); | 63             classMethods.addAll(e.values); | 
| 80           }); | 64           }); | 
| 81           expect(classMethods.every((e) => e is Method), isTrue); | 65           expect(classMethods.every((e) => e is Method), isTrue); | 
| 82 | 66 | 
| 83           var methodParameters = []; | 67           var methodParameters = []; | 
| 84           classMethods.forEach((e) { | 68           classMethods.forEach((e) { | 
| 85             methodParameters.addAll(e.parameters.values); | 69             methodParameters.addAll(e.parameters.values); | 
| 86           }); | 70           }); | 
| 87           expect(methodParameters.every((e) => e is Parameter), isTrue); | 71           expect(methodParameters.every((e) => e is Parameter), isTrue); | 
| 88 | 72 | 
| 89           var functionTypes = library.functions; | 73           var functionTypes = library.functions; | 
| 90           expect(functionTypes is Map<String, Method>, isTrue); | 74           expect(functionTypes is Map<String, Method>, isTrue); | 
| 91 | 75 | 
| 92           var functions = []; | 76           var functions = []; | 
| 93           functions.addAll(functionTypes.values); | 77           functions.addAll(functionTypes.values); | 
| 94           expect(functions.every((e) => e is Method), isTrue); | 78           expect(functions.every((e) => e is Method), isTrue); | 
| 95 | 79 | 
| 96           var functionParameters = []; | 80           var functionParameters = []; | 
| 97           functions.forEach((e) { | 81           functions.forEach((e) { | 
| 98             functionParameters.addAll(e.parameters.values); | 82             functionParameters.addAll(e.parameters.values); | 
| 99           }); | 83           }); | 
| 100           expect(functionParameters.every((e) => e is Parameter), isTrue); | 84           expect(functionParameters.every((e) => e is Parameter), isTrue); | 
| 101 | 85 | 
| 102           var variables = library.variables.values; | 86           var variables = library.variables.values; | 
| 103           expect(variables.every((e) => e is Variable), isTrue); | 87           expect(variables.every((e) => e is Variable), isTrue); | 
| 104 | 88 | 
| 105           /// Testing fixReference | 89           // Testing trying to refer to m1 function | 
| 106           // Testing Doc comment for class [A]. | 90           var libraryDocComment = | 
| 107           var libraryMirror = mirrorSystem.libraries[testLibraryUri]; | 91               library.fixReference('systemRand').children.first.text; | 
| 108           var classMirror = | 92           expect(libraryDocComment, 'sample_synchronous_extension.systemRand'); | 
| 109               dart2js_util.classesOf(libraryMirror.declarations).first; |  | 
| 110           var classDocComment = library.fixReference('A').children.first.text; |  | 
| 111           expect(classDocComment, 'test.A'); |  | 
| 112 | 93 | 
| 113           // Test for linking to parameter [A] | 94           libraryDocComment = | 
| 114           var method = getDocgenObject( | 95               library.fixReference('systemSrand').children.first.text; | 
| 115               classMirror.declarations[dart2js_util.symbolOf('doThis')]); | 96           expect(libraryDocComment, 'sample_synchronous_extension.systemSrand'); | 
| 116           var methodParameterDocComment = method.fixReference( |  | 
| 117               'A').children.first.text; |  | 
| 118           expect(methodParameterDocComment, 'test.A.doThis.A'); |  | 
| 119 |  | 
| 120           // Testing trying to refer to doThis function |  | 
| 121           var methodDocComment = method.fixReference( |  | 
| 122               'doThis').children.first.text; |  | 
| 123           expect(methodDocComment, 'test.A.doThis'); |  | 
| 124 |  | 
| 125           // Testing something with no reference |  | 
| 126           var libraryDocComment = method.fixReference('foobar').text; |  | 
| 127           expect(libraryDocComment, 'foobar'); |  | 
| 128         }).whenComplete(() => temporaryDir.deleteSync(recursive: true)); | 97         }).whenComplete(() => temporaryDir.deleteSync(recursive: true)); | 
| 129     }); | 98     }); | 
| 130   }); | 99   }); | 
| 131 } | 100 } | 
| OLD | NEW | 
|---|