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 1 commit
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
Prev Previous commit
Next Next commit
Bugfix
  • Loading branch information
mosuem committed Jun 15, 2023
commit a410a99ba45f2c00c2297470a35d651806a246f9
22 changes: 13 additions & 9 deletions executors/dart_web/bin/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ import 'dart:io';

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

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

/// Prepare the file to export `testCollationShort`
void prepareOutFile(String name) {
void prepareOutFile(String name, List<String> functions) {
var outFile = File('dart_web/out/$name.js');
var s = outFile.readAsStringSync();
s = s.replaceAll('self.', '');
Expand All @@ -24,15 +25,18 @@ void prepareOutFile(String name) {
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(
'''})();

//# sourceMappingURL=$name.js.map''',
'})();\n\n//# sourceMappingURL=$name.js.map',
'''
return {
testCollationShort: function(date) {
return A.testCollationShort(date);
}
$exportFunctions
};
})();
//# sourceMappingURL=$name.js.map
Expand Down
162 changes: 80 additions & 82 deletions executors/dart_web/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ let doLogOutput = 0;

// Test type support. Add new items as they are implemented
const testTypes = {
TestCollShiftShort : Symbol("coll_shift_short"),
TestDecimalFormat : Symbol("decimal_fmt"),
TestNumberFormat : Symbol("number_fmt"),
TestDateTimeFormat : Symbol("datetime_fmtl"),
TestRelativeDateTimeFormat : Symbol("relative_datetime_fmt"),
TestPluralRules : Symbol("plural_rules"),
TestDisplayNames : Symbol("display_names"),
TestLangNames : Symbol("language_display_name"),
TestCollShiftShort: Symbol("coll_shift_short"),
TestDecimalFormat: Symbol("decimal_fmt"),
TestNumberFormat: Symbol("number_fmt"),
TestDateTimeFormat: Symbol("datetime_fmtl"),
TestRelativeDateTimeFormat: Symbol("relative_datetime_fmt"),
TestPluralRules: Symbol("plural_rules"),
TestDisplayNames: Symbol("display_names"),
TestLangNames: Symbol("language_display_name"),
}

const supported_test_types = [
Expand All @@ -54,14 +54,16 @@ const supported_test_types = [
Symbol("display_names"),
Symbol("language_display_name")
];
const supported_tests_json = {"supported_tests":
[
"coll_shift_short",
"decimal_fmt",
"number_fmt",
"display_names",
"language_display_name"
]};
const supported_tests_json = {
"supported_tests":
[
"coll_shift_short",
"decimal_fmt",
"number_fmt",
"display_names",
"language_display_name"
]
};

// Test line-by-line input, with output as string.
// Check on using Intl functions, e.g., DateTimeFormat()
Expand Down Expand Up @@ -103,7 +105,7 @@ function parseJsonForTestId(parsed) {
// Read JSON tests, each on a single line.
// Process the test and output a line of JSON results.
let lineId = 0;
rl.on('line', function(line) {
rl.on('line', function (line) {

// if logging input.
if (doLogInput > 0) {
Expand All @@ -117,77 +119,73 @@ rl.on('line', function(line) {
// Check for commands starting with "#".
if (line == "#VERSION") {
// JSON output of the test enviroment.
let versionJson = {'platform': 'NodeJS',
'platformVersion': process.version,
'icuVersion': process.versions.icu,
};
let versionJson = {
'platform': 'NodeJS',
'platformVersion': process.version,
'icuVersion': process.versions.icu,
};

// TODO: Make this more specific JSON info.
lineOut = JSON.stringify(versionJson);
process.stdout.write(lineOut);
} else
if (line == "#EXIT") {
process.exit();
} else
if (line == "#TESTS") {
lineOut = JSON.stringify(supported_tests_json);
process.stdout.write(lineOut);
}
else {
// Handle test cases.
let testId;
let parsedJson;
try {
parsedJson = JSON.parse(line);
} catch (error) {
outputLine = {'Cannot parse input line': error,
'input_line': line,
"testId": testId};

// Send result to stdout for verification
jsonOut = JSON.stringify(outputLine);
if (doLogOutput > 0) {
console.log("## ERROR " + lineId + ' ' + outputLine + ' !!!!!');
}
process.stdout.write(jsonOut);
}

if (doLogInput > 0) {
console.log("#----- PARSED JSON: " + JSON.stringify(parsedJson));
}

// testId = parseJsonForTestId(parsedJson);
// Handle the string directly to call the correct function.
const test_type = parsedJson["test_type"];
if (test_type == "coll_shift_short") {
outputLine = collator.testCollationShort(parsedJson);
} else
if (test_type == "decimal_fmt" || test_type == "number_fmt") {
outputLine = numberformatter.testDecimalFormat(parsedJson);
if (line == "#EXIT") {
process.exit();
} else
if (test_type == "display_names") {
outputLine = displaynames.testDisplayNames(parsedJson);
} else
if (test_type == "language_display_name") {
outputLine = langnames.testLangNames(parsedJson);
} else {
outputLine = {'error': 'unknown test type', 'testId': testId,
'unsupported_test': testId};
}

if ('error' in outputLine) {
// To get the attention of the driver
console.log("#!! ERROR in NODE call: " + JSON.stringify(outputLine));
}

// Send result to stdout for verification
jsonOut = JSON.stringify(outputLine);
process.stdout.write(jsonOut + '\n');
if (doLogOutput > 0) {
console.log("##### NODE RETURNS " + lineId + ' ' + jsonOut + ' !!!!!');
}
if (line == "#TESTS") {
lineOut = JSON.stringify(supported_tests_json);
process.stdout.write(lineOut);
}
else {
// Handle test cases.
let testId;
let parsedJson;
try {
parsedJson = JSON.parse(line);
} catch (error) {
outputLine = {
'Cannot parse input line': error,
'input_line': line,
"testId": testId
};

// Send result to stdout for verification
jsonOut = JSON.stringify(outputLine);
if (doLogOutput > 0) {
console.log("## ERROR " + lineId + ' ' + outputLine + ' !!!!!');
}
process.stdout.write(jsonOut);
}

if (doLogInput > 0) {
console.log("#----- PARSED JSON: " + JSON.stringify(parsedJson));
}

// testId = parseJsonForTestId(parsedJson);
// Handle the string directly to call the correct function.
const test_type = parsedJson["test_type"];
if (test_type == "coll_shift_short") {
outputLine = collator.testCollationShort(parsedJson);
} else {
outputLine = {
'error': 'unknown test type', 'testId': testId,
'unsupported_test': testId
};
}

if ('error' in outputLine) {
// To get the attention of the driver
console.log("#!! ERROR in NODE call: " + JSON.stringify(outputLine));
}

// Send result to stdout for verification
jsonOut = JSON.stringify(outputLine);
process.stdout.write(jsonOut + '\n');
if (doLogOutput > 0) {
console.log("##### NODE RETURNS " + lineId + ' ' + jsonOut + ' !!!!!');
}

}
}
lineId += 1;
}
)
)
3 changes: 1 addition & 2 deletions executors/dart_web/out/collator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var tools = require('./collatorDart');
// to the strength.
module.exports = {
testCollationShort: function (json) {
let res = tools.testCollationShort(JSON.stringify(json));
return JSON.parse(res);
return JSON.parse(tools.testCollationShort(JSON.stringify(json)));
}
};