Skip to content

Commit

Permalink
Backlink tests (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Oct 27, 2022
1 parent 50889d4 commit 8483279
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/backlinks_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2022 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
import 'package:realm_common/realm_common.dart';
import 'package:test/expect.dart';

import '../lib/realm.dart';
import 'test.dart';

part 'backlinks_test.g.dart';

@RealmModel()
class _Source {
String name = 'source';
_Target? target;
}

@RealmModel()
class _Target {
@Backlink(#target)
late Iterable<_Source> backlinks; // computed property, so must go last in generated class!

String name = 'target';
}

Future<void> main([List<String>? args]) async {
await setupTests(args);

test('x', () {
final config = Configuration.local([Target.schema, Source.schema]);
final realm = getRealm(config);

final target = Target();
final source = realm.write(() => realm.add(Source(target: target)));

expect(source.target, target);
expect(target.backlinks, [source]);
});
}
104 changes: 104 additions & 0 deletions test/backlinks_test.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8483279

Please sign in to comment.