-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.dart
More file actions
73 lines (66 loc) · 1.94 KB
/
Copy pathexample_test.dart
File metadata and controls
73 lines (66 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import 'dart:io';
import 'package:test/test.dart';
import 'package:meta/meta.dart';
import 'package:raylib_c_translator/raylib_c_translator.dart';
void main() {
Directory('example/generated').createSync(recursive: true);
translate('001_core_basic_window', {Include.raylib, MatchCode.main});
translate('002_core_delta_time', {
Include.raylib,
MatchCode.main,
MatchCode.floatSuffix,
MatchCode('const char *fpsText = 0;', 'late final String fpsText;'),
CastCode.numericLoose,
StructInitializer.vector2,
});
translate('003_core_input_keys', {
Include.raylib,
MatchCode.main,
MatchCode.floatSuffix,
CastCode.numericLoose,
StructInitializer.vector2,
});
translate('004_core_input_mouse', {
Include.raylib,
MatchCode.main,
MatchCode.floatSuffix,
CastCode.numericLoose,
StructInitializer.vector2,
});
translate('005_core_input_mouse_wheel', {
Include.raylib,
MatchCode.main,
MatchCode.floatSuffix,
CastCode.numericLoose,
MatchCode('screenHeight/2', 'screenHeight~/2'),
MatchCode('screenWidth/2', 'screenWidth~/2'),
});
}
@isTest
void translate(String target, Set<TranslateRule> rules) {
test(target, () {
final filePath = 'example/c/$target.c';
final content = File(filePath).readAsStringSync();
final translator = RaylibTranslator(rules);
final translated = translator(content);
final outputPath = 'example/generated/$target.g.dart';
final outputFile = File(outputPath);
outputFile.createSync(recursive: true);
outputFile.writeAsStringSync(translated);
expect(
analyze(outputPath),
isTrue,
reason: 'Translated code should pass analysis',
);
});
}
bool analyze(String filePath) {
ProcessResult result = Process.runSync('dart', ['analyze', filePath]);
if (result.exitCode != 0) {
print('Analysis failed for $filePath:');
print(result.stdout);
print(result.stderr);
return false;
}
return true;
}