Skip to content

Commit

Permalink
add some test case
Browse files Browse the repository at this point in the history
  • Loading branch information
lancexin committed Jan 21, 2025
1 parent e876dd0 commit 245de81
Show file tree
Hide file tree
Showing 101 changed files with 8,932 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class $InheritedWidget extends InheritedWidget with m.InstanceBridge {
: super(key: key, child: child);

@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/widgets/framework.dart", "InheritedWidget"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "InheritedWidget"),
);

@override
bool updateShouldNotify(covariant InheritedWidget oldWidget) {
Expand Down Expand Up @@ -45,10 +44,9 @@ class $StatelessWidget extends StatelessWidget
implements PreferredSizeWidget {
$StatelessWidget({Key? key}) : super(key: key);
@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/widgets/framework.dart", "StatelessWidget"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "StatelessWidget"),
);

@override
Widget build(BuildContext context) {
Expand All @@ -73,10 +71,9 @@ Function _StatefulWidget__$(m.Scope scope$) => ({Key? key}) {
class $StatefulWidget extends StatefulWidget with m.InstanceBridge {
$StatefulWidget({Key? key}) : super(key: key);
@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/widgets/framework.dart", "StatefulWidget"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "StatefulWidget"),
);

@override
State<StatefulWidget> createState() {
Expand All @@ -95,9 +92,9 @@ Function _State__$(m.Scope scope$) => () {
class $State extends State
with m.InstanceBridge, TickerProviderStateMixin, RestorationMixin {
@override
m.CType bridgeType = const m.CType(
m.ClassRef("package:flutter/src/widgets/framework.dart", "State"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "State"),
);

@override
Widget build(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class $InheritedWidget extends InheritedWidget with m.InstanceBridge {
: super(key: key, child: child);

@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/widgets/framework.dart", "InheritedWidget"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "InheritedWidget"),
);

@override
bool updateShouldNotify(covariant InheritedWidget oldWidget) {
Expand Down Expand Up @@ -45,10 +44,9 @@ class $StatelessWidget extends StatelessWidget
implements PreferredSizeWidget {
$StatelessWidget({Key? key}) : super(key: key);
@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/widgets/framework.dart", "StatelessWidget"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "StatelessWidget"),
);

@override
Widget build(BuildContext context) {
Expand All @@ -73,10 +71,9 @@ Function _StatefulWidget__$(m.Scope scope$) => ({Key? key}) {
class $StatefulWidget extends StatefulWidget with m.InstanceBridge {
$StatefulWidget({Key? key}) : super(key: key);
@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/widgets/framework.dart", "StatefulWidget"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "StatefulWidget"),
);

@override
State<StatefulWidget> createState() {
Expand All @@ -95,9 +92,9 @@ Function _State__$(m.Scope scope$) => () {
class $State extends State
with m.InstanceBridge, TickerProviderStateMixin, RestorationMixin {
@override
m.CType bridgeType = const m.CType(
m.ClassRef("package:flutter/src/widgets/framework.dart", "State"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "State"),
);

@override
Widget build(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Function _Model__$(m.Scope scope$) => () {

class $Model extends Model with m.InstanceBridge {
@override
m.CType bridgeType = const m.CType(
m.ClassRef("package:scoped_model/scoped_model.dart", "Model"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:scoped_model/scoped_model.dart", "Model"),
);

@override
late Map<String, Function> superGetters = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Function _Listenable__$(m.Scope scope$) => (bool _value) {

class $Listenable extends Listenable with m.InstanceBridge {
@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/foundation/change_notifier.dart", "Listenable"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef(
"package:flutter/src/foundation/change_notifier.dart", "Listenable"),
);

@override
late Map<String, Function> superGetters = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class $CustomPainter extends CustomPainter with m.InstanceBridge {
$CustomPainter({Listenable? repaint}) : super(repaint: repaint);

@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/rendering/custom_paint.dart", "CustomPainter"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef(
"package:flutter/src/rendering/custom_paint.dart", "CustomPainter"),
);

@override
late Map<String, Function> superGetters = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ class $InheritedWidget extends InheritedWidget with m.InstanceBridge {
: super(key: key, child: child);

@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/widgets/framework.dart", "InheritedWidget"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "InheritedWidget"),
);

@override
bool updateShouldNotify(covariant InheritedWidget oldWidget) {
Expand Down Expand Up @@ -52,10 +51,9 @@ class $StatelessWidget extends StatelessWidget
implements PreferredSizeWidget {
$StatelessWidget({Key? key}) : super(key: key);
@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/widgets/framework.dart", "StatelessWidget"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "StatelessWidget"),
);

@override
Widget build(BuildContext context) {
Expand All @@ -80,10 +78,9 @@ Function _StatefulWidget__$(m.Scope scope$) => ({Key? key}) {
class $StatefulWidget extends StatefulWidget with m.InstanceBridge {
$StatefulWidget({Key? key}) : super(key: key);
@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/widgets/framework.dart", "StatefulWidget"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "StatefulWidget"),
);

@override
State<StatefulWidget> createState() {
Expand All @@ -102,9 +99,9 @@ Function _State__$(m.Scope scope$) => () {
class $State extends State
with m.InstanceBridge, TickerProviderStateMixin, RestorationMixin {
@override
m.CType bridgeType = const m.CType(
m.ClassRef("package:flutter/src/widgets/framework.dart", "State"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/framework.dart", "State"),
);

@override
Widget build(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ Function _RestorableListenable__$(m.Scope scope$) => () {

class $RestorableListenable extends RestorableListenable with m.InstanceBridge {
@override
m.CType bridgeType = const m.CType(
m.ClassRef("package:flutter/src/widgets/restoration_properties.dart",
"RestorableListenable"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:flutter/src/widgets/restoration_properties.dart",
"RestorableListenable"),
);

@override
late Map<String, Function> superGetters = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class $AnimatedWidget extends AnimatedWidget with m.InstanceBridge {
: super(key: key, listenable: listenable);

@override
m.CType bridgeType = const m.CType(
m.ClassRef(
"package:flutter/src/widgets/transitions.dart", "AnimatedWidget"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef(
"package:flutter/src/widgets/transitions.dart", "AnimatedWidget"),
);

@override
late Map<String, Function> superGetters = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Function _Model__$(m.Scope scope$) => () {

class $Model extends Model with m.InstanceBridge {
@override
m.CType bridgeType = const m.CType(
m.ClassRef("package:scoped_model/scoped_model.dart", "Model"),
isExternal: true);
m.CType bridgeType = const m.CType.external(
m.ClassRef("package:scoped_model/scoped_model.dart", "Model"),
);

@override
late Map<String, Function> superGetters = {};
Expand Down
8 changes: 8 additions & 0 deletions micro_dart_compiler/lib/compiler/ast/expression.dart
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ int compileIsExpression(MicroCompilerContext context, IsExpression node) {
context.externalCallMethods.add(isRef);
return context.pushOp(OpCallExternal.make(isRef, true, [], []));
}
} else if (type is FunctionType) {
throw Exception(
"IsExpression type not support : ${type.runtimeType.toString()}");
} else {
throw Exception(
"IsExpression type not support : ${type.runtimeType.toString()}");
Expand Down Expand Up @@ -476,6 +479,11 @@ int compileAsExpression(MicroCompilerContext context, AsExpression node) {
"FunctionType not support : ${node.parent?.runtimeType.toString()} ${type.toStringInternal()}");
//throw Exception(
// "FunctionType not support : ${node.parent?.runtimeType.toString()} ${type.toStringInternal()}");
} else if (type is FutureOrType) {
// print(
// "FutureOrType not support : ${node.parent?.runtimeType.toString()} ${type.toStringInternal()}");
throw Exception(
"AsExpression not support : ${type.runtimeType.toString()}");
} else {
throw Exception(
"AsExpression not support : ${type.runtimeType.toString()}");
Expand Down
92 changes: 89 additions & 3 deletions micro_dart_compiler/test/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,90 @@ const bool printOp = true;

typedef ResultCallback = void Function(dynamic returnValue);

Future<MicroDartEngine> singleFileTestEngine(
String fileName, {
String functionName = "main",
String testCasePath = testCasePath1,
bool astOut = true,
bool jsonAstOut = true,
bool opOut = true,
bool constantOut = true,
bool externalMethodsOut = false,
bool typesOut = true,
bool declarationsOut = true,
bool debug = true,
bool isAsync = false,
bool waitClean = false,
Map<String, LibraryMirror> testLibraryMirrors = libraryMirrors,
}) async {
var file = File("$testCasePath$fileName");
var sources = <String, String>{'main.dart': file.readAsStringSync()};
var program = await compileSource(pluginUriRegExp, options, sources);

if (astOut) {
writeComponentToText(program.component!,
path: "${testCasePath}_$fileName.ast.txt");
}
if (jsonAstOut) {
astToJson(
"${testCasePath}_$fileName.json", pluginUriRegExp, program.component);
}

if (externalMethodsOut) {
File("${testCasePath}_$fileName.externalMethods.txt")
.writeAsStringSync(program.getExternalCallMethods());
}

var engine = MicroDartEngine.fromData(program.write().buffer.asByteData());
engine.setExternalFunctions(testLibraryMirrors);

if (opOut) {
File("${testCasePath}_$fileName.op.txt")
.writeAsStringSync(engine.getOpcodes());
}

if (constantOut) {
File("${testCasePath}_$fileName.constant.txt")
.writeAsStringSync(engine.getConstants());
}

if (typesOut) {
File("${testCasePath}_$fileName.types.txt")
.writeAsStringSync(engine.getTypes());
}

if (declarationsOut) {
File("${testCasePath}_$fileName.declarations.txt")
.writeAsStringSync(engine.getDeclarations());
}

if (debug) {
engine.debug = true;
}

return engine;
}

Future<dynamic> run(
MicroDartEngine engine, {
String functionName = "main",
bool isAsync = false,
bool waitClean = false,
ResultCallback? resultCallback,
}) async {
var returnValue = isAsync
? await await engine
.callStaticFunctionAsync(pluginUri, functionName, [], {})
: waitClean
? await engine
.callStaticFunctionWaitClean(pluginUri, functionName, [], {})
: engine.callStaticFunction(pluginUri, functionName, [], {});

resultCallback?.call(returnValue);

return returnValue;
}

Future<dynamic> singleFileTest(
String fileName, {
String functionName = "main",
Expand Down Expand Up @@ -92,10 +176,12 @@ Future<dynamic> singleFileTest(
}

var returnValue = isAsync
? await await engine.callStaticFunctionAsync(pluginUri, "main", [], {})
? await await engine
.callStaticFunctionAsync(pluginUri, functionName, [], {})
: waitClean
? await engine.callStaticFunctionWaitClean(pluginUri, "main", [], {})
: engine.callStaticFunction(pluginUri, "main", [], {});
? await engine
.callStaticFunctionWaitClean(pluginUri, functionName, [], {})
: engine.callStaticFunction(pluginUri, functionName, [], {});

resultCallback?.call(returnValue);

Expand Down
Loading

0 comments on commit 245de81

Please sign in to comment.