Verify update rule generation in generator, fix tests

This commit is contained in:
Simon Binder 2020-03-04 16:52:08 +01:00
parent 545fbcc86a
commit 799eba1c67
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 52 additions and 2 deletions

View File

@ -77,6 +77,10 @@ END;
.having((table) => table.displayName, 'displayName', 'users'),
},
);
expect(trigger.bodyReferences.map((t) => t.sqlName),
{'users', 'friendships'});
expect(trigger.bodyUpdates.map((t) => t.sqlName), {'friendships'});
});
test('in an index', () async {

View File

@ -0,0 +1,46 @@
import 'package:moor/moor.dart';
import 'package:moor_generator/src/analyzer/runner/results.dart';
import 'package:moor_generator/src/services/find_stream_update_rules.dart';
@Tags(['analyzer'])
import 'package:test/test.dart';
import '../analyzer/utils.dart';
void main() {
test('finds update rules for triggers', () async {
final state = TestState.withContent({
'foo|lib/a.moor': '''
CREATE TABLE users (
id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR NOT NULL
);
CREATE TRIGGER add_angry_user
AFTER INSERT ON users
WHEN new.name != UPPER(new.name)
BEGIN
INSERT INTO users (name) VALUES (UPPER(new.name));
END;
''',
'foo|lib/main.dart': '''
import 'package:moor/moor.dart';
@UseMoor(include: {'a.moor'})
class MyDatabase {}
'''
});
final file = await state.analyze('package:foo/main.dart');
final db = (file.currentResult as ParsedDartFile).declaredDatabases.single;
final rules = FindStreamUpdateRules(db).identifyRules();
expect(rules.rules, hasLength(1));
expect(
rules.rules.single,
isA<WritePropagation>()
.having((e) => e.onTable, 'onTable', 'users')
.having((e) => e.updates, 'updates', {'users'}),
);
});
}

View File

@ -209,7 +209,7 @@ const expected = r'''
"moor_type":"ColumnType.boolean",
"nullable":false,
"customConstraints":"NOT NULL DEFAULT FALSE",
"default_dart":"const CustomExpression<bool, BoolType>('FALSE')",
"default_dart":"const CustomExpression<bool>('FALSE')",
"default_client_dart":null,
"dsl_features":[

View File

@ -17,7 +17,7 @@ class TestBackend extends Backend {
/// input files have been parsed and analyzed by the Dart analyzer.
Future get _ready => _initCompleter.future;
TestBackend(this.fakeContent, {bool enableDartAnalyzer = false}) {
TestBackend(this.fakeContent, {bool enableDartAnalyzer = true}) {
if (enableDartAnalyzer) {
_init();
} else {