| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package com.google.javascript.jscomp; | 5 package com.google.javascript.jscomp; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Tests {@link ChromePass}. | 8 * Tests {@link ChromePass}. |
| 9 */ | 9 */ |
| 10 public class ChromePassTest extends CompilerTestCase { | 10 public class ChromePassTest extends CompilerTestCase { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 " /** I'm function's JSDoc */\n" + | 69 " /** I'm function's JSDoc */\n" + |
| 70 " namespace.externalStaticMethod = function internalStaticMethod()
{\n" + | 70 " namespace.externalStaticMethod = function internalStaticMethod()
{\n" + |
| 71 " alert(42);\n" + | 71 " alert(42);\n" + |
| 72 " }\n" + | 72 " }\n" + |
| 73 " return {\n" + | 73 " return {\n" + |
| 74 " externalStaticMethod: namespace.externalStaticMethod\n" + | 74 " externalStaticMethod: namespace.externalStaticMethod\n" + |
| 75 " };\n" + | 75 " };\n" + |
| 76 "});"); | 76 "});"); |
| 77 } | 77 } |
| 78 | 78 |
| 79 public void testCrDefineReassignsExportedFunctionByQualifiedName() throws Ex
ception { | 79 public void testCrDefineReassignsExportedVarByQualifiedName() throws Excepti
on { |
| 80 test( | 80 test( |
| 81 "cr.define('namespace', function() {\n" + | 81 "cr.define('namespace', function() {\n" + |
| 82 " var internalStaticMethod = function() {\n" + | 82 " var internalStaticMethod = function() {\n" + |
| 83 " alert(42);\n" + | 83 " alert(42);\n" + |
| 84 " }\n" + | 84 " }\n" + |
| 85 " return {\n" + | 85 " return {\n" + |
| 86 " externalStaticMethod: internalStaticMethod\n" + | 86 " externalStaticMethod: internalStaticMethod\n" + |
| 87 " };\n" + | 87 " };\n" + |
| 88 "});", | 88 "});", |
| 89 "var namespace = namespace || {};\n" + | 89 "var namespace = namespace || {};\n" + |
| 90 "cr.define('namespace', function() {\n" + | 90 "cr.define('namespace', function() {\n" + |
| 91 " namespace.externalStaticMethod = function() {\n" + | 91 " namespace.externalStaticMethod = function() {\n" + |
| 92 " alert(42);\n" + | 92 " alert(42);\n" + |
| 93 " }\n" + | 93 " }\n" + |
| 94 " return {\n" + | 94 " return {\n" + |
| 95 " externalStaticMethod: namespace.externalStaticMethod\n" + | 95 " externalStaticMethod: namespace.externalStaticMethod\n" + |
| 96 " };\n" + | 96 " };\n" + |
| 97 "});"); | 97 "});"); |
| 98 } | 98 } |
| 99 | 99 |
| 100 public void testCrDefineExportsVarsWithoutAssignment() throws Exception { |
| 101 test( |
| 102 "cr.define('namespace', function() {\n" + |
| 103 " var a;\n" + |
| 104 " return {\n" + |
| 105 " a: a\n" + |
| 106 " };\n" + |
| 107 "});\n", |
| 108 "var namespace = namespace || {};\n" + |
| 109 "cr.define('namespace', function() {\n" + |
| 110 " namespace.a;\n" + |
| 111 " return {\n" + |
| 112 " a: namespace.a\n" + |
| 113 " };\n" + |
| 114 "});\n"); |
| 115 } |
| 116 |
| 117 public void testCrDefineExportsVarsWithoutAssignmentWithJSDoc() throws Excep
tion { |
| 118 test( |
| 119 "cr.define('namespace', function() {\n" + |
| 120 " /** @type {number} */\n" + |
| 121 " var a;\n" + |
| 122 " return {\n" + |
| 123 " a: a\n" + |
| 124 " };\n" + |
| 125 "});\n", |
| 126 "var namespace = namespace || {};\n" + |
| 127 "cr.define('namespace', function() {\n" + |
| 128 " /** @type {number} */\n" + |
| 129 " namespace.a;\n" + |
| 130 " return {\n" + |
| 131 " a: namespace.a\n" + |
| 132 " };\n" + |
| 133 "});\n"); |
| 134 } |
| 135 |
| 100 public void testCrDefineCopiesJSDocForExportedVariable() throws Exception { | 136 public void testCrDefineCopiesJSDocForExportedVariable() throws Exception { |
| 101 test( | 137 test( |
| 102 "cr.define('namespace', function() {\n" + | 138 "cr.define('namespace', function() {\n" + |
| 103 " /** I'm function's JSDoc */\n" + | 139 " /** I'm function's JSDoc */\n" + |
| 104 " var internalStaticMethod = function() {\n" + | 140 " var internalStaticMethod = function() {\n" + |
| 105 " alert(42);\n" + | 141 " alert(42);\n" + |
| 106 " }\n" + | 142 " }\n" + |
| 107 " return {\n" + | 143 " return {\n" + |
| 108 " externalStaticMethod: internalStaticMethod\n" + | 144 " externalStaticMethod: internalStaticMethod\n" + |
| 109 " };\n" + | 145 " };\n" + |
| (...skipping 20 matching lines...) Expand all Loading... |
| 130 "});", | 166 "});", |
| 131 "var namespace = namespace || {};\n" + | 167 "var namespace = namespace || {};\n" + |
| 132 "cr.define('namespace', function() {\n" + | 168 "cr.define('namespace', function() {\n" + |
| 133 " function internalStaticMethod() {\n" + | 169 " function internalStaticMethod() {\n" + |
| 134 " alert(42);\n" + | 170 " alert(42);\n" + |
| 135 " }\n" + | 171 " }\n" + |
| 136 " return {};\n" + | 172 " return {};\n" + |
| 137 "});"); | 173 "});"); |
| 138 } | 174 } |
| 139 | 175 |
| 176 public void testCrDefineDoesNothingWithNonExportedVar() throws Exception { |
| 177 test( |
| 178 "cr.define('namespace', function() {\n" + |
| 179 " var a;\n" + |
| 180 " var b;\n" + |
| 181 " return {\n" + |
| 182 " a: a\n" + |
| 183 " };\n" + |
| 184 "});\n", |
| 185 "var namespace = namespace || {};\n" + |
| 186 "cr.define('namespace', function() {\n" + |
| 187 " namespace.a;\n" + |
| 188 " var b;\n" + |
| 189 " return {\n" + |
| 190 " a: namespace.a\n" + |
| 191 " };\n" + |
| 192 "});\n"); |
| 193 } |
| 194 |
| 140 public void testCrDefineChangesReferenceToExportedFunction() throws Exceptio
n { | 195 public void testCrDefineChangesReferenceToExportedFunction() throws Exceptio
n { |
| 141 test( | 196 test( |
| 142 "cr.define('namespace', function() {\n" + | 197 "cr.define('namespace', function() {\n" + |
| 143 " function internalStaticMethod() {\n" + | 198 " function internalStaticMethod() {\n" + |
| 144 " alert(42);\n" + | 199 " alert(42);\n" + |
| 145 " }\n" + | 200 " }\n" + |
| 146 " function letsUseIt() {\n" + | 201 " function letsUseIt() {\n" + |
| 147 " internalStaticMethod();\n" + | 202 " internalStaticMethod();\n" + |
| 148 " }\n" + | 203 " }\n" + |
| 149 " return {\n" + | 204 " return {\n" + |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 "var a = a || {};\n" + | 305 "var a = a || {};\n" + |
| 251 "a.b = a.b || {};\n" + | 306 "a.b = a.b || {};\n" + |
| 252 "a.b.c = a.b.c || {};\n" + | 307 "a.b.c = a.b.c || {};\n" + |
| 253 "cr.exportPath('a.b.c');"); | 308 "cr.exportPath('a.b.c');"); |
| 254 } | 309 } |
| 255 | 310 |
| 256 public void testCrDefineCreatesEveryObjectOnlyOnce() throws Exception { | 311 public void testCrDefineCreatesEveryObjectOnlyOnce() throws Exception { |
| 257 test( | 312 test( |
| 258 "cr.define('a.b.c.d', function() {\n" + | 313 "cr.define('a.b.c.d', function() {\n" + |
| 259 " return {};\n" + | 314 " return {};\n" + |
| 260 "});" + | 315 "});\n" + |
| 261 "cr.define('a.b.e.f', function() {\n" + | 316 "cr.define('a.b.e.f', function() {\n" + |
| 262 " return {};\n" + | 317 " return {};\n" + |
| 263 "});", | 318 "});", |
| 264 "var a = a || {};\n" + | 319 "var a = a || {};\n" + |
| 265 "a.b = a.b || {};\n" + | 320 "a.b = a.b || {};\n" + |
| 266 "a.b.c = a.b.c || {};\n" + | 321 "a.b.c = a.b.c || {};\n" + |
| 267 "a.b.c.d = a.b.c.d || {};\n" + | 322 "a.b.c.d = a.b.c.d || {};\n" + |
| 268 "cr.define('a.b.c.d', function() {\n" + | 323 "cr.define('a.b.c.d', function() {\n" + |
| 269 " return {};\n" + | 324 " return {};\n" + |
| 270 "});" + | 325 "});\n" + |
| 271 "a.b.e = a.b.e || {};\n" + | 326 "a.b.e = a.b.e || {};\n" + |
| 272 "a.b.e.f = a.b.e.f || {};\n" + | 327 "a.b.e.f = a.b.e.f || {};\n" + |
| 273 "cr.define('a.b.e.f', function() {\n" + | 328 "cr.define('a.b.e.f', function() {\n" + |
| 274 " return {};\n" + | 329 " return {};\n" + |
| 275 "});"); | 330 "});"); |
| 276 } | 331 } |
| 277 | 332 |
| 278 public void testCrDefineAndCrExportPathCreateEveryObjectOnlyOnce() throws Ex
ception { | 333 public void testCrDefineAndCrExportPathCreateEveryObjectOnlyOnce() throws Ex
ception { |
| 279 test( | 334 test( |
| 280 "cr.exportPath('a.b.c.d');\n" + | 335 "cr.exportPath('a.b.c.d');\n" + |
| (...skipping 21 matching lines...) Expand all Loading... |
| 302 "cr.define('cr.ui', function() {\n" + | 357 "cr.define('cr.ui', function() {\n" + |
| 303 " return {};\n" + | 358 " return {};\n" + |
| 304 "});"); | 359 "});"); |
| 305 } | 360 } |
| 306 | 361 |
| 307 public void testCrExportPathInvalidNumberOfArguments() throws Exception { | 362 public void testCrExportPathInvalidNumberOfArguments() throws Exception { |
| 308 test("cr.exportPath();", null, ChromePass.CR_EXPORT_PATH_WRONG_NUMBER_OF
_ARGUMENTS); | 363 test("cr.exportPath();", null, ChromePass.CR_EXPORT_PATH_WRONG_NUMBER_OF
_ARGUMENTS); |
| 309 } | 364 } |
| 310 | 365 |
| 311 } | 366 } |
| OLD | NEW |