GeezerVison is showing github.com — test,util: add missing tests and conditions · nodejs/node@dc84858
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: benchmark/util/normalize-encoding.js +17-8Lines changed: 17 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,18 +4,25 @@ const common = require('../common.js'); | 4 | 4 | const assert = require('assert'); | 5 | 5 |
| 6 | 6 | const groupedInputs = { | 7 | | - group_common: ['undefined', 'utf8', 'utf-8', 'base64', 'binary', 'latin1'], | 8 | | - group_upper: ['UTF-8', 'UTF8', 'UCS2', 'UTF-16LE', 'UTF16LE', 'BASE64'], | 9 | | - group_uncommon: [ 'foo', '1', 'false', 'undefined', '[]'], | | 7 | + group_common: ['undefined', 'utf8', 'utf-8', 'base64', | | 8 | + 'binary', 'latin1', 'ucs-2', 'usc-2'], | | 9 | + group_upper: ['UTF-8', 'UTF8', 'UCS2', 'UTF-16LE', | | 10 | + 'UTF16LE', 'BASE64', 'UCS-2', 'USC-2'], | | 11 | + group_uncommon: ['foo', '1', 'false', 'undefined', '[]', '{}'], | 10 | 12 | group_misc: ['', 'utf16le', 'usc2', 'hex', 'HEX', 'BINARY'] | 11 | 13 | }; | 12 | 14 |
| 13 | 15 | const inputs = [ | 14 | | - '', 'utf8', 'utf-8', 'UTF-8', | 15 | | - 'UTF8', 'Utf8', 'uTf-8', 'utF-8', 'ucs2', | 16 | | - 'UCS2', 'utf16le', 'utf-16le', 'UTF-16LE', 'UTF16LE', | | 16 | + '', | | 17 | + 'utf8', 'utf-8', 'UTF-8', | | 18 | + 'UTF8', 'Utf8', 'uTf-8', 'utF-8', | | 19 | + 'ucs2', 'UCS2', 'UcS2', | | 20 | + 'USC2', 'usc2', 'uSc2', | | 21 | + 'ucs-2', 'UCS-2', 'UcS-2', | | 22 | + 'usc-2', 'USC-2', 'uSc-2', | | 23 | + 'utf16le', 'utf-16le', 'UTF-16LE', 'UTF16LE', | 17 | 24 | 'binary', 'BINARY', 'latin1', 'base64', 'BASE64', | 18 | | - 'hex', 'HEX', 'foo', '1', 'false', 'undefined', '[]']; | | 25 | + 'hex', 'HEX', 'foo', '1', 'false', 'undefined', '[]', '{}']; | 19 | 26 |
| 20 | 27 | const bench = common.createBenchmark(main, { | 21 | 28 | input: inputs.concat(Object.keys(groupedInputs)), | @@ -42,6 +49,8 @@ function getInput(input) { | 42 | 49 | return [undefined]; | 43 | 50 | case '[]': | 44 | 51 | return [[]]; | | 52 | + case '{}': | | 53 | + return [{}]; | 45 | 54 | default: | 46 | 55 | return [input]; | 47 | 56 | } | @@ -53,7 +62,7 @@ function main({ input, n }) { | 53 | 62 | var noDead = ''; | 54 | 63 |
| 55 | 64 | bench.start(); | 56 | | - for (var i = 0; i < n; i += 1) { | | 65 | + for (var i = 0; i < n; ++i) { | 57 | 66 | for (var j = 0; j < inputs.length; ++j) { | 58 | 67 | noDead = normalizeEncoding(inputs[j]); | 59 | 68 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/util.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -115,7 +115,7 @@ function slowCases(enc) { | 115 | 115 | if (enc === 'ucs2' || enc === 'UCS2') return 'utf16le'; | 116 | 116 | enc = `${enc}`.toLowerCase(); | 117 | 117 | if (enc === 'utf8') return 'utf8'; | 118 | | - if (enc === 'ucs2' || enc === 'UCS2') return 'utf16le'; | | 118 | + if (enc === 'ucs2') return 'utf16le'; | 119 | 119 | break; | 120 | 120 | case 3: | 121 | 121 | if (enc === 'hex' || enc === 'HEX' || `${enc}`.toLowerCase() === 'hex') | @@ -131,6 +131,7 @@ function slowCases(enc) { | 131 | 131 | if (enc === 'utf-8') return 'utf8'; | 132 | 132 | if (enc === 'ascii') return 'ascii'; | 133 | 133 | if (enc === 'usc-2') return 'utf16le'; | | 134 | + if (enc === 'ucs-2') return 'utf16le'; | 134 | 135 | break; | 135 | 136 | case 6: | 136 | 137 | if (enc === 'base64') return 'base64'; | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-internal-util-normalizeencoding.js +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,10 +18,16 @@ const tests = [ | 18 | 18 | ['utF-8', 'utf8'], | 19 | 19 | ['ucs2', 'utf16le'], | 20 | 20 | ['UCS2', 'utf16le'], | | 21 | + ['ucs-2', 'utf16le'], | | 22 | + ['UCS-2', 'utf16le'], | | 23 | + ['UcS-2', 'utf16le'], | 21 | 24 | ['utf16le', 'utf16le'], | 22 | 25 | ['utf-16le', 'utf16le'], | 23 | 26 | ['UTF-16LE', 'utf16le'], | 24 | 27 | ['UTF16LE', 'utf16le'], | | 28 | + ['usc-2', 'utf16le'], | | 29 | + ['USC-2', 'utf16le'], | | 30 | + ['uSc-2', 'utf16le'], | 25 | 31 | ['binary', 'latin1'], | 26 | 32 | ['BINARY', 'latin1'], | 27 | 33 | ['latin1', 'latin1'], | @@ -36,6 +42,7 @@ const tests = [ | 36 | 42 | [NaN, undefined], | 37 | 43 | [0, undefined], | 38 | 44 | [[], undefined], | | 45 | + [{}, undefined] | 39 | 46 | ]; | 40 | 47 |
| 41 | 48 | tests.forEach((e, i) => { | |
|