diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-03-19 02:17:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-19 02:17:15 +0800 |
commit | 274331d0ea05197ea7cb531ccd1d78e0c7b8662c (patch) | |
tree | c4b77238219b3e1d547ac297901395ff8c618612 /test | |
parent | 0489d6de6499154c758a6464387546ec5a060f67 (diff) | |
download | tracifyjs-274331d0ea05197ea7cb531ccd1d78e0c7b8662c.tar.gz tracifyjs-274331d0ea05197ea7cb531ccd1d78e0c7b8662c.zip |
transform String.charAt() to index access (#1620)
Guarded by `unsafe` as `charAt()` can be overridden.
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/evaluate.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 68739503..3d0d8869 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -200,6 +200,7 @@ negative_zero: { 1 / (-0) ); } + expect_stdout: true } positive_zero: { @@ -220,6 +221,7 @@ positive_zero: { 1 / (0) ); } + expect_stdout: true } unsafe_constant: { @@ -411,6 +413,7 @@ unsafe_integer_key: { 1["1"] + 1 ); } + expect_stdout: true } unsafe_integer_key_complex: { @@ -438,6 +441,7 @@ unsafe_integer_key_complex: { 2 ); } + expect_stdout: true } unsafe_float_key: { @@ -465,6 +469,7 @@ unsafe_float_key: { 1["3.14"] + 1 ); } + expect_stdout: true } unsafe_float_key_complex: { @@ -492,6 +497,7 @@ unsafe_float_key_complex: { 2 ); } + expect_stdout: true } unsafe_array: { @@ -554,6 +560,7 @@ unsafe_string: { "11" ); } + expect_stdout: true } unsafe_array_bad_index: { @@ -575,6 +582,7 @@ unsafe_array_bad_index: { [1, 2, 3, 4][3.14] + 1 ); } + expect_stdout: true } unsafe_string_bad_index: { @@ -596,6 +604,7 @@ unsafe_string_bad_index: { "1234"[3.14] + 1 ); } + expect_stdout: true } unsafe_prototype_function: { @@ -701,3 +710,72 @@ in_boolean_context: { ); } } + +unsafe_charAt: { + options = { + evaluate : true, + unsafe : true + } + input: { + console.log( + "1234" + 1, + "1234".charAt(0) + 1, + "1234".charAt(6 - 5) + 1, + ("12" + "34").charAt(0) + 1, + ("12" + "34").charAt(6 - 5) + 1, + [1, 2, 3, 4].join("").charAt(0) + 1 + ); + } + expect: { + console.log( + "12341", + "11", + "21", + "11", + "21", + "11" + ); + } + expect_stdout: true +} + +unsafe_charAt_bad_index: { + options = { + evaluate : true, + unsafe : true + } + input: { + console.log( + "1234".charAt() + 1, + "1234".charAt("a") + 1, + "1234".charAt(3.14) + 1 + ); + } + expect: { + console.log( + "11", + "11", + "41" + ); + } + expect_stdout: true +} + +unsafe_charAt_noop: { + options = { + evaluate : true, + unsafe : true + } + input: { + console.log( + s.charAt(0), + "string".charAt(x) + ); + } + expect: { + console.log( + s.charAt(0), + "string".charAt(x) + ); + } +} |