Fix Dart and PHP lists_sort.

Add generator tests.
This commit is contained in:
Daniel LaLiberte
2016-05-05 17:58:08 -04:00
parent c1cfec8dbd
commit 8904fd1b9c
12 changed files with 4163 additions and 4073 deletions

View File

@@ -321,14 +321,13 @@ Blockly.Dart['lists_sort'] = function(block) {
['List ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ +
'(list, type, direction) {',
' var compareFuncs = {',
' "NUMERIC": (a, b) => direction * ',
' double.parse(a.toString()).compareTo(double.parse(b.toString())),',
' "NUMERIC": (a, b) => direction * a.compareTo(b),',
' "TEXT": (a, b) => direction * a.toString().compareTo(b.toString()),',
' "IGNORE_CASE": ',
' (a, b) => direction * ',
' a.toString().toLowerCase().compareTo(b.toString().toLowerCase())',
' };',
' list = (new List.from(list))', // Clone the list.
' list = new List.from(list);', // Clone the list.
' var compare = compareFuncs[type];',
' list.sort(compare);',
' return list;',

View File

@@ -366,14 +366,14 @@ Blockly.PHP['lists_sort'] = function(block) {
'lists_sort', [
'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
'($list, $type, $direction) {',
' $sortFuncs = array(',
' "NUMERIC" => "sort",',
' "TEXT" => "natsort",',
' "IGNORE_CASE" => "natcasesort"',
' $sortCmpFuncs = array(',
' "NUMERIC" => "strnatcasecmp",',
' "TEXT" => "strcmp",',
' "IGNORE_CASE" => "strcasecmp"',
' );',
' $sort = $sortFuncs[$type];',
' $sortCmp = $sortCmpFuncs[$type];',
' $list2 = $list;', // Clone list.
' $sort($list2);',
' usort($list2, $sortCmp);',
' if ($direction == -1) {',
' $list2 = array_reverse($list2);',
' }',