Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Nov 29, 2024
1 parent af9da2f commit 27032c9
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 9 deletions.
186 changes: 178 additions & 8 deletions pkgs/swift2objc/test/unit/parse_function_info_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ void main() {
));

final info = parseFunctionInfo(json, emptySymbolgraph);
final outputParams = info.params;

final expectedParams = [
Parameter(
Expand All @@ -78,7 +77,7 @@ void main() {
),
];

expectEqualParams(outputParams, expectedParams);
expectEqualParams(info.params, expectedParams);
expect(info.throws, isFalse);
});

Expand Down Expand Up @@ -121,7 +120,6 @@ void main() {
));

final info = parseFunctionInfo(json, emptySymbolgraph);
final outputParams = info.params;

final expectedParams = [
Parameter(
Expand All @@ -140,7 +138,7 @@ void main() {
),
];

expectEqualParams(outputParams, expectedParams);
expectEqualParams(info.params, expectedParams);
expect(info.throws, isFalse);
});

Expand All @@ -163,7 +161,6 @@ void main() {
));

final info = parseFunctionInfo(json, emptySymbolgraph);
final outputParams = info.params;

final expectedParams = [
Parameter(
Expand All @@ -172,7 +169,7 @@ void main() {
),
];

expectEqualParams(outputParams, expectedParams);
expectEqualParams(info.params, expectedParams);
expect(info.throws, isFalse);
});

Expand All @@ -187,11 +184,184 @@ void main() {
));

final info = parseFunctionInfo(json, emptySymbolgraph);
final outputParams = info.params;

expectEqualParams(outputParams, []);
expectEqualParams(info.params, []);
expect(info.throws, isFalse);
});

test('Function with return type', () {
// parseFunctionInfo doesn't parse the return type, but it should be able
// to cope with one.
final json = Json(jsonDecode(
'''
[
{ "kind": "keyword", "spelling": "func" },
{ "kind": "text", "spelling": " " },
{ "kind": "identifier", "spelling": "foo" },
{ "kind": "text", "spelling": "(" },
{ "kind": "externalParam", "spelling": "parameter" },
{ "kind": "text", "spelling": ": " },
{
"kind": "typeIdentifier",
"spelling": "Int",
"preciseIdentifier": "s:Si"
},
{ "kind": "text", "spelling": ") -> " },
{
"kind": "typeIdentifier",
"spelling": "Int",
"preciseIdentifier": "s:Si"
}
]
''',
));

final info = parseFunctionInfo(json, emptySymbolgraph);

final expectedParams = [
Parameter(
name: 'parameter',
type: intType,
),
];

expectEqualParams(info.params, expectedParams);
expect(info.throws, isFalse);
});

test('Function with no params with return type', () {
final json = Json(jsonDecode(
'''
[
{ "kind": "keyword", "spelling": "func" },
{ "kind": "text", "spelling": " " },
{ "kind": "identifier", "spelling": "foo" },
{ "kind": "text", "spelling": "() -> " },
{
"kind": "typeIdentifier",
"spelling": "Int",
"preciseIdentifier": "s:Si"
}
]
''',
));

final info = parseFunctionInfo(json, emptySymbolgraph);

expectEqualParams(info.params, []);
expect(info.throws, isFalse);
});

test('Function with no params and no return type', () {
final json = Json(jsonDecode(
'''
[
{ "kind": "keyword", "spelling": "func" },
{ "kind": "text", "spelling": " " },
{ "kind": "identifier", "spelling": "foo" },
{ "kind": "text", "spelling": "()" }
]
''',
));

final info = parseFunctionInfo(json, emptySymbolgraph);

expectEqualParams(info.params, []);
expect(info.throws, isFalse);
});

test('Function with return type that throws', () {
final json = Json(jsonDecode(
'''
[
{ "kind": "keyword", "spelling": "func" },
{ "kind": "text", "spelling": " " },
{ "kind": "identifier", "spelling": "foo" },
{ "kind": "text", "spelling": "(" },
{ "kind": "externalParam", "spelling": "parameter" },
{ "kind": "text", "spelling": ": " },
{
"kind": "typeIdentifier",
"spelling": "Int",
"preciseIdentifier": "s:Si"
},
{ "kind": "text", "spelling": ") " },
{ "kind": "keyword", "spelling": "throws" },
{ "kind": "text", "spelling": " -> " },
{
"kind": "typeIdentifier",
"spelling": "Int",
"preciseIdentifier": "s:Si"
}
]
''',
));

final info = parseFunctionInfo(json, emptySymbolgraph);

final expectedParams = [
Parameter(
name: 'parameter',
type: intType,
),
];

expectEqualParams(info.params, expectedParams);
expect(info.throws, isTrue);
});

test('Function with no return type that throws', () {
final json = Json(jsonDecode(
'''
[
{ "kind": "keyword", "spelling": "func" },
{ "kind": "text", "spelling": " " },
{ "kind": "identifier", "spelling": "foo" },
{ "kind": "text", "spelling": "(" },
{ "kind": "externalParam", "spelling": "parameter" },
{ "kind": "text", "spelling": ": " },
{
"kind": "typeIdentifier",
"spelling": "Int",
"preciseIdentifier": "s:Si"
},
{ "kind": "text", "spelling": ") " },
{ "kind": "keyword", "spelling": "throws" }
]
''',
));

final info = parseFunctionInfo(json, emptySymbolgraph);

final expectedParams = [
Parameter(
name: 'parameter',
type: intType,
),
];

expectEqualParams(info.params, expectedParams);
expect(info.throws, isTrue);
});

test('Function with no params that throws', () {
final json = Json(jsonDecode(
'''
[
{ "kind": "keyword", "spelling": "func" },
{ "kind": "text", "spelling": " " },
{ "kind": "identifier", "spelling": "foo" },
{ "kind": "text", "spelling": "() " },
{ "kind": "keyword", "spelling": "throws" }
]
''',
));

final info = parseFunctionInfo(json, emptySymbolgraph);

expectEqualParams(info.params, []);
expect(info.throws, isTrue);
});
});

group('Invalid json', () {
Expand Down
1 change: 0 additions & 1 deletion pkgs/swiftgen/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ environment:

dependencies:
ffi: ^2.1.0
meta: ^1.16.0

dev_dependencies:
dart_flutter_team_lints: ^2.0.0
Expand Down

0 comments on commit 27032c9

Please sign in to comment.