-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add typeNameOf(DartType). (dart-lang/source_gen#295)
* Add typeNameOf(DartType). * Dartfmt.
- Loading branch information
1 parent
8adb3ce
commit 1d90811
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Increase timeouts on this test which resolves source code and can be slow. | ||
@Timeout.factor(2.0) | ||
import 'package:analyzer/dart/element/element.dart'; | ||
import 'package:build_test/build_test.dart'; | ||
import 'package:source_gen/source_gen.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
ClassElement example; | ||
|
||
setUpAll(() async { | ||
const source = r''' | ||
library example; | ||
abstract class Example { | ||
ClassType classType(); | ||
FunctionType functionType(); | ||
} | ||
class ClassType {} | ||
typedef FunctionType(); | ||
'''; | ||
example = await resolveSource( | ||
source, | ||
(resolver) => resolver | ||
.findLibraryByName('example') | ||
.then((e) => e.getType('Example'))); | ||
}); | ||
|
||
test('should return the name of a class type', () { | ||
final classType = example.methods.first.returnType; | ||
expect(typeNameOf(classType), 'ClassType'); | ||
}); | ||
|
||
test('should return the name of a function type', () { | ||
final functionType = example.methods.last.returnType; | ||
expect(typeNameOf(functionType), 'FunctionType'); | ||
}); | ||
} |