-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
171 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:realm_common/realm_common.dart'; | ||
|
||
@RealmModel() | ||
@MapTo('Fooo') | ||
class _Foo { | ||
int x = 0; | ||
} | ||
|
||
@RealmModel() | ||
class _Bar { | ||
@PrimaryKey() | ||
late String id; | ||
late bool aBool, another; | ||
var data = Uint8List(16); | ||
// late RealmAny any; // not supported yet | ||
@MapTo('tidspunkt') | ||
var timestamp = DateTime.now(); | ||
var aDouble = 0.0; | ||
// late Decimal128 decimal; // not supported yet | ||
_Foo? foo; | ||
// late ObjectId id; | ||
// late Uuid uuid; // not supported yet | ||
@Ignored() | ||
var theMeaningOfEverything = 42; | ||
var list = [0]; // list of ints with default value | ||
// late Set<int> set; // not supported yet | ||
// late map = <String, int>{}; // not supported yet | ||
|
||
@Indexed() | ||
String? anOptionalString; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:realm_common/realm_common.dart'; | ||
|
||
//part 'not_a_realm_type.g.dart'; | ||
|
||
class NonRealm {} | ||
|
||
@RealmModel() | ||
class _Bad { | ||
late NonRealm notARealmType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Not a realm type | ||
|
||
in: asset:pkg/test/generator_test_io/not_a_realm_type.dart:9:8 | ||
╷ | ||
5 │ class NonRealm {} | ||
│ ━━━━━━━━ | ||
... │ | ||
7 │ @RealmModel() | ||
8 │ class _Bad { | ||
│ ━━━━ in realm model for 'Bad' | ||
9 │ late NonRealm notARealmType; | ||
│ ^^^^^^^^ NonRealm is not a realm model type | ||
╵ | ||
Add a @RealmModel annotation on 'NonRealm', or an @Ignored annotation on 'notARealmType'. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:realm_common/realm_common.dart'; | ||
import '../../../lib/realm.dart'; //For partial file references | ||
|
||
part 'pinhole.g.dart'; | ||
|
||
@RealmModel() | ||
class _Foo { | ||
int x = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ************************************************************************** | ||
// RealmObjectGenerator | ||
// ************************************************************************** | ||
part of 'pinhole.dart'; | ||
|
||
class Foo extends _Foo with RealmEntity, RealmObject { | ||
static var _defaultsSet = false; | ||
|
||
Foo({ | ||
int x = 0, | ||
}) { | ||
if (!_defaultsSet) { | ||
_defaultsSet = RealmObject.setDefaults<Foo>({ | ||
'x': 0, | ||
}); | ||
} | ||
RealmObject.set(this, 'x', x); | ||
} | ||
|
||
Foo._(); | ||
|
||
@override | ||
int get x => RealmObject.get<int>(this, 'x') as int; | ||
@override | ||
set x(int value) => RealmObject.set(this, 'x', value); | ||
|
||
@override | ||
Stream<RealmObjectChanges<Foo>> get changes => RealmObject.getChanges<Foo>(this); | ||
|
||
static SchemaObject get schema => _schema ??= _initSchema(); | ||
static SchemaObject? _schema; | ||
static SchemaObject _initSchema() { | ||
RealmObject.registerFactory(Foo._); | ||
return const SchemaObject(Foo, [ | ||
SchemaProperty('x', RealmPropertyType.int), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'dart:io'; | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'package:path/path.dart' as _path; | ||
import 'package:dart_style/dart_style.dart'; | ||
import 'package:build_test/build_test.dart'; | ||
import 'package:realm_generator/realm_generator.dart'; | ||
|
||
String _stringReplacements(String content) { | ||
final formatter = DartFormatter(); | ||
var lines = LineSplitter.split(content); | ||
String formattedContent = lines.where((element) => !element.startsWith("part of")).join('\n'); | ||
return formatter.format(formattedContent); | ||
} | ||
|
||
Future<String> readFileAsDartFormattedString(String path) async { | ||
var file = File(_path.join(Directory.current.path, path)); | ||
String content = await file.readAsString(encoding: utf8); | ||
return _stringReplacements(content); | ||
} | ||
|
||
Future<String> readFileAsErrorFormattedString(String directoryName, String logFileName) async { | ||
var file = File(_path.join(Directory.current.path, 'test/$directoryName/$logFileName')); | ||
String content = await file.readAsString(encoding: utf8); | ||
if (Platform.isWindows) { | ||
var macToWinSymbols = {'╷': ',', '━': '=', '╵': '\'', '│': '|'}; | ||
macToWinSymbols.forEach((key, value) { | ||
content = content.replaceAll(key, value); | ||
}); | ||
} | ||
return LineSplitter.split(content).join('\n'); | ||
} | ||
|
||
Future<Map<String, Object>> getInputFileAsset(String inputFilePath) async { | ||
var key = 'pkg|$inputFilePath'; | ||
String inputContent = await readFileAsDartFormattedString(inputFilePath); | ||
return {key: inputContent}; | ||
} | ||
|
||
Future<Map<String, Object>> getOutputFileAsset(String inputFilePath, String outputFilePath) async { | ||
var key = 'pkg|${_path.setExtension(inputFilePath, '.realm_objects.g.part')}'; | ||
String outputContent = await readFileAsDartFormattedString(outputFilePath); | ||
return {key: outputContent}; | ||
} | ||
|
||
Future<dynamic> ioTestBuilder(String directoryName, String inputFileName, [String outputFileName = ""]) async { | ||
return testBuilder(generateRealmObjects(), await getInputFileAsset('test/$directoryName/$inputFileName'), | ||
outputs: outputFileName.isEmpty ? null : await getOutputFileAsset('test/$directoryName/$inputFileName', 'test/$directoryName/$outputFileName'), | ||
reader: await PackageAssetReader.currentIsolate()); | ||
} | ||
|
||
Future<dynamic> ioTestErrorBuilder(String directoryName, String inputFileName) async { | ||
return testBuilder( | ||
generateRealmObjects(), | ||
await getInputFileAsset('test/$directoryName/$inputFileName'), | ||
reader: await PackageAssetReader.currentIsolate(), | ||
); | ||
} |