blob: fbf2615000f294e61d4ec207e24fea7d4c36fe8f [file] [log] [blame]
// 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;
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.Type _simple(String name) =>
new ast.Type(new ast.Token(ast.TokenType.IDENTIFIER, name), []);
ast.ArrayType _array(String name) => new ast.ArrayType(_simple(name));
ast.UnionType _union(List<String> names) =>
new ast.UnionType(names.map(_simple).toList());