This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle generic types in LSP spec parsing
The regex wasn't picking up generate type args (in interface definitions or usages in field definitions). This adds <> characters to the regex and handles them in mapping of types (as well as adds some additional tests to cover this). Change-Id: I8187b3d2abb2b35c0d7638839e3116700cfbf9e0 Reviewed-on: https://dart-review.googlesource.com/c/81004 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Danny Tuppeny <dantup@google.com>
- Loading branch information
Showing
6 changed files
with
258 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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/codegen_dart.dart'; | ||
|
||
main() { | ||
group('mapType', () { | ||
test('handles basic types', () { | ||
expect(mapType(['string']), equals('String')); | ||
expect(mapType(['boolean']), equals('bool')); | ||
expect(mapType(['any']), equals('dynamic')); | ||
expect(mapType(['object']), equals('dynamic')); | ||
expect(mapType(['int']), equals('int')); | ||
expect(mapType(['num']), equals('num')); | ||
}); | ||
|
||
test('handles union types', () { | ||
expect(mapType(['string', 'int']), equals('Either2<String, int>')); | ||
expect(mapType(['string | int']), equals('Either2<String, int>')); | ||
}); | ||
|
||
test('handles arrays', () { | ||
expect(mapType(['string[]']), equals('List<String>')); | ||
expect(mapType(['Array<string>']), equals('List<String>')); | ||
}); | ||
|
||
test('handles types with args', () { | ||
expect(mapType(['Class<string[]>']), equals('Class<List<String>>')); | ||
expect(mapType(['Array<string | num>']), | ||
equals('List<Either2<String, num>>')); | ||
}); | ||
|
||
test('handles complex nested types', () { | ||
expect( | ||
mapType([ | ||
'Array<string>', | ||
'any[]', | ||
'Response<A>', | ||
'Request<Array<string | num>>' | ||
]), | ||
equals( | ||
'Either4<List<String>, List<dynamic>, Response<A>, Request<List<Either2<String, num>>>>')); | ||
}); | ||
}); | ||
} |
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
Oops, something went wrong.