Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dart to executors #65

Merged
merged 21 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
name: End-to-end (Gen data, run tests, gen GH Pages)
runs-on: ubuntu-latest
steps:
- uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f
with:
sdk: stable

- uses: actions/checkout@v2
- run: bash generateDataAndRun.sh
- name: Setup Pages
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ testgen/icu*/*.json

# C / CPP compiled
*.o

testdriver/.local-chrome/
testgen/*.json

TEMP_DATA/*
5 changes: 5 additions & 0 deletions executors/dart_native/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin/executor.exe

.dart_tool
build/
pubspec.lock
18 changes: 18 additions & 0 deletions executors/dart_native/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
include: package:lints/recommended.yaml

analyzer:
language:
strict-raw-types: true
errors:
deprecated_member_use_from_same_package: ignore

linter:
rules:
- always_declare_return_types
- directives_ordering
- prefer_single_quotes
- sort_pub_dependencies
- unnecessary_parenthesis
- avoid_dynamic_calls
- type_annotate_public_apis
- non_constant_identifier_names
89 changes: 89 additions & 0 deletions executors/dart_native/bin/executor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'dart:convert';
import 'dart:io';
import 'package:intl4x/intl4x.dart';

Map<String, List<String>> supportedTests = {
'supported_tests': [
'coll_shift_short',
'decimal_fmt',
'number_fmt',
'display_names',
'language_display_name',
],
};

enum TestTypes {
coll_shift_short,
decimal_fmt,
datetime_fmt,
display_names,
lang_names,
number_fmt;
}

void main() {
stdin.listen((event) {
var lines = utf8.decode(event);
for (var line in lines.split('\n')) {
if (line == '#EXIT') {
exit(0);
} else if (line == '#VERSION') {
printVersion();
} else if (line == '#TESTS') {
print(json.encode(supportedTests));
} else {
Map<String, dynamic> decoded;
try {
decoded = json.decode(line);
} catch (e) {
print('ERROR $line');
rethrow;
}

var testType = TestTypes.values
.firstWhere((element) => element.name == decoded['test_type']);
Object result;
switch (testType) {
case TestTypes.coll_shift_short:
result = testCollator(decoded);
break;
case TestTypes.decimal_fmt:
// TODO: Handle this case.
case TestTypes.datetime_fmt:
// TODO: Handle this case.
case TestTypes.display_names:
// TODO: Handle this case.
case TestTypes.lang_names:
// TODO: Handle this case.
case TestTypes.number_fmt:
// TODO: Handle this case.
default:
throw UnsupportedError('');
}

var outputLine = {'label': decoded['label'], 'result': result};
print(json.encode(outputLine));
}
}
});
}

bool testCollator(Map<String, dynamic> decoded) {
var compared = Intl().collation.compare(
decoded['string1'],
decoded['string2'],
);
var result = compared <= 0 ? true : false;
return result;
}

void printVersion() {
var version = Platform.version;
var parsedVersion = version.substring(0, version.indexOf(' '));
var versionInfo = {
'icuVersion': '71.1',
'platform': 'Dart',
'platformVersion': parsedVersion,
};
print(json.encode(versionInfo));
}
21 changes: 21 additions & 0 deletions executors/dart_native/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: dart
description: A sample command-line application.
version: 1.0.0
publish_to: none

environment:
sdk: ^3.0.0

# Add regular dependencies here.
dependencies:
intl4x:
git:
url: https://github.com/dart-lang/i18n.git
path: pkgs/intl4x/
ref: addIntl4x

dev_dependencies:
build_runner: ^2.4.4
build_web_compilers: ^4.0.3
lints: ^2.0.0
test: ^1.21.0
7 changes: 7 additions & 0 deletions executors/dart_web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
out/collatorDart.js
out/collatorDart.js.deps
out/collatorDart.js.map
pubspec.lock
5 changes: 5 additions & 0 deletions executors/dart_web/bin/all_executors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'collator.dart';

void main(List<String> args) {
testCollationShort(args.first); //just some call to not treeshake the function
}
45 changes: 45 additions & 0 deletions executors/dart_web/bin/collator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// The Collator used for the actual testing.

// !!! TODO: Collation: determine the sensitivity that corresponds
// to the strength.
import 'dart:convert';

import 'package:intl4x/collation.dart';
import 'package:intl4x/intl4x.dart';

String testCollationShort(String jsonEncoded) {
var json =
jsonDecode(jsonEncoded); // For the moment, use strings for easier interop
// Global default locale
var testLocale = '';
Map<String, dynamic> outputLine;

// Set up collator object with optional locale and testOptions.
try {
Intl coll;
if (testLocale.isNotEmpty) {
coll = Intl(defaultLocale: testLocale);
} else {
coll = Intl();
}
var d1 = json['string1'];
var d2 = json['string2'];

var collationOptions = CollationOptions(ignorePunctuation: true);
var compared = coll.collation(collationOptions).compare(d1, d2);
var result = compared <= 0 ? true : false;
outputLine = {'label': json['label'], "result": result};

if (result != true) {
// Additional info for the comparison
outputLine['compare'] = compared;
}
} catch (error) {
outputLine = {
'label': json['label'],
'error_message': error.toString(),
'error': 'Collator compare failed'
};
}
return jsonEncode(outputLine);
}
47 changes: 47 additions & 0 deletions executors/dart_web/bin/make_runnable_by_node.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dart:io';

Future<void> main(List<String> args) async {
var name = 'collatorDart';
var compile = await Process.run('dart', [
'compile',
'js',
'bin/all_executors.dart',
'-o',
'out/$name.js',
]);
print(compile.stderr);

prepareOutFile(name, ['testCollationShort']);
}

/// Prepare the file to export `testCollationShort`
void prepareOutFile(String name, List<String> functions) {
var outFile = File('out/$name.js');
var s = outFile.readAsStringSync();
s = s.replaceAll('self.', '');
s = s.replaceFirst('(function dartProgram() {',
'module.exports = (function dartProgram() {');

s = s.replaceFirst('(function dartProgram() {',
'module.exports = (function dartProgram() {');

var exportFunctions = functions
.map(
(e) => '''$e: function(arg) {
return A.$e(arg);
}''',
)
.join(',\n');
s = s.replaceFirst(
'})();\n\n//# sourceMappingURL=$name.js.map',
'''
return {
$exportFunctions
};
})();
//# sourceMappingURL=$name.js.map
''',
);
s = 'function dartMainRunner(main, args){}' + s;
outFile.writeAsStringSync(s);
}
10 changes: 10 additions & 0 deletions executors/dart_web/out/collator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var tools = require('./collatorDart');
// The Collator used for the actual testing.

// !!! TODO: Collation: determine the sensitivity that corresponds
// to the strength.
module.exports = {
testCollationShort: function (json) {
return JSON.parse(tools.testCollationShort(JSON.stringify(json)));
}
};
Loading