mirror of https://github.com/AMT-Cheif/drift.git
fix code generation for `enum` with generic
This commit is contained in:
parent
5aaeddd9d3
commit
9575612840
|
@ -357,9 +357,9 @@ AppliedTypeConverter readEnumConverter(
|
|||
}
|
||||
builder
|
||||
..addText('<')
|
||||
..addDartType(dartEnumType)
|
||||
..addTopLevelElement(dartEnumType.element!)
|
||||
..addText('>(')
|
||||
..addDartType(dartEnumType)
|
||||
..addTopLevelElement(dartEnumType.element!)
|
||||
..addText('.values)');
|
||||
});
|
||||
|
||||
|
|
|
@ -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>()();
|
||||
}
|
||||
|
||||
|
|
|
@ -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.getDisplayString(withNullability: true),
|
||||
'dartType', 'FruitsWithGeneric'),
|
||||
);
|
||||
|
||||
final nameColumn =
|
||||
table.columns.singleWhere((c) => c.nameInSql == 'fruitName');
|
||||
|
||||
|
|
Loading…
Reference in New Issue