Best JavaScript code snippet using stryker-parent
Resolver-test.js
Source:Resolver-test.js
1/**2 * Copyright (c) 2015-present, Facebook, Inc.3 * All rights reserved.4 *5 * This source code is licensed under the BSD-style license found in the6 * LICENSE file in the root directory of this source tree. An additional grant7 * of patent rights can be found in the PATENTS file in the same directory.8 */9'use strict';10jest.dontMock('../')11 .dontMock('underscore')12 .dontMock('PixelRatio')13 .dontMock('../../DependencyResolver/lib/extractRequires')14 .dontMock('../../DependencyResolver/lib/replacePatterns');15jest.mock('path');16var Promise = require('promise');17var Resolver = require('../');18var Module = require('../../DependencyResolver/Module');19var Polyfill = require('../../DependencyResolver/Polyfill');20var DependencyGraph = require('../../DependencyResolver/DependencyGraph');21var path = require('path');22var _ = require('underscore');23describe('Resolver', function() {24 beforeEach(function() {25 Polyfill.mockClear();26 // For the polyfillDeps27 path.join.mockImpl(function(a, b) {28 return b;29 });30 });31 class ResolutionResponseMock {32 constructor({dependencies, mainModuleId, asyncDependencies}) {33 this.dependencies = dependencies;34 this.mainModuleId = mainModuleId;35 this.asyncDependencies = asyncDependencies;36 }37 prependDependency(dependency) {38 this.dependencies.unshift(dependency);39 }40 finalize() {41 return Promise.resolve(this);42 }43 }44 function createModule(id, dependencies) {45 var module = new Module({});46 module.getName.mockImpl(() => Promise.resolve(id));47 module.getDependencies.mockImpl(() => Promise.resolve(dependencies));48 return module;49 }50 describe('getDependencies', function() {51 pit('should get dependencies with polyfills', function() {52 var module = createModule('index');53 var deps = [module];54 var depResolver = new Resolver({55 projectRoot: '/root',56 });57 DependencyGraph.prototype.getDependencies.mockImpl(function() {58 return Promise.resolve(new ResolutionResponseMock({59 dependencies: deps,60 mainModuleId: 'index',61 asyncDependencies: [],62 }));63 });64 return depResolver.getDependencies('/root/index.js', { dev: false })65 .then(function(result) {66 expect(result.mainModuleId).toEqual('index');67 expect(result.dependencies[result.dependencies.length - 1]).toBe(module);68 expect(_.pluck(Polyfill.mock.calls, 0)).toEqual([69 { path: 'polyfills/polyfills.js',70 id: 'polyfills/polyfills.js',71 isPolyfill: true,72 dependencies: []73 },74 { id: 'polyfills/console.js',75 isPolyfill: true,76 path: 'polyfills/console.js',77 dependencies: [78 'polyfills/polyfills.js'79 ],80 },81 { id: 'polyfills/error-guard.js',82 isPolyfill: true,83 path: 'polyfills/error-guard.js',84 dependencies: [85 'polyfills/polyfills.js',86 'polyfills/console.js'87 ],88 },89 { id: 'polyfills/String.prototype.es6.js',90 isPolyfill: true,91 path: 'polyfills/String.prototype.es6.js',92 dependencies: [93 'polyfills/polyfills.js',94 'polyfills/console.js',95 'polyfills/error-guard.js'96 ],97 },98 { id: 'polyfills/Array.prototype.es6.js',99 isPolyfill: true,100 path: 'polyfills/Array.prototype.es6.js',101 dependencies: [102 'polyfills/polyfills.js',103 'polyfills/console.js',104 'polyfills/error-guard.js',105 'polyfills/String.prototype.es6.js',106 ],107 },108 { id: 'polyfills/Array.es6.js',109 isPolyfill: true,110 path: 'polyfills/Array.es6.js',111 dependencies: [112 'polyfills/polyfills.js',113 'polyfills/console.js',114 'polyfills/error-guard.js',115 'polyfills/String.prototype.es6.js',116 'polyfills/Array.prototype.es6.js',117 ],118 },119 { id: 'polyfills/babelHelpers.js',120 isPolyfill: true,121 path: 'polyfills/babelHelpers.js',122 dependencies: [123 'polyfills/polyfills.js',124 'polyfills/console.js',125 'polyfills/error-guard.js',126 'polyfills/String.prototype.es6.js',127 'polyfills/Array.prototype.es6.js',128 'polyfills/Array.es6.js',129 ],130 },131 ]);132 });133 });134 pit('should get dependencies with polyfills', function() {135 var module = createModule('index');136 var deps = [module];137 var depResolver = new Resolver({138 projectRoot: '/root',139 });140 DependencyGraph.prototype.getDependencies.mockImpl(function() {141 return Promise.resolve(new ResolutionResponseMock({142 dependencies: deps,143 mainModuleId: 'index',144 asyncDependencies: [],145 }));146 });147 return depResolver.getDependencies('/root/index.js', { dev: true })148 .then(function(result) {149 expect(result.mainModuleId).toEqual('index');150 expect(DependencyGraph.mock.instances[0].getDependencies).toBeCalledWith('/root/index.js', undefined);151 expect(result.dependencies[0]).toBe(Polyfill.mock.instances[0]);152 expect(result.dependencies[result.dependencies.length - 1])153 .toBe(module);154 });155 });156 pit('should pass in more polyfills', function() {157 var module = createModule('index');158 var deps = [module];159 var depResolver = new Resolver({160 projectRoot: '/root',161 polyfillModuleNames: ['some module'],162 });163 DependencyGraph.prototype.getDependencies.mockImpl(function() {164 return Promise.resolve(new ResolutionResponseMock({165 dependencies: deps,166 mainModuleId: 'index',167 asyncDependencies: [],168 }));169 });170 return depResolver.getDependencies('/root/index.js', { dev: false })171 .then((result) => {172 expect(result.mainModuleId).toEqual('index');173 expect(Polyfill.mock.calls[result.dependencies.length - 2]).toEqual([174 { path: 'some module',175 id: 'some module',176 isPolyfill: true,177 dependencies: [178 'polyfills/polyfills.js',179 'polyfills/console.js',180 'polyfills/error-guard.js',181 'polyfills/String.prototype.es6.js',182 'polyfills/Array.prototype.es6.js',183 'polyfills/Array.es6.js',184 'polyfills/babelHelpers.js',185 ]186 },187 ]);188 });189 });190 });191 describe('wrapModule', function() {192 pit('should resolve modules', function() {193 var depResolver = new Resolver({194 projectRoot: '/root',195 });196 var dependencies = ['x', 'y', 'z', 'a', 'b'];197 /*eslint-disable */198 var code = [199 // single line import200 "import'x';",201 "import 'x';",202 "import 'x' ;",203 "import Default from 'x';",204 "import * as All from 'x';",205 "import {} from 'x';",206 "import { } from 'x';",207 "import {Foo} from 'x';",208 "import { Foo } from 'x';",209 "import { Foo, } from 'x';",210 "import {Foo as Bar} from 'x';",211 "import { Foo as Bar } from 'x';",212 "import { Foo as Bar, } from 'x';",213 "import { Foo, Bar } from 'x';",214 "import { Foo, Bar, } from 'x';",215 "import { Foo as Bar, Baz } from 'x';",216 "import { Foo as Bar, Baz, } from 'x';",217 "import { Foo, Bar as Baz } from 'x';",218 "import { Foo, Bar as Baz, } from 'x';",219 "import { Foo as Bar, Baz as Qux } from 'x';",220 "import { Foo as Bar, Baz as Qux, } from 'x';",221 "import { Foo, Bar, Baz } from 'x';",222 "import { Foo, Bar, Baz, } from 'x';",223 "import { Foo as Bar, Baz, Qux } from 'x';",224 "import { Foo as Bar, Baz, Qux, } from 'x';",225 "import { Foo, Bar as Baz, Qux } from 'x';",226 "import { Foo, Bar as Baz, Qux, } from 'x';",227 "import { Foo, Bar, Baz as Qux } from 'x';",228 "import { Foo, Bar, Baz as Qux, } from 'x';",229 "import { Foo as Bar, Baz as Qux, Norf } from 'x';",230 "import { Foo as Bar, Baz as Qux, Norf, } from 'x';",231 "import { Foo as Bar, Baz, Qux as Norf } from 'x';",232 "import { Foo as Bar, Baz, Qux as Norf, } from 'x';",233 "import { Foo, Bar as Baz, Qux as Norf } from 'x';",234 "import { Foo, Bar as Baz, Qux as Norf, } from 'x';",235 "import { Foo as Bar, Baz as Qux, Norf as Enuf } from 'x';",236 "import { Foo as Bar, Baz as Qux, Norf as Enuf, } from 'x';",237 "import Default, * as All from 'x';",238 "import Default, { } from 'x';",239 "import Default, { Foo } from 'x';",240 "import Default, { Foo, } from 'x';",241 "import Default, { Foo as Bar } from 'x';",242 "import Default, { Foo as Bar, } from 'x';",243 "import Default, { Foo, Bar } from 'x';",244 "import Default, { Foo, Bar, } from 'x';",245 "import Default, { Foo as Bar, Baz } from 'x';",246 "import Default, { Foo as Bar, Baz, } from 'x';",247 "import Default, { Foo, Bar as Baz } from 'x';",248 "import Default, { Foo, Bar as Baz, } from 'x';",249 "import Default, { Foo as Bar, Baz as Qux } from 'x';",250 "import Default, { Foo as Bar, Baz as Qux, } from 'x';",251 "import Default, { Foo, Bar, Baz } from 'x';",252 "import Default, { Foo, Bar, Baz, } from 'x';",253 "import Default, { Foo as Bar, Baz, Qux } from 'x';",254 "import Default, { Foo as Bar, Baz, Qux, } from 'x';",255 "import Default, { Foo, Bar as Baz, Qux } from 'x';",256 "import Default, { Foo, Bar as Baz, Qux, } from 'x';",257 "import Default, { Foo, Bar, Baz as Qux } from 'x';",258 "import Default, { Foo, Bar, Baz as Qux, } from 'x';",259 "import Default, { Foo as Bar, Baz as Qux, Norf } from 'x';",260 "import Default, { Foo as Bar, Baz as Qux, Norf, } from 'x';",261 "import Default, { Foo as Bar, Baz, Qux as Norf } from 'x';",262 "import Default, { Foo as Bar, Baz, Qux as Norf, } from 'x';",263 "import Default, { Foo, Bar as Baz, Qux as Norf } from 'x';",264 "import Default, { Foo, Bar as Baz, Qux as Norf, } from 'x';",265 "import Default, { Foo as Bar, Baz as Qux, Norf as NoMore } from 'x';",266 "import Default, { Foo as Bar, Baz as Qux, Norf as NoMore, } from 'x';",267 "import Default , { } from 'x';",268 'import "x";',269 'import Default from "x";',270 'import * as All from "x";',271 'import { } from "x";',272 'import { Foo } from "x";',273 'import { Foo, } from "x";',274 'import { Foo as Bar } from "x";',275 'import { Foo as Bar, } from "x";',276 'import { Foo, Bar } from "x";',277 'import { Foo, Bar, } from "x";',278 'import { Foo as Bar, Baz } from "x";',279 'import { Foo as Bar, Baz, } from "x";',280 'import { Foo, Bar as Baz } from "x";',281 'import { Foo, Bar as Baz, } from "x";',282 'import { Foo as Bar, Baz as Qux } from "x";',283 'import { Foo as Bar, Baz as Qux, } from "x";',284 'import { Foo, Bar, Baz } from "x";',285 'import { Foo, Bar, Baz, } from "x";',286 'import { Foo as Bar, Baz, Qux } from "x";',287 'import { Foo as Bar, Baz, Qux, } from "x";',288 'import { Foo, Bar as Baz, Qux } from "x";',289 'import { Foo, Bar as Baz, Qux, } from "x";',290 'import { Foo, Bar, Baz as Qux } from "x";',291 'import { Foo, Bar, Baz as Qux, } from "x";',292 'import { Foo as Bar, Baz as Qux, Norf } from "x";',293 'import { Foo as Bar, Baz as Qux, Norf, } from "x";',294 'import { Foo as Bar, Baz, Qux as Norf } from "x";',295 'import { Foo as Bar, Baz, Qux as Norf, } from "x";',296 'import { Foo, Bar as Baz, Qux as Norf } from "x";',297 'import { Foo, Bar as Baz, Qux as Norf, } from "x";',298 'import { Foo as Bar, Baz as Qux, Norf as NoMore } from "x";',299 'import { Foo as Bar, Baz as Qux, Norf as NoMore, } from "x";',300 'import Default, * as All from "x";',301 'import Default, { } from "x";',302 'import Default, { Foo } from "x";',303 'import Default, { Foo, } from "x";',304 'import Default, { Foo as Bar } from "x";',305 'import Default, { Foo as Bar, } from "x";',306 'import Default, { Foo, Bar } from "x";',307 'import Default, { Foo, Bar, } from "x";',308 'import Default, { Foo as Bar, Baz } from "x";',309 'import Default, { Foo as Bar, Baz, } from "x";',310 'import Default, { Foo, Bar as Baz } from "x";',311 'import Default, { Foo, Bar as Baz, } from "x";',312 'import Default, { Foo as Bar, Baz as Qux } from "x";',313 'import Default, { Foo as Bar, Baz as Qux, } from "x";',314 'import Default, { Foo, Bar, Baz } from "x";',315 'import Default, { Foo, Bar, Baz, } from "x";',316 'import Default, { Foo as Bar, Baz, Qux } from "x";',317 'import Default, { Foo as Bar, Baz, Qux, } from "x";',318 'import Default, { Foo, Bar as Baz, Qux } from "x";',319 'import Default, { Foo, Bar as Baz, Qux, } from "x";',320 'import Default, { Foo, Bar, Baz as Qux } from "x";',321 'import Default, { Foo, Bar, Baz as Qux, } from "x";',322 'import Default, { Foo as Bar, Baz as Qux, Norf } from "x";',323 'import Default, { Foo as Bar, Baz as Qux, Norf, } from "x";',324 'import Default, { Foo as Bar, Baz, Qux as Norf } from "x";',325 'import Default, { Foo as Bar, Baz, Qux as Norf, } from "x";',326 'import Default, { Foo, Bar as Baz, Qux as Norf } from "x";',327 'import Default, { Foo, Bar as Baz, Qux as Norf, } from "x";',328 'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf } from "x";',329 'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "x";',330 'import Default from "y";',331 'import * as All from \'z\';',332 // import with support for new lines333 "import { Foo,\n Bar }\n from 'x';",334 "import { \nFoo,\nBar,\n }\n from 'x';",335 "import { Foo as Bar,\n Baz\n }\n from 'x';",336 "import { \nFoo as Bar,\n Baz\n, }\n from 'x';",337 "import { Foo,\n Bar as Baz\n }\n from 'x';",338 "import { Foo,\n Bar as Baz,\n }\n from 'x';",339 "import { Foo as Bar,\n Baz as Qux\n }\n from 'x';",340 "import { Foo as Bar,\n Baz as Qux,\n }\n from 'x';",341 "import { Foo,\n Bar,\n Baz }\n from 'x';",342 "import { Foo,\n Bar,\n Baz,\n }\n from 'x';",343 "import { Foo as Bar,\n Baz,\n Qux\n }\n from 'x';",344 "import { Foo as Bar,\n Baz,\n Qux,\n }\n from 'x';",345 "import { Foo,\n Bar as Baz,\n Qux\n }\n from 'x';",346 "import { Foo,\n Bar as Baz,\n Qux,\n }\n from 'x';",347 "import { Foo,\n Bar,\n Baz as Qux\n }\n from 'x';",348 "import { Foo,\n Bar,\n Baz as Qux,\n }\n from 'x';",349 "import { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'x';",350 "import { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'x';",351 "import { Foo as Bar,\n Baz,\n Qux as Norf\n }\n from 'x';",352 "import { Foo as Bar,\n Baz,\n Qux as Norf,\n }\n from 'x';",353 "import { Foo,\n Bar as Baz,\n Qux as Norf\n }\n from 'x';",354 "import { Foo,\n Bar as Baz,\n Qux as Norf,\n }\n from 'x';",355 "import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf\n }\n from 'x';",356 "import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf,\n }\n from 'x';",357 "import Default,\n * as All from 'x';",358 "import Default,\n { } from 'x';",359 "import Default,\n { Foo\n }\n from 'x';",360 "import Default,\n { Foo,\n }\n from 'x';",361 "import Default,\n { Foo as Bar\n }\n from 'x';",362 "import Default,\n { Foo as Bar,\n }\n from 'x';",363 "import Default,\n { Foo,\n Bar\n } from\n 'x';",364 "import Default,\n { Foo,\n Bar,\n } from\n 'x';",365 "import Default,\n { Foo as Bar,\n Baz\n }\n from 'x';",366 "import Default,\n { Foo as Bar,\n Baz,\n }\n from 'x';",367 "import Default,\n { Foo,\n Bar as Baz\n }\n from 'x';",368 "import Default,\n { Foo,\n Bar as Baz,\n }\n from 'x';",369 "import Default,\n { Foo as Bar,\n Baz as Qux\n }\n from 'x';",370 "import Default,\n { Foo as Bar,\n Baz as Qux,\n }\n from 'x';",371 "import Default,\n { Foo,\n Bar,\n Baz\n }\n from 'x';",372 "import Default,\n { Foo,\n Bar,\n Baz,\n }\n from 'x';",373 "import Default,\n { Foo as Bar,\n Baz,\n Qux\n }\n from 'x';",374 "import Default,\n { Foo as Bar,\n Baz,\n Qux,\n }\n from 'x';",375 "import Default,\n { Foo,\n Bar as Baz,\n Qux\n }\n from 'x';",376 "import Default,\n { Foo,\n Bar as Baz,\n Qux,\n }\n from 'x';",377 "import Default,\n { Foo,\n Bar,\n Baz as Qux\n }\n from 'x';",378 "import Default,\n { Foo,\n Bar,\n Baz as Qux,\n }\n from 'x';",379 "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'x';",380 "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'x';",381 "import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf }\n from 'x';",382 "import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf, }\n from 'x';",383 "import Default,\n { Foo, Bar as Baz,\n Qux as Norf }\n from 'x';",384 "import Default,\n { Foo, Bar as Baz,\n Qux as Norf, }\n from 'x';",385 "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore\n }\n from 'x';",386 "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore,\n }\n from 'x';",387 "import Default\n , { } from 'x';",388 // single line export389 "export'x';",390 "export 'x';",391 "export 'x' ;",392 "export Default from 'x';",393 "export * as All from 'x';",394 "export {} from 'x';",395 "export { } from 'x';",396 "export {Foo} from 'x';",397 "export { Foo } from 'x';",398 "export { Foo, } from 'x';",399 "export {Foo as Bar} from 'x';",400 "export { Foo as Bar } from 'x';",401 "export { Foo as Bar, } from 'x';",402 "export { Foo, Bar } from 'x';",403 "export { Foo, Bar, } from 'x';",404 "export { Foo as Bar, Baz } from 'x';",405 "export { Foo as Bar, Baz, } from 'x';",406 "export { Foo, Bar as Baz } from 'x';",407 "export { Foo, Bar as Baz, } from 'x';",408 "export { Foo as Bar, Baz as Qux } from 'x';",409 "export { Foo as Bar, Baz as Qux, } from 'x';",410 "export { Foo, Bar, Baz } from 'x';",411 "export { Foo, Bar, Baz, } from 'x';",412 "export { Foo as Bar, Baz, Qux } from 'x';",413 "export { Foo as Bar, Baz, Qux, } from 'x';",414 "export { Foo, Bar as Baz, Qux } from 'x';",415 "export { Foo, Bar as Baz, Qux, } from 'x';",416 "export { Foo, Bar, Baz as Qux } from 'x';",417 "export { Foo, Bar, Baz as Qux, } from 'x';",418 "export { Foo as Bar, Baz as Qux, Norf } from 'x';",419 "export { Foo as Bar, Baz as Qux, Norf, } from 'x';",420 "export { Foo as Bar, Baz, Qux as Norf } from 'x';",421 "export { Foo as Bar, Baz, Qux as Norf, } from 'x';",422 "export { Foo, Bar as Baz, Qux as Norf } from 'x';",423 "export { Foo, Bar as Baz, Qux as Norf, } from 'x';",424 "export { Foo as Bar, Baz as Qux, Norf as Enuf } from 'x';",425 "export { Foo as Bar, Baz as Qux, Norf as Enuf, } from 'x';",426 "export Default, * as All from 'x';",427 "export Default, { } from 'x';",428 "export Default, { Foo } from 'x';",429 "export Default, { Foo, } from 'x';",430 "export Default, { Foo as Bar } from 'x';",431 "export Default, { Foo as Bar, } from 'x';",432 "export Default, { Foo, Bar } from 'x';",433 "export Default, { Foo, Bar, } from 'x';",434 "export Default, { Foo as Bar, Baz } from 'x';",435 "export Default, { Foo as Bar, Baz, } from 'x';",436 "export Default, { Foo, Bar as Baz } from 'x';",437 "export Default, { Foo, Bar as Baz, } from 'x';",438 "export Default, { Foo as Bar, Baz as Qux } from 'x';",439 "export Default, { Foo as Bar, Baz as Qux, } from 'x';",440 "export Default, { Foo, Bar, Baz } from 'x';",441 "export Default, { Foo, Bar, Baz, } from 'x';",442 "export Default, { Foo as Bar, Baz, Qux } from 'x';",443 "export Default, { Foo as Bar, Baz, Qux, } from 'x';",444 "export Default, { Foo, Bar as Baz, Qux } from 'x';",445 "export Default, { Foo, Bar as Baz, Qux, } from 'x';",446 "export Default, { Foo, Bar, Baz as Qux } from 'x';",447 "export Default, { Foo, Bar, Baz as Qux, } from 'x';",448 "export Default, { Foo as Bar, Baz as Qux, Norf } from 'x';",449 "export Default, { Foo as Bar, Baz as Qux, Norf, } from 'x';",450 "export Default, { Foo as Bar, Baz, Qux as Norf } from 'x';",451 "export Default, { Foo as Bar, Baz, Qux as Norf, } from 'x';",452 "export Default, { Foo, Bar as Baz, Qux as Norf } from 'x';",453 "export Default, { Foo, Bar as Baz, Qux as Norf, } from 'x';",454 "export Default, { Foo as Bar, Baz as Qux, Norf as NoMore } from 'x';",455 "export Default, { Foo as Bar, Baz as Qux, Norf as NoMore, } from 'x';",456 "export Default , { } from 'x';",457 'export "x";',458 'export Default from "x";',459 'export * as All from "x";',460 'export { } from "x";',461 'export { Foo } from "x";',462 'export { Foo, } from "x";',463 'export { Foo as Bar } from "x";',464 'export { Foo as Bar, } from "x";',465 'export { Foo, Bar } from "x";',466 'export { Foo, Bar, } from "x";',467 'export { Foo as Bar, Baz } from "x";',468 'export { Foo as Bar, Baz, } from "x";',469 'export { Foo, Bar as Baz } from "x";',470 'export { Foo, Bar as Baz, } from "x";',471 'export { Foo as Bar, Baz as Qux } from "x";',472 'export { Foo as Bar, Baz as Qux, } from "x";',473 'export { Foo, Bar, Baz } from "x";',474 'export { Foo, Bar, Baz, } from "x";',475 'export { Foo as Bar, Baz, Qux } from "x";',476 'export { Foo as Bar, Baz, Qux, } from "x";',477 'export { Foo, Bar as Baz, Qux } from "x";',478 'export { Foo, Bar as Baz, Qux, } from "x";',479 'export { Foo, Bar, Baz as Qux } from "x";',480 'export { Foo, Bar, Baz as Qux, } from "x";',481 'export { Foo as Bar, Baz as Qux, Norf } from "x";',482 'export { Foo as Bar, Baz as Qux, Norf, } from "x";',483 'export { Foo as Bar, Baz, Qux as Norf } from "x";',484 'export { Foo as Bar, Baz, Qux as Norf, } from "x";',485 'export { Foo, Bar as Baz, Qux as Norf } from "x";',486 'export { Foo, Bar as Baz, Qux as Norf, } from "x";',487 'export { Foo as Bar, Baz as Qux, Norf as NoMore } from "x";',488 'export { Foo as Bar, Baz as Qux, Norf as NoMore, } from "x";',489 'export Default, * as All from "x";',490 'export Default, { } from "x";',491 'export Default, { Foo } from "x";',492 'export Default, { Foo, } from "x";',493 'export Default, { Foo as Bar } from "x";',494 'export Default, { Foo as Bar, } from "x";',495 'export Default, { Foo, Bar } from "x";',496 'export Default, { Foo, Bar, } from "x";',497 'export Default, { Foo as Bar, Baz } from "x";',498 'export Default, { Foo as Bar, Baz, } from "x";',499 'export Default, { Foo, Bar as Baz } from "x";',500 'export Default, { Foo, Bar as Baz, } from "x";',501 'export Default, { Foo as Bar, Baz as Qux } from "x";',502 'export Default, { Foo as Bar, Baz as Qux, } from "x";',503 'export Default, { Foo, Bar, Baz } from "x";',504 'export Default, { Foo, Bar, Baz, } from "x";',505 'export Default, { Foo as Bar, Baz, Qux } from "x";',506 'export Default, { Foo as Bar, Baz, Qux, } from "x";',507 'export Default, { Foo, Bar as Baz, Qux } from "x";',508 'export Default, { Foo, Bar as Baz, Qux, } from "x";',509 'export Default, { Foo, Bar, Baz as Qux } from "x";',510 'export Default, { Foo, Bar, Baz as Qux, } from "x";',511 'export Default, { Foo as Bar, Baz as Qux, Norf } from "x";',512 'export Default, { Foo as Bar, Baz as Qux, Norf, } from "x";',513 'export Default, { Foo as Bar, Baz, Qux as Norf } from "x";',514 'export Default, { Foo as Bar, Baz, Qux as Norf, } from "x";',515 'export Default, { Foo, Bar as Baz, Qux as Norf } from "x";',516 'export Default, { Foo, Bar as Baz, Qux as Norf, } from "x";',517 'export Default, { Foo as Bar, Baz as Qux, Norf as Enuf } from "x";',518 'export Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "x";',519 'export Default from "y";',520 'export * as All from \'z\';',521 // export with support for new lines522 "export { Foo,\n Bar }\n from 'x';",523 "export { \nFoo,\nBar,\n }\n from 'x';",524 "export { Foo as Bar,\n Baz\n }\n from 'x';",525 "export { \nFoo as Bar,\n Baz\n, }\n from 'x';",526 "export { Foo,\n Bar as Baz\n }\n from 'x';",527 "export { Foo,\n Bar as Baz,\n }\n from 'x';",528 "export { Foo as Bar,\n Baz as Qux\n }\n from 'x';",529 "export { Foo as Bar,\n Baz as Qux,\n }\n from 'x';",530 "export { Foo,\n Bar,\n Baz }\n from 'x';",531 "export { Foo,\n Bar,\n Baz,\n }\n from 'x';",532 "export { Foo as Bar,\n Baz,\n Qux\n }\n from 'x';",533 "export { Foo as Bar,\n Baz,\n Qux,\n }\n from 'x';",534 "export { Foo,\n Bar as Baz,\n Qux\n }\n from 'x';",535 "export { Foo,\n Bar as Baz,\n Qux,\n }\n from 'x';",536 "export { Foo,\n Bar,\n Baz as Qux\n }\n from 'x';",537 "export { Foo,\n Bar,\n Baz as Qux,\n }\n from 'x';",538 "export { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'x';",539 "export { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'x';",540 "export { Foo as Bar,\n Baz,\n Qux as Norf\n }\n from 'x';",541 "export { Foo as Bar,\n Baz,\n Qux as Norf,\n }\n from 'x';",542 "export { Foo,\n Bar as Baz,\n Qux as Norf\n }\n from 'x';",543 "export { Foo,\n Bar as Baz,\n Qux as Norf,\n }\n from 'x';",544 "export { Foo as Bar,\n Baz as Qux,\n Norf as Enuf\n }\n from 'x';",545 "export { Foo as Bar,\n Baz as Qux,\n Norf as Enuf,\n }\n from 'x';",546 "export Default,\n * as All from 'x';",547 "export Default,\n { } from 'x';",548 "export Default,\n { Foo\n }\n from 'x';",549 "export Default,\n { Foo,\n }\n from 'x';",550 "export Default,\n { Foo as Bar\n }\n from 'x';",551 "export Default,\n { Foo as Bar,\n }\n from 'x';",552 "export Default,\n { Foo,\n Bar\n } from\n 'x';",553 "export Default,\n { Foo,\n Bar,\n } from\n 'x';",554 "export Default,\n { Foo as Bar,\n Baz\n }\n from 'x';",555 "export Default,\n { Foo as Bar,\n Baz,\n }\n from 'x';",556 "export Default,\n { Foo,\n Bar as Baz\n }\n from 'x';",557 "export Default,\n { Foo,\n Bar as Baz,\n }\n from 'x';",558 "export Default,\n { Foo as Bar,\n Baz as Qux\n }\n from 'x';",559 "export Default,\n { Foo as Bar,\n Baz as Qux,\n }\n from 'x';",560 "export Default,\n { Foo,\n Bar,\n Baz\n }\n from 'x';",561 "export Default,\n { Foo,\n Bar,\n Baz,\n }\n from 'x';",562 "export Default,\n { Foo as Bar,\n Baz,\n Qux\n }\n from 'x';",563 "export Default,\n { Foo as Bar,\n Baz,\n Qux,\n }\n from 'x';",564 "export Default,\n { Foo,\n Bar as Baz,\n Qux\n }\n from 'x';",565 "export Default,\n { Foo,\n Bar as Baz,\n Qux,\n }\n from 'x';",566 "export Default,\n { Foo,\n Bar,\n Baz as Qux\n }\n from 'x';",567 "export Default,\n { Foo,\n Bar,\n Baz as Qux,\n }\n from 'x';",568 "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'x';",569 "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'x';",570 "export Default,\n { Foo as Bar,\n Baz,\n Qux as Norf }\n from 'x';",571 "export Default,\n { Foo as Bar,\n Baz,\n Qux as Norf, }\n from 'x';",572 "export Default,\n { Foo, Bar as Baz,\n Qux as Norf }\n from 'x';",573 "export Default,\n { Foo, Bar as Baz,\n Qux as Norf, }\n from 'x';",574 "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore\n }\n from 'x';",575 "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore,\n }\n from 'x';",576 "export Default\n , { } from 'x';",577 // require578 'require("x")',579 'require("y")',580 'require( \'z\' )',581 'require( "a")',582 'require("b" )',583 ].join('\n');584 /*eslint-disable */585 const module = createModule('test module', ['x', 'y']);586 const resolutionResponse = new ResolutionResponseMock({587 dependencies: [module],588 mainModuleId: 'test module',589 asyncDependencies: [],590 });591 resolutionResponse.getResolvedDependencyPairs = (module) => {592 return [593 ['x', createModule('changed')],594 ['y', createModule('Y')],595 ];596 }597 return depResolver.wrapModule(598 resolutionResponse,599 createModule('test module', ['x', 'y']),600 code601 ).then(processedCode => {602 expect(processedCode.name).toEqual('test module');603 expect(processedCode.code).toEqual([604 '__d(\'test module\',function(global, require,' +605 ' module, exports) { ' +606 // single line import607 "import'x';",608 "import 'changed';",609 "import 'changed' ;",610 "import Default from 'changed';",611 "import * as All from 'changed';",612 "import {} from 'changed';",613 "import { } from 'changed';",614 "import {Foo} from 'changed';",615 "import { Foo } from 'changed';",616 "import { Foo, } from 'changed';",617 "import {Foo as Bar} from 'changed';",618 "import { Foo as Bar } from 'changed';",619 "import { Foo as Bar, } from 'changed';",620 "import { Foo, Bar } from 'changed';",621 "import { Foo, Bar, } from 'changed';",622 "import { Foo as Bar, Baz } from 'changed';",623 "import { Foo as Bar, Baz, } from 'changed';",624 "import { Foo, Bar as Baz } from 'changed';",625 "import { Foo, Bar as Baz, } from 'changed';",626 "import { Foo as Bar, Baz as Qux } from 'changed';",627 "import { Foo as Bar, Baz as Qux, } from 'changed';",628 "import { Foo, Bar, Baz } from 'changed';",629 "import { Foo, Bar, Baz, } from 'changed';",630 "import { Foo as Bar, Baz, Qux } from 'changed';",631 "import { Foo as Bar, Baz, Qux, } from 'changed';",632 "import { Foo, Bar as Baz, Qux } from 'changed';",633 "import { Foo, Bar as Baz, Qux, } from 'changed';",634 "import { Foo, Bar, Baz as Qux } from 'changed';",635 "import { Foo, Bar, Baz as Qux, } from 'changed';",636 "import { Foo as Bar, Baz as Qux, Norf } from 'changed';",637 "import { Foo as Bar, Baz as Qux, Norf, } from 'changed';",638 "import { Foo as Bar, Baz, Qux as Norf } from 'changed';",639 "import { Foo as Bar, Baz, Qux as Norf, } from 'changed';",640 "import { Foo, Bar as Baz, Qux as Norf } from 'changed';",641 "import { Foo, Bar as Baz, Qux as Norf, } from 'changed';",642 "import { Foo as Bar, Baz as Qux, Norf as Enuf } from 'changed';",643 "import { Foo as Bar, Baz as Qux, Norf as Enuf, } from 'changed';",644 "import Default, * as All from 'changed';",645 "import Default, { } from 'changed';",646 "import Default, { Foo } from 'changed';",647 "import Default, { Foo, } from 'changed';",648 "import Default, { Foo as Bar } from 'changed';",649 "import Default, { Foo as Bar, } from 'changed';",650 "import Default, { Foo, Bar } from 'changed';",651 "import Default, { Foo, Bar, } from 'changed';",652 "import Default, { Foo as Bar, Baz } from 'changed';",653 "import Default, { Foo as Bar, Baz, } from 'changed';",654 "import Default, { Foo, Bar as Baz } from 'changed';",655 "import Default, { Foo, Bar as Baz, } from 'changed';",656 "import Default, { Foo as Bar, Baz as Qux } from 'changed';",657 "import Default, { Foo as Bar, Baz as Qux, } from 'changed';",658 "import Default, { Foo, Bar, Baz } from 'changed';",659 "import Default, { Foo, Bar, Baz, } from 'changed';",660 "import Default, { Foo as Bar, Baz, Qux } from 'changed';",661 "import Default, { Foo as Bar, Baz, Qux, } from 'changed';",662 "import Default, { Foo, Bar as Baz, Qux } from 'changed';",663 "import Default, { Foo, Bar as Baz, Qux, } from 'changed';",664 "import Default, { Foo, Bar, Baz as Qux } from 'changed';",665 "import Default, { Foo, Bar, Baz as Qux, } from 'changed';",666 "import Default, { Foo as Bar, Baz as Qux, Norf } from 'changed';",667 "import Default, { Foo as Bar, Baz as Qux, Norf, } from 'changed';",668 "import Default, { Foo as Bar, Baz, Qux as Norf } from 'changed';",669 "import Default, { Foo as Bar, Baz, Qux as Norf, } from 'changed';",670 "import Default, { Foo, Bar as Baz, Qux as Norf } from 'changed';",671 "import Default, { Foo, Bar as Baz, Qux as Norf, } from 'changed';",672 "import Default, { Foo as Bar, Baz as Qux, Norf as NoMore } from 'changed';",673 "import Default, { Foo as Bar, Baz as Qux, Norf as NoMore, } from 'changed';",674 "import Default , { } from 'changed';",675 'import "changed";',676 'import Default from "changed";',677 'import * as All from "changed";',678 'import { } from "changed";',679 'import { Foo } from "changed";',680 'import { Foo, } from "changed";',681 'import { Foo as Bar } from "changed";',682 'import { Foo as Bar, } from "changed";',683 'import { Foo, Bar } from "changed";',684 'import { Foo, Bar, } from "changed";',685 'import { Foo as Bar, Baz } from "changed";',686 'import { Foo as Bar, Baz, } from "changed";',687 'import { Foo, Bar as Baz } from "changed";',688 'import { Foo, Bar as Baz, } from "changed";',689 'import { Foo as Bar, Baz as Qux } from "changed";',690 'import { Foo as Bar, Baz as Qux, } from "changed";',691 'import { Foo, Bar, Baz } from "changed";',692 'import { Foo, Bar, Baz, } from "changed";',693 'import { Foo as Bar, Baz, Qux } from "changed";',694 'import { Foo as Bar, Baz, Qux, } from "changed";',695 'import { Foo, Bar as Baz, Qux } from "changed";',696 'import { Foo, Bar as Baz, Qux, } from "changed";',697 'import { Foo, Bar, Baz as Qux } from "changed";',698 'import { Foo, Bar, Baz as Qux, } from "changed";',699 'import { Foo as Bar, Baz as Qux, Norf } from "changed";',700 'import { Foo as Bar, Baz as Qux, Norf, } from "changed";',701 'import { Foo as Bar, Baz, Qux as Norf } from "changed";',702 'import { Foo as Bar, Baz, Qux as Norf, } from "changed";',703 'import { Foo, Bar as Baz, Qux as Norf } from "changed";',704 'import { Foo, Bar as Baz, Qux as Norf, } from "changed";',705 'import { Foo as Bar, Baz as Qux, Norf as NoMore } from "changed";',706 'import { Foo as Bar, Baz as Qux, Norf as NoMore, } from "changed";',707 'import Default, * as All from "changed";',708 'import Default, { } from "changed";',709 'import Default, { Foo } from "changed";',710 'import Default, { Foo, } from "changed";',711 'import Default, { Foo as Bar } from "changed";',712 'import Default, { Foo as Bar, } from "changed";',713 'import Default, { Foo, Bar } from "changed";',714 'import Default, { Foo, Bar, } from "changed";',715 'import Default, { Foo as Bar, Baz } from "changed";',716 'import Default, { Foo as Bar, Baz, } from "changed";',717 'import Default, { Foo, Bar as Baz } from "changed";',718 'import Default, { Foo, Bar as Baz, } from "changed";',719 'import Default, { Foo as Bar, Baz as Qux } from "changed";',720 'import Default, { Foo as Bar, Baz as Qux, } from "changed";',721 'import Default, { Foo, Bar, Baz } from "changed";',722 'import Default, { Foo, Bar, Baz, } from "changed";',723 'import Default, { Foo as Bar, Baz, Qux } from "changed";',724 'import Default, { Foo as Bar, Baz, Qux, } from "changed";',725 'import Default, { Foo, Bar as Baz, Qux } from "changed";',726 'import Default, { Foo, Bar as Baz, Qux, } from "changed";',727 'import Default, { Foo, Bar, Baz as Qux } from "changed";',728 'import Default, { Foo, Bar, Baz as Qux, } from "changed";',729 'import Default, { Foo as Bar, Baz as Qux, Norf } from "changed";',730 'import Default, { Foo as Bar, Baz as Qux, Norf, } from "changed";',731 'import Default, { Foo as Bar, Baz, Qux as Norf } from "changed";',732 'import Default, { Foo as Bar, Baz, Qux as Norf, } from "changed";',733 'import Default, { Foo, Bar as Baz, Qux as Norf } from "changed";',734 'import Default, { Foo, Bar as Baz, Qux as Norf, } from "changed";',735 'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf } from "changed";',736 'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "changed";',737 'import Default from "Y";',738 'import * as All from \'z\';',739 // import with support for new lines740 "import { Foo,\n Bar }\n from 'changed';",741 "import { \nFoo,\nBar,\n }\n from 'changed';",742 "import { Foo as Bar,\n Baz\n }\n from 'changed';",743 "import { \nFoo as Bar,\n Baz\n, }\n from 'changed';",744 "import { Foo,\n Bar as Baz\n }\n from 'changed';",745 "import { Foo,\n Bar as Baz,\n }\n from 'changed';",746 "import { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",747 "import { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",748 "import { Foo,\n Bar,\n Baz }\n from 'changed';",749 "import { Foo,\n Bar,\n Baz,\n }\n from 'changed';",750 "import { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",751 "import { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",752 "import { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",753 "import { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",754 "import { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",755 "import { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",756 "import { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",757 "import { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",758 "import { Foo as Bar,\n Baz,\n Qux as Norf\n }\n from 'changed';",759 "import { Foo as Bar,\n Baz,\n Qux as Norf,\n }\n from 'changed';",760 "import { Foo,\n Bar as Baz,\n Qux as Norf\n }\n from 'changed';",761 "import { Foo,\n Bar as Baz,\n Qux as Norf,\n }\n from 'changed';",762 "import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf\n }\n from 'changed';",763 "import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf,\n }\n from 'changed';",764 "import Default,\n * as All from 'changed';",765 "import Default,\n { } from 'changed';",766 "import Default,\n { Foo\n }\n from 'changed';",767 "import Default,\n { Foo,\n }\n from 'changed';",768 "import Default,\n { Foo as Bar\n }\n from 'changed';",769 "import Default,\n { Foo as Bar,\n }\n from 'changed';",770 "import Default,\n { Foo,\n Bar\n } from\n 'changed';",771 "import Default,\n { Foo,\n Bar,\n } from\n 'changed';",772 "import Default,\n { Foo as Bar,\n Baz\n }\n from 'changed';",773 "import Default,\n { Foo as Bar,\n Baz,\n }\n from 'changed';",774 "import Default,\n { Foo,\n Bar as Baz\n }\n from 'changed';",775 "import Default,\n { Foo,\n Bar as Baz,\n }\n from 'changed';",776 "import Default,\n { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",777 "import Default,\n { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",778 "import Default,\n { Foo,\n Bar,\n Baz\n }\n from 'changed';",779 "import Default,\n { Foo,\n Bar,\n Baz,\n }\n from 'changed';",780 "import Default,\n { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",781 "import Default,\n { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",782 "import Default,\n { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",783 "import Default,\n { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",784 "import Default,\n { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",785 "import Default,\n { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",786 "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",787 "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",788 "import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf }\n from 'changed';",789 "import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf, }\n from 'changed';",790 "import Default,\n { Foo, Bar as Baz,\n Qux as Norf }\n from 'changed';",791 "import Default,\n { Foo, Bar as Baz,\n Qux as Norf, }\n from 'changed';",792 "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore\n }\n from 'changed';",793 "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore,\n }\n from 'changed';",794 "import Default\n , { } from 'changed';",795 // single line export796 "export'x';",797 "export 'changed';",798 "export 'changed' ;",799 "export Default from 'changed';",800 "export * as All from 'changed';",801 "export {} from 'changed';",802 "export { } from 'changed';",803 "export {Foo} from 'changed';",804 "export { Foo } from 'changed';",805 "export { Foo, } from 'changed';",806 "export {Foo as Bar} from 'changed';",807 "export { Foo as Bar } from 'changed';",808 "export { Foo as Bar, } from 'changed';",809 "export { Foo, Bar } from 'changed';",810 "export { Foo, Bar, } from 'changed';",811 "export { Foo as Bar, Baz } from 'changed';",812 "export { Foo as Bar, Baz, } from 'changed';",813 "export { Foo, Bar as Baz } from 'changed';",814 "export { Foo, Bar as Baz, } from 'changed';",815 "export { Foo as Bar, Baz as Qux } from 'changed';",816 "export { Foo as Bar, Baz as Qux, } from 'changed';",817 "export { Foo, Bar, Baz } from 'changed';",818 "export { Foo, Bar, Baz, } from 'changed';",819 "export { Foo as Bar, Baz, Qux } from 'changed';",820 "export { Foo as Bar, Baz, Qux, } from 'changed';",821 "export { Foo, Bar as Baz, Qux } from 'changed';",822 "export { Foo, Bar as Baz, Qux, } from 'changed';",823 "export { Foo, Bar, Baz as Qux } from 'changed';",824 "export { Foo, Bar, Baz as Qux, } from 'changed';",825 "export { Foo as Bar, Baz as Qux, Norf } from 'changed';",826 "export { Foo as Bar, Baz as Qux, Norf, } from 'changed';",827 "export { Foo as Bar, Baz, Qux as Norf } from 'changed';",828 "export { Foo as Bar, Baz, Qux as Norf, } from 'changed';",829 "export { Foo, Bar as Baz, Qux as Norf } from 'changed';",830 "export { Foo, Bar as Baz, Qux as Norf, } from 'changed';",831 "export { Foo as Bar, Baz as Qux, Norf as Enuf } from 'changed';",832 "export { Foo as Bar, Baz as Qux, Norf as Enuf, } from 'changed';",833 "export Default, * as All from 'changed';",834 "export Default, { } from 'changed';",835 "export Default, { Foo } from 'changed';",836 "export Default, { Foo, } from 'changed';",837 "export Default, { Foo as Bar } from 'changed';",838 "export Default, { Foo as Bar, } from 'changed';",839 "export Default, { Foo, Bar } from 'changed';",840 "export Default, { Foo, Bar, } from 'changed';",841 "export Default, { Foo as Bar, Baz } from 'changed';",842 "export Default, { Foo as Bar, Baz, } from 'changed';",843 "export Default, { Foo, Bar as Baz } from 'changed';",844 "export Default, { Foo, Bar as Baz, } from 'changed';",845 "export Default, { Foo as Bar, Baz as Qux } from 'changed';",846 "export Default, { Foo as Bar, Baz as Qux, } from 'changed';",847 "export Default, { Foo, Bar, Baz } from 'changed';",848 "export Default, { Foo, Bar, Baz, } from 'changed';",849 "export Default, { Foo as Bar, Baz, Qux } from 'changed';",850 "export Default, { Foo as Bar, Baz, Qux, } from 'changed';",851 "export Default, { Foo, Bar as Baz, Qux } from 'changed';",852 "export Default, { Foo, Bar as Baz, Qux, } from 'changed';",853 "export Default, { Foo, Bar, Baz as Qux } from 'changed';",854 "export Default, { Foo, Bar, Baz as Qux, } from 'changed';",855 "export Default, { Foo as Bar, Baz as Qux, Norf } from 'changed';",856 "export Default, { Foo as Bar, Baz as Qux, Norf, } from 'changed';",857 "export Default, { Foo as Bar, Baz, Qux as Norf } from 'changed';",858 "export Default, { Foo as Bar, Baz, Qux as Norf, } from 'changed';",859 "export Default, { Foo, Bar as Baz, Qux as Norf } from 'changed';",860 "export Default, { Foo, Bar as Baz, Qux as Norf, } from 'changed';",861 "export Default, { Foo as Bar, Baz as Qux, Norf as NoMore } from 'changed';",862 "export Default, { Foo as Bar, Baz as Qux, Norf as NoMore, } from 'changed';",863 "export Default , { } from 'changed';",864 'export "changed";',865 'export Default from "changed";',866 'export * as All from "changed";',867 'export { } from "changed";',868 'export { Foo } from "changed";',869 'export { Foo, } from "changed";',870 'export { Foo as Bar } from "changed";',871 'export { Foo as Bar, } from "changed";',872 'export { Foo, Bar } from "changed";',873 'export { Foo, Bar, } from "changed";',874 'export { Foo as Bar, Baz } from "changed";',875 'export { Foo as Bar, Baz, } from "changed";',876 'export { Foo, Bar as Baz } from "changed";',877 'export { Foo, Bar as Baz, } from "changed";',878 'export { Foo as Bar, Baz as Qux } from "changed";',879 'export { Foo as Bar, Baz as Qux, } from "changed";',880 'export { Foo, Bar, Baz } from "changed";',881 'export { Foo, Bar, Baz, } from "changed";',882 'export { Foo as Bar, Baz, Qux } from "changed";',883 'export { Foo as Bar, Baz, Qux, } from "changed";',884 'export { Foo, Bar as Baz, Qux } from "changed";',885 'export { Foo, Bar as Baz, Qux, } from "changed";',886 'export { Foo, Bar, Baz as Qux } from "changed";',887 'export { Foo, Bar, Baz as Qux, } from "changed";',888 'export { Foo as Bar, Baz as Qux, Norf } from "changed";',889 'export { Foo as Bar, Baz as Qux, Norf, } from "changed";',890 'export { Foo as Bar, Baz, Qux as Norf } from "changed";',891 'export { Foo as Bar, Baz, Qux as Norf, } from "changed";',892 'export { Foo, Bar as Baz, Qux as Norf } from "changed";',893 'export { Foo, Bar as Baz, Qux as Norf, } from "changed";',894 'export { Foo as Bar, Baz as Qux, Norf as NoMore } from "changed";',895 'export { Foo as Bar, Baz as Qux, Norf as NoMore, } from "changed";',896 'export Default, * as All from "changed";',897 'export Default, { } from "changed";',898 'export Default, { Foo } from "changed";',899 'export Default, { Foo, } from "changed";',900 'export Default, { Foo as Bar } from "changed";',901 'export Default, { Foo as Bar, } from "changed";',902 'export Default, { Foo, Bar } from "changed";',903 'export Default, { Foo, Bar, } from "changed";',904 'export Default, { Foo as Bar, Baz } from "changed";',905 'export Default, { Foo as Bar, Baz, } from "changed";',906 'export Default, { Foo, Bar as Baz } from "changed";',907 'export Default, { Foo, Bar as Baz, } from "changed";',908 'export Default, { Foo as Bar, Baz as Qux } from "changed";',909 'export Default, { Foo as Bar, Baz as Qux, } from "changed";',910 'export Default, { Foo, Bar, Baz } from "changed";',911 'export Default, { Foo, Bar, Baz, } from "changed";',912 'export Default, { Foo as Bar, Baz, Qux } from "changed";',913 'export Default, { Foo as Bar, Baz, Qux, } from "changed";',914 'export Default, { Foo, Bar as Baz, Qux } from "changed";',915 'export Default, { Foo, Bar as Baz, Qux, } from "changed";',916 'export Default, { Foo, Bar, Baz as Qux } from "changed";',917 'export Default, { Foo, Bar, Baz as Qux, } from "changed";',918 'export Default, { Foo as Bar, Baz as Qux, Norf } from "changed";',919 'export Default, { Foo as Bar, Baz as Qux, Norf, } from "changed";',920 'export Default, { Foo as Bar, Baz, Qux as Norf } from "changed";',921 'export Default, { Foo as Bar, Baz, Qux as Norf, } from "changed";',922 'export Default, { Foo, Bar as Baz, Qux as Norf } from "changed";',923 'export Default, { Foo, Bar as Baz, Qux as Norf, } from "changed";',924 'export Default, { Foo as Bar, Baz as Qux, Norf as Enuf } from "changed";',925 'export Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "changed";',926 'export Default from "Y";',927 'export * as All from \'z\';',928 // export with support for new lines929 "export { Foo,\n Bar }\n from 'changed';",930 "export { \nFoo,\nBar,\n }\n from 'changed';",931 "export { Foo as Bar,\n Baz\n }\n from 'changed';",932 "export { \nFoo as Bar,\n Baz\n, }\n from 'changed';",933 "export { Foo,\n Bar as Baz\n }\n from 'changed';",934 "export { Foo,\n Bar as Baz,\n }\n from 'changed';",935 "export { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",936 "export { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",937 "export { Foo,\n Bar,\n Baz }\n from 'changed';",938 "export { Foo,\n Bar,\n Baz,\n }\n from 'changed';",939 "export { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",940 "export { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",941 "export { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",942 "export { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",943 "export { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",944 "export { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",945 "export { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",946 "export { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",947 "export { Foo as Bar,\n Baz,\n Qux as Norf\n }\n from 'changed';",948 "export { Foo as Bar,\n Baz,\n Qux as Norf,\n }\n from 'changed';",949 "export { Foo,\n Bar as Baz,\n Qux as Norf\n }\n from 'changed';",950 "export { Foo,\n Bar as Baz,\n Qux as Norf,\n }\n from 'changed';",951 "export { Foo as Bar,\n Baz as Qux,\n Norf as Enuf\n }\n from 'changed';",952 "export { Foo as Bar,\n Baz as Qux,\n Norf as Enuf,\n }\n from 'changed';",953 "export Default,\n * as All from 'changed';",954 "export Default,\n { } from 'changed';",955 "export Default,\n { Foo\n }\n from 'changed';",956 "export Default,\n { Foo,\n }\n from 'changed';",957 "export Default,\n { Foo as Bar\n }\n from 'changed';",958 "export Default,\n { Foo as Bar,\n }\n from 'changed';",959 "export Default,\n { Foo,\n Bar\n } from\n 'changed';",960 "export Default,\n { Foo,\n Bar,\n } from\n 'changed';",961 "export Default,\n { Foo as Bar,\n Baz\n }\n from 'changed';",962 "export Default,\n { Foo as Bar,\n Baz,\n }\n from 'changed';",963 "export Default,\n { Foo,\n Bar as Baz\n }\n from 'changed';",964 "export Default,\n { Foo,\n Bar as Baz,\n }\n from 'changed';",965 "export Default,\n { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",966 "export Default,\n { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",967 "export Default,\n { Foo,\n Bar,\n Baz\n }\n from 'changed';",968 "export Default,\n { Foo,\n Bar,\n Baz,\n }\n from 'changed';",969 "export Default,\n { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",970 "export Default,\n { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",971 "export Default,\n { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",972 "export Default,\n { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",973 "export Default,\n { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",974 "export Default,\n { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",975 "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",976 "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",977 "export Default,\n { Foo as Bar,\n Baz,\n Qux as Norf }\n from 'changed';",978 "export Default,\n { Foo as Bar,\n Baz,\n Qux as Norf, }\n from 'changed';",979 "export Default,\n { Foo, Bar as Baz,\n Qux as Norf }\n from 'changed';",980 "export Default,\n { Foo, Bar as Baz,\n Qux as Norf, }\n from 'changed';",981 "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore\n }\n from 'changed';",982 "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore,\n }\n from 'changed';",983 "export Default\n , { } from 'changed';",984 // require985 'require("changed")',986 'require("Y")',987 'require( \'z\' )',988 'require( "a")',989 'require("b" )',990 '});',991 ].join('\n'));992 });993 });994 });...
test_context.py
Source:test_context.py
1# This Source Code Form is subject to the terms of the Mozilla Public2# License, v. 2.0. If a copy of the MPL was not distributed with this3# file, You can obtain one at http://mozilla.org/MPL/2.0/.4from __future__ import absolute_import, print_function, unicode_literals5import os6import six7import unittest8from mozunit import main9from mozbuild.frontend.context import (10 AbsolutePath,11 Context,12 ContextDerivedTypedHierarchicalStringList,13 ContextDerivedTypedList,14 ContextDerivedTypedListWithItems,15 ContextDerivedTypedRecord,16 Files,17 FUNCTIONS,18 ObjDirPath,19 Path,20 SourcePath,21 SPECIAL_VARIABLES,22 SUBCONTEXTS,23 VARIABLES,24)25from mozbuild.util import StrictOrderingOnAppendListWithFlagsFactory26from mozpack import path as mozpath27class TestContext(unittest.TestCase):28 def test_defaults(self):29 test = Context(30 {31 "foo": (int, int, ""),32 "bar": (bool, bool, ""),33 "baz": (dict, dict, ""),34 }35 )36 self.assertEqual(list(test), [])37 self.assertEqual(test["foo"], 0)38 self.assertEqual(set(test.keys()), {"foo"})39 self.assertEqual(test["bar"], False)40 self.assertEqual(set(test.keys()), {"foo", "bar"})41 self.assertEqual(test["baz"], {})42 self.assertEqual(set(test.keys()), {"foo", "bar", "baz"})43 with self.assertRaises(KeyError):44 test["qux"]45 self.assertEqual(set(test.keys()), {"foo", "bar", "baz"})46 def test_type_check(self):47 test = Context(48 {49 "foo": (int, int, ""),50 "baz": (dict, list, ""),51 }52 )53 test["foo"] = 554 self.assertEqual(test["foo"], 5)55 with self.assertRaises(ValueError):56 test["foo"] = {}57 self.assertEqual(test["foo"], 5)58 with self.assertRaises(KeyError):59 test["bar"] = True60 test["baz"] = [("a", 1), ("b", 2)]61 self.assertEqual(test["baz"], {"a": 1, "b": 2})62 def test_update(self):63 test = Context(64 {65 "foo": (int, int, ""),66 "bar": (bool, bool, ""),67 "baz": (dict, list, ""),68 }69 )70 self.assertEqual(list(test), [])71 with self.assertRaises(ValueError):72 test.update(bar=True, foo={})73 self.assertEqual(list(test), [])74 test.update(bar=True, foo=1)75 self.assertEqual(set(test.keys()), {"foo", "bar"})76 self.assertEqual(test["foo"], 1)77 self.assertEqual(test["bar"], True)78 test.update([("bar", False), ("foo", 2)])79 self.assertEqual(test["foo"], 2)80 self.assertEqual(test["bar"], False)81 test.update([("foo", 0), ("baz", {"a": 1, "b": 2})])82 self.assertEqual(test["foo"], 0)83 self.assertEqual(test["baz"], {"a": 1, "b": 2})84 test.update([("foo", 42), ("baz", [("c", 3), ("d", 4)])])85 self.assertEqual(test["foo"], 42)86 self.assertEqual(test["baz"], {"c": 3, "d": 4})87 def test_context_paths(self):88 test = Context()89 # Newly created context has no paths.90 self.assertIsNone(test.main_path)91 self.assertIsNone(test.current_path)92 self.assertEqual(test.all_paths, set())93 self.assertEqual(test.source_stack, [])94 foo = os.path.abspath("foo")95 test.add_source(foo)96 # Adding the first source makes it the main and current path.97 self.assertEqual(test.main_path, foo)98 self.assertEqual(test.current_path, foo)99 self.assertEqual(test.all_paths, set([foo]))100 self.assertEqual(test.source_stack, [foo])101 bar = os.path.abspath("bar")102 test.add_source(bar)103 # Adding the second source makes leaves main and current paths alone.104 self.assertEqual(test.main_path, foo)105 self.assertEqual(test.current_path, foo)106 self.assertEqual(test.all_paths, set([bar, foo]))107 self.assertEqual(test.source_stack, [foo])108 qux = os.path.abspath("qux")109 test.push_source(qux)110 # Pushing a source makes it the current path111 self.assertEqual(test.main_path, foo)112 self.assertEqual(test.current_path, qux)113 self.assertEqual(test.all_paths, set([bar, foo, qux]))114 self.assertEqual(test.source_stack, [foo, qux])115 hoge = os.path.abspath("hoge")116 test.push_source(hoge)117 self.assertEqual(test.main_path, foo)118 self.assertEqual(test.current_path, hoge)119 self.assertEqual(test.all_paths, set([bar, foo, hoge, qux]))120 self.assertEqual(test.source_stack, [foo, qux, hoge])121 fuga = os.path.abspath("fuga")122 # Adding a source after pushing doesn't change the source stack123 test.add_source(fuga)124 self.assertEqual(test.main_path, foo)125 self.assertEqual(test.current_path, hoge)126 self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))127 self.assertEqual(test.source_stack, [foo, qux, hoge])128 # Adding a source twice doesn't change anything129 test.add_source(qux)130 self.assertEqual(test.main_path, foo)131 self.assertEqual(test.current_path, hoge)132 self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))133 self.assertEqual(test.source_stack, [foo, qux, hoge])134 last = test.pop_source()135 # Popping a source returns the last pushed one, not the last added one.136 self.assertEqual(last, hoge)137 self.assertEqual(test.main_path, foo)138 self.assertEqual(test.current_path, qux)139 self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))140 self.assertEqual(test.source_stack, [foo, qux])141 last = test.pop_source()142 self.assertEqual(last, qux)143 self.assertEqual(test.main_path, foo)144 self.assertEqual(test.current_path, foo)145 self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))146 self.assertEqual(test.source_stack, [foo])147 # Popping the main path is allowed.148 last = test.pop_source()149 self.assertEqual(last, foo)150 self.assertEqual(test.main_path, foo)151 self.assertIsNone(test.current_path)152 self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))153 self.assertEqual(test.source_stack, [])154 # Popping past the main path asserts.155 with self.assertRaises(AssertionError):156 test.pop_source()157 # Pushing after the main path was popped asserts.158 with self.assertRaises(AssertionError):159 test.push_source(foo)160 test = Context()161 test.push_source(foo)162 test.push_source(bar)163 # Pushing the same file twice is allowed.164 test.push_source(bar)165 test.push_source(foo)166 self.assertEqual(last, foo)167 self.assertEqual(test.main_path, foo)168 self.assertEqual(test.current_path, foo)169 self.assertEqual(test.all_paths, set([bar, foo]))170 self.assertEqual(test.source_stack, [foo, bar, bar, foo])171 def test_context_dirs(self):172 class Config(object):173 pass174 config = Config()175 config.topsrcdir = mozpath.abspath(os.curdir)176 config.topobjdir = mozpath.abspath("obj")177 test = Context(config=config)178 foo = mozpath.abspath("foo")179 test.push_source(foo)180 self.assertEqual(test.srcdir, config.topsrcdir)181 self.assertEqual(test.relsrcdir, "")182 self.assertEqual(test.objdir, config.topobjdir)183 self.assertEqual(test.relobjdir, "")184 foobar = os.path.abspath("foo/bar")185 test.push_source(foobar)186 self.assertEqual(test.srcdir, mozpath.join(config.topsrcdir, "foo"))187 self.assertEqual(test.relsrcdir, "foo")188 self.assertEqual(test.objdir, config.topobjdir)189 self.assertEqual(test.relobjdir, "")190class TestSymbols(unittest.TestCase):191 def _verify_doc(self, doc):192 # Documentation should be of the format:193 # """SUMMARY LINE194 #195 # EXTRA PARAGRAPHS196 # """197 self.assertNotIn("\r", doc)198 lines = doc.split("\n")199 # No trailing whitespace.200 for line in lines[0:-1]:201 self.assertEqual(line, line.rstrip())202 self.assertGreater(len(lines), 0)203 self.assertGreater(len(lines[0].strip()), 0)204 # Last line should be empty.205 self.assertEqual(lines[-1].strip(), "")206 def test_documentation_formatting(self):207 for typ, inp, doc in VARIABLES.values():208 self._verify_doc(doc)209 for attr, args, doc in FUNCTIONS.values():210 self._verify_doc(doc)211 for func, typ, doc in SPECIAL_VARIABLES.values():212 self._verify_doc(doc)213 for name, cls in SUBCONTEXTS.items():214 self._verify_doc(cls.__doc__)215 for name, v in cls.VARIABLES.items():216 self._verify_doc(v[2])217class TestPaths(unittest.TestCase):218 @classmethod219 def setUpClass(cls):220 class Config(object):221 pass222 cls.config = config = Config()223 config.topsrcdir = mozpath.abspath(os.curdir)224 config.topobjdir = mozpath.abspath("obj")225 def test_path(self):226 config = self.config227 ctxt1 = Context(config=config)228 ctxt1.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))229 ctxt2 = Context(config=config)230 ctxt2.push_source(mozpath.join(config.topsrcdir, "bar", "moz.build"))231 path1 = Path(ctxt1, "qux")232 self.assertIsInstance(path1, SourcePath)233 self.assertEqual(path1, "qux")234 self.assertEqual(path1.full_path, mozpath.join(config.topsrcdir, "foo", "qux"))235 path2 = Path(ctxt2, "../foo/qux")236 self.assertIsInstance(path2, SourcePath)237 self.assertEqual(path2, "../foo/qux")238 self.assertEqual(path2.full_path, mozpath.join(config.topsrcdir, "foo", "qux"))239 self.assertEqual(path1, path2)240 self.assertEqual(241 path1.join("../../bar/qux").full_path,242 mozpath.join(config.topsrcdir, "bar", "qux"),243 )244 path1 = Path(ctxt1, "/qux/qux")245 self.assertIsInstance(path1, SourcePath)246 self.assertEqual(path1, "/qux/qux")247 self.assertEqual(path1.full_path, mozpath.join(config.topsrcdir, "qux", "qux"))248 path2 = Path(ctxt2, "/qux/qux")249 self.assertIsInstance(path2, SourcePath)250 self.assertEqual(path2, "/qux/qux")251 self.assertEqual(path2.full_path, mozpath.join(config.topsrcdir, "qux", "qux"))252 self.assertEqual(path1, path2)253 path1 = Path(ctxt1, "!qux")254 self.assertIsInstance(path1, ObjDirPath)255 self.assertEqual(path1, "!qux")256 self.assertEqual(path1.full_path, mozpath.join(config.topobjdir, "foo", "qux"))257 path2 = Path(ctxt2, "!../foo/qux")258 self.assertIsInstance(path2, ObjDirPath)259 self.assertEqual(path2, "!../foo/qux")260 self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "foo", "qux"))261 self.assertEqual(path1, path2)262 path1 = Path(ctxt1, "!/qux/qux")263 self.assertIsInstance(path1, ObjDirPath)264 self.assertEqual(path1, "!/qux/qux")265 self.assertEqual(path1.full_path, mozpath.join(config.topobjdir, "qux", "qux"))266 path2 = Path(ctxt2, "!/qux/qux")267 self.assertIsInstance(path2, ObjDirPath)268 self.assertEqual(path2, "!/qux/qux")269 self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "qux", "qux"))270 self.assertEqual(path1, path2)271 path1 = Path(ctxt1, path1)272 self.assertIsInstance(path1, ObjDirPath)273 self.assertEqual(path1, "!/qux/qux")274 self.assertEqual(path1.full_path, mozpath.join(config.topobjdir, "qux", "qux"))275 path2 = Path(ctxt2, path2)276 self.assertIsInstance(path2, ObjDirPath)277 self.assertEqual(path2, "!/qux/qux")278 self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "qux", "qux"))279 self.assertEqual(path1, path2)280 path1 = Path(path1)281 self.assertIsInstance(path1, ObjDirPath)282 self.assertEqual(path1, "!/qux/qux")283 self.assertEqual(path1.full_path, mozpath.join(config.topobjdir, "qux", "qux"))284 self.assertEqual(path1, path2)285 path2 = Path(path2)286 self.assertIsInstance(path2, ObjDirPath)287 self.assertEqual(path2, "!/qux/qux")288 self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "qux", "qux"))289 self.assertEqual(path1, path2)290 def test_source_path(self):291 config = self.config292 ctxt = Context(config=config)293 ctxt.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))294 path = SourcePath(ctxt, "qux")295 self.assertEqual(path, "qux")296 self.assertEqual(path.full_path, mozpath.join(config.topsrcdir, "foo", "qux"))297 self.assertEqual(path.translated, mozpath.join(config.topobjdir, "foo", "qux"))298 path = SourcePath(ctxt, "../bar/qux")299 self.assertEqual(path, "../bar/qux")300 self.assertEqual(path.full_path, mozpath.join(config.topsrcdir, "bar", "qux"))301 self.assertEqual(path.translated, mozpath.join(config.topobjdir, "bar", "qux"))302 path = SourcePath(ctxt, "/qux/qux")303 self.assertEqual(path, "/qux/qux")304 self.assertEqual(path.full_path, mozpath.join(config.topsrcdir, "qux", "qux"))305 self.assertEqual(path.translated, mozpath.join(config.topobjdir, "qux", "qux"))306 with self.assertRaises(ValueError):307 SourcePath(ctxt, "!../bar/qux")308 with self.assertRaises(ValueError):309 SourcePath(ctxt, "!/qux/qux")310 path = SourcePath(path)311 self.assertIsInstance(path, SourcePath)312 self.assertEqual(path, "/qux/qux")313 self.assertEqual(path.full_path, mozpath.join(config.topsrcdir, "qux", "qux"))314 self.assertEqual(path.translated, mozpath.join(config.topobjdir, "qux", "qux"))315 path = Path(path)316 self.assertIsInstance(path, SourcePath)317 def test_objdir_path(self):318 config = self.config319 ctxt = Context(config=config)320 ctxt.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))321 path = ObjDirPath(ctxt, "!qux")322 self.assertEqual(path, "!qux")323 self.assertEqual(path.full_path, mozpath.join(config.topobjdir, "foo", "qux"))324 path = ObjDirPath(ctxt, "!../bar/qux")325 self.assertEqual(path, "!../bar/qux")326 self.assertEqual(path.full_path, mozpath.join(config.topobjdir, "bar", "qux"))327 path = ObjDirPath(ctxt, "!/qux/qux")328 self.assertEqual(path, "!/qux/qux")329 self.assertEqual(path.full_path, mozpath.join(config.topobjdir, "qux", "qux"))330 with self.assertRaises(ValueError):331 path = ObjDirPath(ctxt, "../bar/qux")332 with self.assertRaises(ValueError):333 path = ObjDirPath(ctxt, "/qux/qux")334 path = ObjDirPath(path)335 self.assertIsInstance(path, ObjDirPath)336 self.assertEqual(path, "!/qux/qux")337 self.assertEqual(path.full_path, mozpath.join(config.topobjdir, "qux", "qux"))338 path = Path(path)339 self.assertIsInstance(path, ObjDirPath)340 def test_absolute_path(self):341 config = self.config342 ctxt = Context(config=config)343 ctxt.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))344 path = AbsolutePath(ctxt, "%/qux")345 self.assertEqual(path, "%/qux")346 self.assertEqual(path.full_path, "/qux")347 with self.assertRaises(ValueError):348 path = AbsolutePath(ctxt, "%qux")349 def test_path_with_mixed_contexts(self):350 config = self.config351 ctxt1 = Context(config=config)352 ctxt1.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))353 ctxt2 = Context(config=config)354 ctxt2.push_source(mozpath.join(config.topsrcdir, "bar", "moz.build"))355 path1 = Path(ctxt1, "qux")356 path2 = Path(ctxt2, path1)357 self.assertEqual(path2, path1)358 self.assertEqual(path2, "qux")359 self.assertEqual(path2.context, ctxt1)360 self.assertEqual(path2.full_path, mozpath.join(config.topsrcdir, "foo", "qux"))361 path1 = Path(ctxt1, "../bar/qux")362 path2 = Path(ctxt2, path1)363 self.assertEqual(path2, path1)364 self.assertEqual(path2, "../bar/qux")365 self.assertEqual(path2.context, ctxt1)366 self.assertEqual(path2.full_path, mozpath.join(config.topsrcdir, "bar", "qux"))367 path1 = Path(ctxt1, "/qux/qux")368 path2 = Path(ctxt2, path1)369 self.assertEqual(path2, path1)370 self.assertEqual(path2, "/qux/qux")371 self.assertEqual(path2.context, ctxt1)372 self.assertEqual(path2.full_path, mozpath.join(config.topsrcdir, "qux", "qux"))373 path1 = Path(ctxt1, "!qux")374 path2 = Path(ctxt2, path1)375 self.assertEqual(path2, path1)376 self.assertEqual(path2, "!qux")377 self.assertEqual(path2.context, ctxt1)378 self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "foo", "qux"))379 path1 = Path(ctxt1, "!../bar/qux")380 path2 = Path(ctxt2, path1)381 self.assertEqual(path2, path1)382 self.assertEqual(path2, "!../bar/qux")383 self.assertEqual(path2.context, ctxt1)384 self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "bar", "qux"))385 path1 = Path(ctxt1, "!/qux/qux")386 path2 = Path(ctxt2, path1)387 self.assertEqual(path2, path1)388 self.assertEqual(path2, "!/qux/qux")389 self.assertEqual(path2.context, ctxt1)390 self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "qux", "qux"))391 def test_path_typed_list(self):392 config = self.config393 ctxt1 = Context(config=config)394 ctxt1.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))395 ctxt2 = Context(config=config)396 ctxt2.push_source(mozpath.join(config.topsrcdir, "bar", "moz.build"))397 paths = [398 "!../bar/qux",399 "!/qux/qux",400 "!qux",401 "../bar/qux",402 "/qux/qux",403 "qux",404 ]405 MyList = ContextDerivedTypedList(Path)406 l = MyList(ctxt1)407 l += paths408 for p_str, p_path in zip(paths, l):409 self.assertEqual(p_str, p_path)410 self.assertEqual(p_path, Path(ctxt1, p_str))411 self.assertEqual(412 p_path.join("foo"), Path(ctxt1, mozpath.join(p_str, "foo"))413 )414 l2 = MyList(ctxt2)415 l2 += paths416 for p_str, p_path in zip(paths, l2):417 self.assertEqual(p_str, p_path)418 self.assertEqual(p_path, Path(ctxt2, p_str))419 # Assigning with Paths from another context doesn't rebase them420 l2 = MyList(ctxt2)421 l2 += l422 for p_str, p_path in zip(paths, l2):423 self.assertEqual(p_str, p_path)424 self.assertEqual(p_path, Path(ctxt1, p_str))425 MyListWithFlags = ContextDerivedTypedListWithItems(426 Path,427 StrictOrderingOnAppendListWithFlagsFactory(428 {429 "foo": bool,430 }431 ),432 )433 l = MyListWithFlags(ctxt1)434 l += paths435 for p in paths:436 l[p].foo = True437 for p_str, p_path in zip(paths, l):438 self.assertEqual(p_str, p_path)439 self.assertEqual(p_path, Path(ctxt1, p_str))440 self.assertEqual(l[p_str].foo, True)441 self.assertEqual(l[p_path].foo, True)442 def test_path_typed_hierarchy_list(self):443 config = self.config444 ctxt1 = Context(config=config)445 ctxt1.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))446 ctxt2 = Context(config=config)447 ctxt2.push_source(mozpath.join(config.topsrcdir, "bar", "moz.build"))448 paths = [449 "!../bar/qux",450 "!/qux/qux",451 "!qux",452 "../bar/qux",453 "/qux/qux",454 "qux",455 ]456 MyList = ContextDerivedTypedHierarchicalStringList(Path)457 l = MyList(ctxt1)458 l += paths459 l.subdir += paths460 for _, files in l.walk():461 for p_str, p_path in zip(paths, files):462 self.assertEqual(p_str, p_path)463 self.assertEqual(p_path, Path(ctxt1, p_str))464 self.assertEqual(465 p_path.join("foo"), Path(ctxt1, mozpath.join(p_str, "foo"))466 )467 l2 = MyList(ctxt2)468 l2 += paths469 l2.subdir += paths470 for _, files in l2.walk():471 for p_str, p_path in zip(paths, files):472 self.assertEqual(p_str, p_path)473 self.assertEqual(p_path, Path(ctxt2, p_str))474 # Assigning with Paths from another context doesn't rebase them475 l2 = MyList(ctxt2)476 l2 += l477 for _, files in l2.walk():478 for p_str, p_path in zip(paths, files):479 self.assertEqual(p_str, p_path)480 self.assertEqual(p_path, Path(ctxt1, p_str))481class TestTypedRecord(unittest.TestCase):482 def test_fields(self):483 T = ContextDerivedTypedRecord(("field1", six.text_type), ("field2", list))484 inst = T(None)485 self.assertEqual(inst.field1, "")486 self.assertEqual(inst.field2, [])487 inst.field1 = "foo"488 inst.field2 += ["bar"]489 self.assertEqual(inst.field1, "foo")490 self.assertEqual(inst.field2, ["bar"])491 with self.assertRaises(AttributeError):492 inst.field3 = []493 def test_coercion(self):494 T = ContextDerivedTypedRecord(("field1", six.text_type), ("field2", list))495 inst = T(None)496 inst.field1 = 3497 inst.field2 += ("bar",)498 self.assertEqual(inst.field1, "3")499 self.assertEqual(inst.field2, ["bar"])500 with self.assertRaises(TypeError):501 inst.field2 = object()502class TestFiles(unittest.TestCase):503 def test_aggregate_empty(self):504 c = Context({})505 files = {"moz.build": Files(c, "**")}506 self.assertEqual(507 Files.aggregate(files),508 {509 "bug_component_counts": [],510 "recommended_bug_component": None,511 },512 )513 def test_single_bug_component(self):514 c = Context({})515 f = Files(c, "**")516 f["BUG_COMPONENT"] = ("Product1", "Component1")517 files = {"moz.build": f}518 self.assertEqual(519 Files.aggregate(files),520 {521 "bug_component_counts": [(("Product1", "Component1"), 1)],522 "recommended_bug_component": ("Product1", "Component1"),523 },524 )525 def test_multiple_bug_components(self):526 c = Context({})527 f1 = Files(c, "**")528 f1["BUG_COMPONENT"] = ("Product1", "Component1")529 f2 = Files(c, "**")530 f2["BUG_COMPONENT"] = ("Product2", "Component2")531 files = {"a": f1, "b": f2, "c": f1}532 self.assertEqual(533 Files.aggregate(files),534 {535 "bug_component_counts": [536 (("Product1", "Component1"), 2),537 (("Product2", "Component2"), 1),538 ],539 "recommended_bug_component": ("Product1", "Component1"),540 },541 )542 def test_no_recommended_bug_component(self):543 """If there is no clear count winner, we don't recommend a bug component."""544 c = Context({})545 f1 = Files(c, "**")546 f1["BUG_COMPONENT"] = ("Product1", "Component1")547 f2 = Files(c, "**")548 f2["BUG_COMPONENT"] = ("Product2", "Component2")549 files = {"a": f1, "b": f2}550 self.assertEqual(551 Files.aggregate(files),552 {553 "bug_component_counts": [554 (("Product1", "Component1"), 1),555 (("Product2", "Component2"), 1),556 ],557 "recommended_bug_component": None,558 },559 )560 def test_multiple_patterns(self):561 c = Context({})562 f1 = Files(c, "a/**")563 f1["BUG_COMPONENT"] = ("Product1", "Component1")564 f2 = Files(c, "b/**", "a/bar")565 f2["BUG_COMPONENT"] = ("Product2", "Component2")566 files = {"a/foo": f1, "a/bar": f2, "b/foo": f2}567 self.assertEqual(568 Files.aggregate(files),569 {570 "bug_component_counts": [571 (("Product2", "Component2"), 2),572 (("Product1", "Component1"), 1),573 ],574 "recommended_bug_component": ("Product2", "Component2"),575 },576 )577if __name__ == "__main__":...
define_test.ts
Source:define_test.ts
1import {describe, it} from 'mocha';2import {expect} from 'chai';3import {Define} from '../../src/js/asm/define';4import {Token} from '../../src/js/asm/token';5import {Tokenizer} from '../../src/js/asm/tokenizer';6import * as util from 'util';7const [] = [util];8//const value = require('../dist/js/asm/value.js');9describe('Define', function() {10 function testExpand(define: string, input: string, output: string,11 extra?: string) {12 const defTok = tok(define);13 const defName = defTok[1] || expect.fail('no name');14 const def = Define.from(defTok);15 const tokens = tok(input);16 // TODO - handle this better...17 let found = -1;18 for (let i = 0; i < tokens.length; i++) {19 if (Token.eq(defName, tokens[i])) {20 found = i;21 break;22 }23 }24 expect(found).to.not.equal(-1);25 const overflow = def.expand(tokens, found);26 expect(overflow).to.be.ok;27 expect(tokens.map(strip)).to.eql(tok(output));28 expect(overflow!.map(ts => ts.map(strip))).to.eql(extra ? toks(extra) : []);29 }30 describe('with no parameters', function() {31 it('should expand in place', function() {32 testExpand('.define foo .bar baz',33 'qux foo bar',34 'qux .bar baz bar');35 });36 });37 describe('with unary C-style argument list', function() {38 it('should expand correctly when called without parens', function() {39 testExpand('.define foo(baz) .bar baz baz',40 'qux foo bar',41 'qux .bar bar bar');42 });43 it('should expand correctly when called with parens', function() {44 testExpand('.define foo(baz) .bar baz baz',45 'qux foo(bar)',46 'qux .bar bar bar');47 });48 it('should expand correctly when called with braces', function() {49 testExpand('.define foo(baz) .bar baz baz',50 'qux foo {bar}',51 'qux .bar bar bar');52 });53 it('should expand correctly when called with ({})', function() {54 testExpand('.define foo(baz) .bar baz baz',55 'qux foo({bar})',56 'qux .bar bar bar');57 });58 });59 describe('with n-ary C-style parameter list', function() {60 it('should expand correctly when called withut parens', function() {61 testExpand('.define foo(a, b, c) 1 a 2 b 3 c 4',62 'qux foo x, y, z',63 'qux 1 x 2 y 3 z 4');64 });65 it('should expand correctly with blanks in the middle', function() {66 testExpand('.define foo(a, b, c) 1 a 2 b 3 c 4',67 'qux foo , , z',68 'qux 1 2 3 z 4');69 });70 it('should expand correctly with one blank at the end', function() {71 testExpand('.define foo(a, b, c) 1 a 2 b 3 c 4',72 'qux foo x, y',73 'qux 1 x 2 y 3 4');74 });75 it('should expand correctly with two blanks at the end', function() {76 testExpand('.define foo(a, b, c) 1 a 2 b 3 c 4',77 'qux foo x',78 'qux 1 x 2 3 4');79 });80 it('should expand correctly with no parameters given', function() {81 testExpand('.define foo(a, b, c) 1 a 2 b 3 c 4',82 'qux foo',83 'qux 1 2 3 4');84 });85 it('should glob to end of line on last parameter', function() {86 testExpand('.define foo(a, b, c) 1 a 2 b 3 c 4',87 'qux foo a b c d e, f g h i j, k l m n o',88 'qux 1 a b c d e 2 f g h i j 3 k l m n o 4');89 });90 it('should expand a parenthesized call site', function() {91 testExpand('.define foo(a, b, c) 1 a 2 b 3 c 4',92 'qux foo(x, y yy, z) w',93 'qux 1 x 2 y yy 3 z 4 w');94 });95 it('should pass through braces in call-site', function() {96 testExpand('.define foo(a, b, c) 1 a 2 b 3 c 4',97 'qux foo x, {y )}, {z}',98 'qux 1 x 2 y ) 3 z 4');99 });100 it('should pass through braces in parenthesized call site', function() {101 testExpand('.define foo(a, b, c) 1 a 2 b 3 c 4',102 'qux foo({x}, {y )}, {z})',103 'qux 1 x 2 y ) 3 z 4');104 });105 it('should expand to end of line', function() {106 testExpand('.define foo(a, b, c) 1 a 2 b 3 c 4',107 'qux foo {x}, {y )}, {z} w',108 'qux 1 x 2 y ) 3 {z} w 4');109 });110 it('should not retain a pair of braces in a single arg', function() {111 testExpand('.define foo(a, b) [a:b]',112 'foo({1}{2}, 3)',113 '[{1}{2} : 3]');114 });115 it('should retain non-single-group braces', function() {116 testExpand('.define foo(a, b) [a:b]',117 'foo({1} 2, 3)',118 '[{1} 2 : 3]');119 testExpand('.define foo(a, b) [a:b]',120 'foo {1} 2, 3',121 '[{1} 2 : 3]'); 122 testExpand('.define foo(a, b) [a:b]',123 'foo(1, {2} 3)',124 '[1 : {2} 3]'); 125 });126 it('should fail on parenthesized calls with too many args', function() {127 const define = Define.from(tok('.define foo(a, b) [a:b]'));128 expect(define.expand(tok('foo(1, 2, 3)'), 0)).to.not.be.ok;129 });130 // TODO - is it possible to make an invalid call???131 // TODO - junk at end of line?132 });133 // optional parens134 // skipping args implicitly135 // extra braces136 // don't inspect stray groups for delimiters137 // (e.g. (\a,b)(1 {2, 3}, 4) => a=1 {2, 3} b=4138 describe('with TeX-style argument list', function() {139 it('should capture empty last argument', function() {140 testExpand('.define foo {a b c .eol} [a:b:c]',141 'qux foo bar baz',142 'qux [bar:baz:]');143 });144 it('should fail on empty undelimited argument', function() {145 const define = Define.from(tok('.define foo {a b} [a:b]'));146 expect(define.expand(tok('foo bar'), 0)).to.not.be.ok; 147 });148 it('should fail on missing delimiter', function() {149 const define = Define.from(tok('.define foo {a,b} [a:b]'));150 expect(define.expand(tok('foo bar baz qux'), 0)).to.not.be.ok; 151 });152 it('should capture entire group for undelimited arg', function() {153 testExpand('.define foo {a b c} [a:b:c]',154 'qux foo {bar baz} qux corge',155 'qux [bar baz:qux:corge]');156 });157 it('should capture entire group for undelimited arg', function() {158 testExpand('.define foo {a b c} [a:b:c]',159 'qux foo {bar baz} qux corge',160 'qux [bar baz:qux:corge]');161 });162 it('should capture delimited arg', function() {163 testExpand('.define foo {a,b,c} [a:b:c]',164 'qux foo bar baz, qux, corge',165 'qux [bar baz:qux:corge]');166 });167 it('should retain braces for delimited arg', function() {168 testExpand('.define foo {a,b,c} [a:b:c]',169 'qux foo {bar baz}, qux, corge',170 'qux [{bar baz}:qux:corge]');171 });172 it('should skip param delimiter in braces', function() {173 testExpand('.define foo {a,b,c} [a:b:c]',174 'qux foo {bar, baz}, qux, corge',175 'qux [{bar, baz}:qux:corge]');176 });177 it('should not gobble to end of line if delimited at end', function() {178 testExpand('.define foo {a,b,c,} [a:b:c]',179 'qux foo bar, baz, qux, corge',180 'qux [bar:baz:qux] corge');181 });182 it('should allow arbitrary tokens as delimiters', function() {183 testExpand('.define foo {a .d b 1 c ]} [a:b:c]',184 'qux foo bar .d baz 1 qux ] corge',185 'qux [bar:baz:qux] corge');186 });187 it('should expand .eol', function() {188 testExpand('.define foo {a b c} [a:b:c] .eol a:c .eol b',189 'qux foo bar baz qux',190 'qux [bar:baz:qux]',191 'bar:qux\nbaz'); // overflow192 });193 it('should not expand .eol if not at end of line', function() {194 const define = Define.from(tok('.define foo {a b c} [a:b:c] .eol a:c'));195 expect(define.expand(tok('foo bar baz qux not_eol'), 0)).to.not.be.ok; 196 });197 });198});199function strip(t: Token): Token {200 delete t.source;201 if (t.token === 'grp') t.inner.map(strip);202 return t;203};204function tok(str: string): Token[] {205 return new Tokenizer(str).next()!.map(strip);206}207function toks(str: string): Token[][] {208 const lines: Token[][] = [];209 const tokenizer = new Tokenizer(str);210 for (let line = tokenizer.next(); line; line = tokenizer.next()) {211 lines.push(line.map(strip));212 }213 return lines;...
test_mozpath.py
Source:test_mozpath.py
1# This Source Code Form is subject to the terms of the Mozilla Public2# License, v. 2.0. If a copy of the MPL was not distributed with this3# file, You can obtain one at http://mozilla.org/MPL/2.0/.4from __future__ import absolute_import5from compare_locales.mozpath import (6 relpath,7 join,8 normpath,9 dirname,10 commonprefix,11 basename,12 split,13 splitext,14 basedir,15 match,16 rebase,17)18import unittest19import os20class TestPath(unittest.TestCase):21 SEP = os.sep22 def test_relpath(self):23 self.assertEqual(relpath('foo', 'foo'), '')24 self.assertEqual(relpath(self.SEP.join(('foo', 'bar')), 'foo/bar'), '')25 self.assertEqual(relpath(self.SEP.join(('foo', 'bar')), 'foo'), 'bar')26 self.assertEqual(relpath(self.SEP.join(('foo', 'bar', 'baz')), 'foo'),27 'bar/baz')28 self.assertEqual(relpath(self.SEP.join(('foo', 'bar')), 'foo/bar/baz'),29 '..')30 self.assertEqual(relpath(self.SEP.join(('foo', 'bar')), 'foo/baz'),31 '../bar')32 self.assertEqual(relpath('foo/', 'foo'), '')33 self.assertEqual(relpath('foo/bar/', 'foo'), 'bar')34 def test_join(self):35 self.assertEqual(join('foo', 'bar', 'baz'), 'foo/bar/baz')36 self.assertEqual(join('foo', '', 'bar'), 'foo/bar')37 self.assertEqual(join('', 'foo', 'bar'), 'foo/bar')38 self.assertEqual(join('', 'foo', '/bar'), '/bar')39 def test_normpath(self):40 self.assertEqual(normpath(self.SEP.join(('foo', 'bar', 'baz',41 '..', 'qux'))), 'foo/bar/qux')42 def test_dirname(self):43 self.assertEqual(dirname('foo/bar/baz'), 'foo/bar')44 self.assertEqual(dirname('foo/bar'), 'foo')45 self.assertEqual(dirname('foo'), '')46 self.assertEqual(dirname('foo/bar/'), 'foo/bar')47 def test_commonprefix(self):48 self.assertEqual(commonprefix([self.SEP.join(('foo', 'bar', 'baz')),49 'foo/qux', 'foo/baz/qux']), 'foo/')50 self.assertEqual(commonprefix([self.SEP.join(('foo', 'bar', 'baz')),51 'foo/qux', 'baz/qux']), '')52 def test_basename(self):53 self.assertEqual(basename('foo/bar/baz'), 'baz')54 self.assertEqual(basename('foo/bar'), 'bar')55 self.assertEqual(basename('foo'), 'foo')56 self.assertEqual(basename('foo/bar/'), '')57 def test_split(self):58 self.assertEqual(split(self.SEP.join(('foo', 'bar', 'baz'))),59 ['foo', 'bar', 'baz'])60 def test_splitext(self):61 self.assertEqual(splitext(self.SEP.join(('foo', 'bar', 'baz.qux'))),62 ('foo/bar/baz', '.qux'))63 def test_basedir(self):64 foobarbaz = self.SEP.join(('foo', 'bar', 'baz'))65 self.assertEqual(basedir(foobarbaz, ['foo', 'bar', 'baz']), 'foo')66 self.assertEqual(basedir(foobarbaz, ['foo', 'foo/bar', 'baz']),67 'foo/bar')68 self.assertEqual(basedir(foobarbaz, ['foo/bar', 'foo', 'baz']),69 'foo/bar')70 self.assertEqual(basedir(foobarbaz, ['foo', 'bar', '']), 'foo')71 self.assertEqual(basedir(foobarbaz, ['bar', 'baz', '']), '')72 def test_match(self):73 self.assertTrue(match('foo', ''))74 self.assertTrue(match('foo/bar/baz.qux', 'foo/bar'))75 self.assertTrue(match('foo/bar/baz.qux', 'foo'))76 self.assertTrue(match('foo', '*'))77 self.assertTrue(match('foo/bar/baz.qux', 'foo/bar/*'))78 self.assertTrue(match('foo/bar/baz.qux', 'foo/bar/*'))79 self.assertTrue(match('foo/bar/baz.qux', 'foo/bar/*'))80 self.assertTrue(match('foo/bar/baz.qux', 'foo/bar/*'))81 self.assertTrue(match('foo/bar/baz.qux', 'foo/*/baz.qux'))82 self.assertTrue(match('foo/bar/baz.qux', '*/bar/baz.qux'))83 self.assertTrue(match('foo/bar/baz.qux', '*/*/baz.qux'))84 self.assertTrue(match('foo/bar/baz.qux', '*/*/*'))85 self.assertTrue(match('foo/bar/baz.qux', 'foo/*/*'))86 self.assertTrue(match('foo/bar/baz.qux', 'foo/*/*.qux'))87 self.assertTrue(match('foo/bar/baz.qux', 'foo/b*/*z.qux'))88 self.assertTrue(match('foo/bar/baz.qux', 'foo/b*r/ba*z.qux'))89 self.assertFalse(match('foo/bar/baz.qux', 'foo/b*z/ba*r.qux'))90 self.assertTrue(match('foo/bar/baz.qux', '**'))91 self.assertTrue(match('foo/bar/baz.qux', '**/baz.qux'))92 self.assertTrue(match('foo/bar/baz.qux', '**/bar/baz.qux'))93 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/baz.qux'))94 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/*.qux'))95 self.assertTrue(match('foo/bar/baz.qux', '**/foo/bar/baz.qux'))96 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/bar/baz.qux'))97 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/bar/*.qux'))98 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/*.qux'))99 self.assertTrue(match('foo/bar/baz.qux', '**/*.qux'))100 self.assertFalse(match('foo/bar/baz.qux', '**.qux'))101 self.assertFalse(match('foo/bar', 'foo/*/bar'))102 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/bar/**'))103 self.assertFalse(match('foo/nobar/baz.qux', 'foo/**/bar/**'))104 self.assertTrue(match('foo/bar', 'foo/**/bar/**'))105 def test_rebase(self):106 self.assertEqual(rebase('foo', 'foo/bar', 'bar/baz'), 'baz')107 self.assertEqual(rebase('foo', 'foo', 'bar/baz'), 'bar/baz')108 self.assertEqual(rebase('foo/bar', 'foo', 'baz'), 'bar/baz')109if os.altsep:110 class TestAltPath(TestPath):111 SEP = os.altsep112 class TestReverseAltPath(TestPath):113 def setUp(self):114 sep = os.sep115 os.sep = os.altsep116 os.altsep = sep117 def tearDown(self):118 self.setUp()119 class TestAltReverseAltPath(TestReverseAltPath):...
test_path.py
Source:test_path.py
1# This Source Code Form is subject to the terms of the Mozilla Public2# License, v. 2.0. If a copy of the MPL was not distributed with this3# file, You can obtain one at http://mozilla.org/MPL/2.0/.4from mozpack.path import (5 relpath,6 join,7 normpath,8 dirname,9 commonprefix,10 basename,11 split,12 splitext,13 basedir,14 match,15 rebase,16)17import unittest18import mozunit19import os20class TestPath(unittest.TestCase):21 def test_relpath(self):22 self.assertEqual(relpath('foo', 'foo'), '')23 self.assertEqual(relpath(os.path.join('foo', 'bar'), 'foo/bar'), '')24 self.assertEqual(relpath(os.path.join('foo', 'bar'), 'foo'), 'bar')25 self.assertEqual(relpath(os.path.join('foo', 'bar', 'baz'), 'foo'),26 'bar/baz')27 self.assertEqual(relpath(os.path.join('foo', 'bar'), 'foo/bar/baz'),28 '..')29 self.assertEqual(relpath(os.path.join('foo', 'bar'), 'foo/baz'),30 '../bar')31 self.assertEqual(relpath('foo/', 'foo'), '')32 self.assertEqual(relpath('foo/bar/', 'foo'), 'bar')33 def test_join(self):34 self.assertEqual(join('foo', 'bar', 'baz'), 'foo/bar/baz')35 self.assertEqual(join('foo', '', 'bar'), 'foo/bar')36 self.assertEqual(join('', 'foo', 'bar'), 'foo/bar')37 self.assertEqual(join('', 'foo', '/bar'), '/bar')38 def test_normpath(self):39 self.assertEqual(normpath(os.path.join('foo', 'bar', 'baz',40 '..', 'qux')), 'foo/bar/qux')41 def test_dirname(self):42 self.assertEqual(dirname('foo/bar/baz'), 'foo/bar')43 self.assertEqual(dirname('foo/bar'), 'foo')44 self.assertEqual(dirname('foo'), '')45 self.assertEqual(dirname('foo/bar/'), 'foo/bar')46 def test_commonprefix(self):47 self.assertEqual(commonprefix([os.path.join('foo', 'bar', 'baz'),48 'foo/qux', 'foo/baz/qux']), 'foo/')49 self.assertEqual(commonprefix([os.path.join('foo', 'bar', 'baz'),50 'foo/qux', 'baz/qux']), '')51 def test_basename(self):52 self.assertEqual(basename('foo/bar/baz'), 'baz')53 self.assertEqual(basename('foo/bar'), 'bar')54 self.assertEqual(basename('foo'), 'foo')55 self.assertEqual(basename('foo/bar/'), '')56 def test_split(self):57 self.assertEqual(split(os.path.join('foo', 'bar', 'baz')),58 ['foo', 'bar', 'baz'])59 def test_splitext(self):60 self.assertEqual(splitext(os.path.join('foo', 'bar', 'baz.qux')),61 ('foo/bar/baz', '.qux'))62 def test_basedir(self):63 foobarbaz = os.path.join('foo', 'bar', 'baz')64 self.assertEqual(basedir(foobarbaz, ['foo', 'bar', 'baz']), 'foo')65 self.assertEqual(basedir(foobarbaz, ['foo', 'foo/bar', 'baz']),66 'foo/bar')67 self.assertEqual(basedir(foobarbaz, ['foo/bar', 'foo', 'baz']),68 'foo/bar')69 self.assertEqual(basedir(foobarbaz, ['foo', 'bar', '']), 'foo')70 self.assertEqual(basedir(foobarbaz, ['bar', 'baz', '']), '')71 def test_match(self):72 self.assertTrue(match('foo', ''))73 self.assertTrue(match('foo/bar/baz.qux', 'foo/bar'))74 self.assertTrue(match('foo/bar/baz.qux', 'foo'))75 self.assertTrue(match('foo', '*'))76 self.assertTrue(match('foo/bar/baz.qux', 'foo/bar/*'))77 self.assertTrue(match('foo/bar/baz.qux', 'foo/bar/*'))78 self.assertTrue(match('foo/bar/baz.qux', 'foo/bar/*'))79 self.assertTrue(match('foo/bar/baz.qux', 'foo/bar/*'))80 self.assertTrue(match('foo/bar/baz.qux', 'foo/*/baz.qux'))81 self.assertTrue(match('foo/bar/baz.qux', '*/bar/baz.qux'))82 self.assertTrue(match('foo/bar/baz.qux', '*/*/baz.qux'))83 self.assertTrue(match('foo/bar/baz.qux', '*/*/*'))84 self.assertTrue(match('foo/bar/baz.qux', 'foo/*/*'))85 self.assertTrue(match('foo/bar/baz.qux', 'foo/*/*.qux'))86 self.assertTrue(match('foo/bar/baz.qux', 'foo/b*/*z.qux'))87 self.assertTrue(match('foo/bar/baz.qux', 'foo/b*r/ba*z.qux'))88 self.assertFalse(match('foo/bar/baz.qux', 'foo/b*z/ba*r.qux'))89 self.assertTrue(match('foo/bar/baz.qux', '**'))90 self.assertTrue(match('foo/bar/baz.qux', '**/baz.qux'))91 self.assertTrue(match('foo/bar/baz.qux', '**/bar/baz.qux'))92 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/baz.qux'))93 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/*.qux'))94 self.assertTrue(match('foo/bar/baz.qux', '**/foo/bar/baz.qux'))95 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/bar/baz.qux'))96 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/bar/*.qux'))97 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/*.qux'))98 self.assertTrue(match('foo/bar/baz.qux', '**/*.qux'))99 self.assertFalse(match('foo/bar/baz.qux', '**.qux'))100 self.assertFalse(match('foo/bar', 'foo/*/bar'))101 self.assertTrue(match('foo/bar/baz.qux', 'foo/**/bar/**'))102 self.assertFalse(match('foo/nobar/baz.qux', 'foo/**/bar/**'))103 self.assertTrue(match('foo/bar', 'foo/**/bar/**'))104 def test_rebase(self):105 self.assertEqual(rebase('foo', 'foo/bar', 'bar/baz'), 'baz')106 self.assertEqual(rebase('foo', 'foo', 'bar/baz'), 'bar/baz')107 self.assertEqual(rebase('foo/bar', 'foo', 'baz'), 'bar/baz')108if __name__ == '__main__':...
test_packager_l10n.py
Source:test_packager_l10n.py
1# This Source Code Form is subject to the terms of the Mozilla Public2# License, v. 2.0. If a copy of the MPL was not distributed with this3# file, You can obtain one at http://mozilla.org/MPL/2.0/.4import unittest5import mozunit6from test_packager import MockFinder7from mozpack.packager import l10n8from mozpack.files import (9 GeneratedFile,10 ManifestFile,11)12from mozpack.chrome.manifest import (13 Manifest,14 ManifestLocale,15 ManifestContent,16)17from mozpack.copier import FileRegistry18from mozpack.packager.formats import FlatFormatter19class TestL10NRepack(unittest.TestCase):20 def test_l10n_repack(self):21 foo = GeneratedFile('foo')22 foobar = GeneratedFile('foobar')23 qux = GeneratedFile('qux')24 bar = GeneratedFile('bar')25 baz = GeneratedFile('baz')26 dict_aa = GeneratedFile('dict_aa')27 dict_bb = GeneratedFile('dict_bb')28 dict_cc = GeneratedFile('dict_cc')29 barbaz = GeneratedFile('barbaz')30 lst = GeneratedFile('foo\nbar')31 app_finder = MockFinder({32 'bar/foo': foo,33 'chrome/foo/foobar': foobar,34 'chrome/qux/qux.properties': qux,35 'chrome/qux/baz/baz.properties': baz,36 'chrome/chrome.manifest': ManifestFile('chrome', [37 ManifestContent('chrome', 'foo', 'foo/'),38 ManifestLocale('chrome', 'qux', 'en-US', 'qux/'),39 ]),40 'chrome.manifest':41 ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]),42 'dict/aa': dict_aa,43 'app/chrome/bar/barbaz.dtd': barbaz,44 'app/chrome/chrome.manifest': ManifestFile('app/chrome', [45 ManifestLocale('app/chrome', 'bar', 'en-US', 'bar/')46 ]),47 'app/chrome.manifest':48 ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]),49 'app/dict/bb': dict_bb,50 'app/dict/cc': dict_cc,51 'app/chrome/bar/search/foo.xml': foo,52 'app/chrome/bar/search/bar.xml': bar,53 'app/chrome/bar/search/lst.txt': lst,54 })55 app_finder.jarlogs = {}56 app_finder.base = 'app'57 foo_l10n = GeneratedFile('foo_l10n')58 qux_l10n = GeneratedFile('qux_l10n')59 baz_l10n = GeneratedFile('baz_l10n')60 barbaz_l10n = GeneratedFile('barbaz_l10n')61 lst_l10n = GeneratedFile('foo\nqux')62 l10n_finder = MockFinder({63 'chrome/qux-l10n/qux.properties': qux_l10n,64 'chrome/qux-l10n/baz/baz.properties': baz_l10n,65 'chrome/chrome.manifest': ManifestFile(' chrome', [66 ManifestLocale('chrome', 'qux', 'x-test', 'qux-l10n/'),67 ]),68 'chrome.manifest':69 ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]),70 'dict/bb': dict_bb,71 'dict/cc': dict_cc,72 'app/chrome/bar-l10n/barbaz.dtd': barbaz_l10n,73 'app/chrome/chrome.manifest': ManifestFile('app/chrome', [74 ManifestLocale('app/chrome', 'bar', 'x-test', 'bar-l10n/')75 ]),76 'app/chrome.manifest':77 ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]),78 'app/dict/aa': dict_aa,79 'app/chrome/bar-l10n/search/foo.xml': foo_l10n,80 'app/chrome/bar-l10n/search/qux.xml': qux_l10n,81 'app/chrome/bar-l10n/search/lst.txt': lst_l10n,82 })83 l10n_finder.base = 'l10n'84 copier = FileRegistry()85 formatter = FlatFormatter(copier)86 l10n._repack(app_finder, l10n_finder, copier, formatter,87 ['dict', 'chrome/**/search/*.xml'])88 self.maxDiff = None89 repacked = {90 'bar/foo': foo,91 'chrome/foo/foobar': foobar,92 'chrome/qux-l10n/qux.properties': qux_l10n,93 'chrome/qux-l10n/baz/baz.properties': baz_l10n,94 'chrome/chrome.manifest': ManifestFile('chrome', [95 ManifestContent('chrome', 'foo', 'foo/'),96 ManifestLocale('chrome', 'qux', 'x-test', 'qux-l10n/'),97 ]),98 'chrome.manifest':99 ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]),100 'dict/bb': dict_bb,101 'dict/cc': dict_cc,102 'app/chrome/bar-l10n/barbaz.dtd': barbaz_l10n,103 'app/chrome/chrome.manifest': ManifestFile('app/chrome', [104 ManifestLocale('app/chrome', 'bar', 'x-test', 'bar-l10n/')105 ]),106 'app/chrome.manifest':107 ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]),108 'app/dict/aa': dict_aa,109 'app/chrome/bar-l10n/search/foo.xml': foo_l10n,110 'app/chrome/bar-l10n/search/qux.xml': qux_l10n,111 'app/chrome/bar-l10n/search/lst.txt': lst_l10n,112 }113 self.assertEqual(114 dict((p, f.open().read()) for p, f in copier),115 dict((p, f.open().read()) for p, f in repacked.iteritems())116 )117if __name__ == '__main__':...
bm_call_simple.py
Source:bm_call_simple.py
...75 quux(a)76 quux(a)77def quux(a):78 # 20 calls79 qux()80 qux()81 qux()82 qux()83 qux()84 qux()85 qux()86 qux()87 qux()88 qux()89 qux()90 qux()91 qux()92 qux()93 qux()94 qux()95 qux()96 qux()97 qux()98 qux()99def qux():100 pass101def test_calls(iterations):102 from javascript import console103 times = []104 for _i in range(iterations):105 console.log("iteration: %s" % _i)106 t0 = time.time()107 # 40 calls108 foo(1, 2, 3, 4)109 foo(1, 2, 3, 4)110 foo(1, 2, 3, 4)111 foo(1, 2, 3, 4)112 foo(1, 2, 3, 4)113 foo(1, 2, 3, 4)...
test.js
Source:test.js
1var tap = require("tap")2var nst = require("../index")3// main4tap.throws(nst.main)5// getRunScripts6var runScripts = {7 'foo': [],8 'foo && npm run': [],9 'foo && npm run bar': ['bar'],10 'foo && npm run bar_toto': ['bar_toto'],11 'foo && npm run bar-toto': ['bar-toto'],12 'foo && npm run bar && qux': ['bar'],13 'foo && npm run bar': ['bar'],14 'foo && npm run bar && npm run bar': ['bar'],15 'foo && npm run bar && npm run qux': ['bar', 'qux'],16 'foo && npm run bar && npm run qux': ['bar', 'qux'],17 'foo && npm run bar:qux': ['bar:qux'],18 'foo && npm run bar:qux:toto': ['bar:qux:toto'],19}20Object.keys(runScripts).forEach((cmd) => {21 tap.same(nst.getRunScripts(cmd), runScripts[cmd])22})23// getRunAllScripts24var runAllScripts = {25 'foo': [],26 'foo && npm-run-all': [],27 'foo && npm-run-all bar': ['bar'],28 'foo && npm-run-all bar_toto': ['bar_toto'],29 'foo && npm-run-all bar-toto': ['bar-toto'],30 'foo && npm-run-all bar:toto': ['bar:toto'],31 'foo && npm-run-all bar:*': ['bar:*'],32 'foo && npm-run-all bar:*:*': ['bar:*:*'],33 'foo && npm-run-all bar': ['bar'],34 'foo && npm-run-all bar bar': ['bar'],35 'foo && npm-run-all bar qux': ['bar', 'qux'],36 'foo && npm-run-all bar qux': ['bar', 'qux'],37 'foo && npm-run-all bar qux && npm-run-all yolo toto': ['bar', 'qux', 'yolo', 'toto'],38 'foo && npm-run-all bar qux && npm-run-all yolo toto': ['bar', 'qux', 'yolo', 'toto'],39 'foo && npm-run-all -s bar qux': ['bar', 'qux'],40 'foo && npm-run-all --serial bar qux': ['bar', 'qux'],41 'foo && npm-run-all -s bar qux && npm-run-all yolo': ['bar', 'qux', 'yolo'],42 'foo && npm-run-all -p bar qux': ['bar', 'qux'],43 'foo && npm-run-all --parallel bar qux': ['bar', 'qux'],44}45Object.keys(runAllScripts).forEach((cmd) => {46 tap.same(nst.getRunAllScripts(cmd), runAllScripts[cmd])47})48// isLifeCycleScript49tap.notOk(nst.isLifeCycleScript('foo', 'bar', { bar: 'bar' }))50tap.ok(nst.isLifeCycleScript('foo', 'foobar', { bar: 'bar' }))51// expandWildcard52tap.same(53 nst.expandWildcard('foo:*', {54 'foo': 'bar',55 'foo:bar': 'qux',56 'foo:yolo': 'toto',57 'foo:bar:yolo': 'toto',58 'fooqux': 'qux',59 }),60 ['foo:bar', 'foo:yolo']61)62// Globstar63tap.same(64 nst.expandWildcard('foo:**', {65 'foo': 'bar',66 'foo:bar': 'qux',67 'foo:yolo': 'toto',68 'foo:bar:yolo': 'toto',69 'fooqux': 'qux',70 }),71 ['foo:bar', 'foo:yolo', 'foo:bar:yolo']...
Using AI Code Generation
1var strykerParent = require('stryker-parent');2strykerParent.qux();3var strykerParent = require('stryker-parent');4strykerParent.qux();5var strykerParent = require('stryker-parent');6strykerParent.qux();7var strykerParent = require('stryker-parent');8strykerParent.qux();9var strykerParent = require('stryker-parent');10strykerParent.qux();11var strykerParent = require('stryker-parent');12strykerParent.qux();13var strykerParent = require('stryker-parent');14strykerParent.qux();15var strykerParent = require('stryker-parent');16strykerParent.qux();17var strykerParent = require('stryker-parent');18strykerParent.qux();19var strykerParent = require('stryker-parent');20strykerParent.qux();21var strykerParent = require('stryker-parent');22strykerParent.qux();23var strykerParent = require('stryker-parent');24strykerParent.qux();25var strykerParent = require('stryker-parent');26strykerParent.qux();27var strykerParent = require('stryker-parent');28strykerParent.qux();
Using AI Code Generation
1var strykerParent = require('stryker-parent');2strykerParent.qux();3var strykerChild = require('stryker-child');4strykerChild.bar();5var strykerGrandChild = require('stryker-grandchild');6strykerGrandChild.foo();7var strykerParent = require('stryker-parent');8strykerParent.qux();9var strykerChild = require('stryker-child');10strykerChild.bar();11var strykerGrandChild = require('stryker-grandchild');12strykerGrandChild.foo();13var strykerParent = require('stryker-parent');14strykerParent.qux();15var strykerChild = require('stryker-child');16strykerChild.bar();17var strykerGrandChild = require('stryker-grandchild');18strykerGrandChild.foo();19var strykerParent = require('stryker-parent');20strykerParent.qux();21var strykerChild = require('stryker-child');22strykerChild.bar();23var strykerGrandChild = require('stryker-grandchild');24strykerGrandChild.foo();25var strykerParent = require('stryker-parent');26strykerParent.qux();27var strykerChild = require('stryker-child');28strykerChild.bar();29var strykerGrandChild = require('stryker-grandchild');30strykerGrandChild.foo();
Using AI Code Generation
1const strykerParent = require('stryker-parent');2strykerParent.qux();3const strykerParent = require('stryker-parent');4strykerParent.qux();5const strykerParent = require('stryker-parent');6strykerParent.qux();7const strykerParent = require('stryker-parent');8strykerParent.qux();9const strykerParent = require('stryker-parent');10strykerParent.qux();11const strykerParent = require('stryker-parent');12strykerParent.qux();13const strykerParent = require('stryker-parent');14strykerParent.qux();15const strykerParent = require('stryker-parent');16strykerParent.qux();17const strykerParent = require('stryker-parent');18strykerParent.qux();19const strykerParent = require('stryker-parent');20strykerParent.qux();21const strykerParent = require('stryker-parent');22strykerParent.qux();23const strykerParent = require('stryker-parent');24strykerParent.qux();25const strykerParent = require('stryker-parent');26strykerParent.qux();27const strykerParent = require('stryker-parent');28strykerParent.qux();
Using AI Code Generation
1var parent = require('stryker-parent');2var child = require('stryker-child');3module.exports = function(config) {4 config.set({5 karma: {6 config: {7 }8 }9 });10};
Using AI Code Generation
1var parent = require('stryker-parent');2parent.qux();3module.exports = {4 qux: function() {5 console.log('qux');6 }7};8var parent = require('stryker-parent');9module.exports = {10 qux: function() {11 console.log('qux child');12 }13};14var child = require('stryker-child');15module.exports = {16 qux: function() {17 console.log('qux parent');18 }19};
Using AI Code Generation
1var strykerParent = require('./stryker-parent.js');2strykerParent.qux();3var strykerChild = require('./stryker-child.js');4module.exports = {5 qux: function () {6 strykerChild.foo();7 }8};9module.exports = {10 foo: function () {11 console.log('foo');12 }13};14var strykerChild = require(require.resolve('./stryker-child.js'));15module.exports = {16 qux: function () {17 strykerChild.foo();18 }19};
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!