mirror of https://github.com/AMT-Cheif/drift.git
test: Update the tests
This commit is contained in:
parent
b2054b947b
commit
059108fff6
|
@ -18,6 +18,18 @@ class Users extends Table {
|
|||
TextColumn get foo => text().map(withoutJson())();
|
||||
TextColumn get bar => text().map(withJson())();
|
||||
}
|
||||
''',
|
||||
'a|lib/json_nullability.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
JsonTypeConverter<Dart, Sql> tc<Dart, Sql>() => throw 'stub';
|
||||
|
||||
class Users extends Table {
|
||||
TextColumn get wrongSqlType => text().map(tc<int, int>())();
|
||||
TextColumn get illegalNull => text().map(tc<String, String?>())();
|
||||
TextColumn get illegalNonNull => text().map(tc<String?, String>()).nullable()();
|
||||
TextColumn get implicitlyNullAware => text().map(tc<String, String>()).nullable()();
|
||||
}
|
||||
''',
|
||||
'a|lib/nullability.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -71,6 +83,30 @@ CREATE TABLE users (
|
|||
return testWith('package:a/json.dart');
|
||||
});
|
||||
|
||||
test('warns about type issues around json converters', () async {
|
||||
final result = await state.driver
|
||||
.fullyAnalyze(Uri.parse('package:a/json_nullability.dart'));
|
||||
final table = result.analyzedElements.whereType<DriftTable>().single;
|
||||
|
||||
expect(
|
||||
result.allErrors,
|
||||
[
|
||||
isDriftError(contains('must accept String')).withSpan('tc<int, int>()'),
|
||||
isDriftError(contains('has a type converter with a nullable SQL type'))
|
||||
.withSpan('tc<String, String?>()'),
|
||||
isDriftError(allOf([
|
||||
contains('This column is nullable'),
|
||||
contains(
|
||||
'Try wrapping the converter in `JsonTypeConverter2.asNullable`',
|
||||
)
|
||||
])).withSpan('tc<String?, String>()'),
|
||||
],
|
||||
);
|
||||
|
||||
final implicitlyNullAware = table.columns[3];
|
||||
expect(implicitlyNullAware.typeConverter?.canBeSkippedForNulls, isTrue);
|
||||
});
|
||||
|
||||
test('warns about type issues around converters', () async {
|
||||
final result = await state.driver
|
||||
.fullyAnalyze(Uri.parse('package:a/nullability.dart'));
|
||||
|
@ -82,8 +118,12 @@ CREATE TABLE users (
|
|||
isDriftError(contains('must accept String')).withSpan('tc<int, int>()'),
|
||||
isDriftError(contains('has a type converter with a nullable SQL type'))
|
||||
.withSpan('tc<String, String?>()'),
|
||||
isDriftError(contains('This column is nullable'))
|
||||
.withSpan('tc<String?, String>()'),
|
||||
isDriftError(allOf([
|
||||
contains('This column is nullable'),
|
||||
contains(
|
||||
'Try wrapping the converter in `NullAwareTypeConverter.wrap`',
|
||||
)
|
||||
])).withSpan('tc<String?, String>()'),
|
||||
],
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue