1f0fe212b2
Change-Id: I988692263486d277017a057768fcae2edeca3889 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195279 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
38 lines
1.3 KiB
Dart
38 lines
1.3 KiB
Dart
// Copyright (c) 2018, 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.
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
import '../../../tool/lsp_spec/typescript_parser.dart' as ast;
|
|
|
|
void main() {
|
|
group('dartType mapping', () {
|
|
test('handles basic types', () {
|
|
expect(_simple('string').dartType, equals('String'));
|
|
expect(_simple('boolean').dartType, equals('bool'));
|
|
expect(_simple('any').dartType, equals('dynamic'));
|
|
expect(_simple('object').dartType, equals('dynamic'));
|
|
expect(_simple('int').dartType, equals('int'));
|
|
expect(_simple('num').dartType, equals('num'));
|
|
});
|
|
|
|
test('handles union types', () {
|
|
expect(_union(['string', 'int']).dartTypeWithTypeArgs,
|
|
equals('Either2<String, int>'));
|
|
});
|
|
|
|
test('handles arrays', () {
|
|
expect(_array('string').dartTypeWithTypeArgs, equals('List<String>'));
|
|
});
|
|
});
|
|
}
|
|
|
|
ast.ArrayType _array(String name) => ast.ArrayType(_simple(name));
|
|
|
|
ast.Type _simple(String name) =>
|
|
ast.Type(ast.Token(ast.TokenType.IDENTIFIER, name), []);
|
|
|
|
ast.UnionType _union(List<String> names) =>
|
|
ast.UnionType(names.map(_simple).toList());
|