Merge pull request #2581 from nikitadol/develop

fix code generation for `enum` with generics
This commit is contained in:
Simon Binder 2023-08-27 07:12:21 +02:00 committed by GitHub
commit 18b11d7bb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -357,9 +357,9 @@ AppliedTypeConverter readEnumConverter(
}
builder
..addText('<')
..addDartType(dartEnumType)
..addTopLevelElement(dartEnumType.element!)
..addText('>(')
..addDartType(dartEnumType)
..addTopLevelElement(dartEnumType.element!)
..addText('.values)');
});

View File

@ -17,10 +17,15 @@ void main() {
apple, orange, banana
}
enum FruitsWithGeneric<T> {
apple, orange, banana
}
class NotAnEnum {}
class ValidUsage extends Table {
IntColumn get intFruit => intEnum<Fruits>()();
IntColumn get intFruitsWithGeneric => intEnum<FruitsWithGeneric>()();
TextColumn get textFruit => textEnum<Fruits>()();
}

View File

@ -89,6 +89,7 @@ CREATE TABLE b (
CREATE TABLE foo (
fruitIndex ENUM(Fruits) NOT NULL,
fruitWithGenericIndex ENUM(FruitsWithGeneric) NOT NULL,
fruitName ENUMNAME(Fruits) NOT NULL,
anotherIndex ENUM(DoesNotExist) NOT NULL,
anotherName ENUMNAME(DoesNotExist) NOT NULL
@ -98,6 +99,10 @@ CREATE TABLE b (
enum Fruits {
apple, orange, banana
}
enum FruitsWithGeneric<T> {
apple, orange, banana
}
''',
});
@ -118,6 +123,22 @@ CREATE TABLE b (
.having((e) => e.dartType.getDisplayString(withNullability: true),
'dartType', 'Fruits'),
);
final withGenericIndexColumn = table.columns
.singleWhere((c) => c.nameInSql == 'fruitWithGenericIndex');
expect(withGenericIndexColumn.sqlType, DriftSqlType.int);
expect(
withGenericIndexColumn.typeConverter,
isA<AppliedTypeConverter>()
.having(
(e) => e.expression.toString(),
'expression',
contains('EnumIndexConverter<FruitsWithGeneric>'),
)
.having(
(e) => e.dartType.element!.name, 'dartType', 'FruitsWithGeneric'),
);
final nameColumn =
table.columns.singleWhere((c) => c.nameInSql == 'fruitName');