text:
'use strict';

jest.dontMock('../')
  .dontMock('underscore')
  .dontMock('../../DependencyResolver/lib/extractRequires')
  .dontMock('../../DependencyResolver/lib/replacePatterns');

jest.mock('path');

var Promise = require('promise');
var Resolver = require('../');
var Module = require('../../DependencyResolver/Module');
var Polyfill = require('../../DependencyResolver/Polyfill');
var DependencyGraph = require('../../DependencyResolver/DependencyGraph');

var path = require('path');
var _ = require('underscore');

describe('Resolver', function() {
  beforeEach(function() {
    Polyfill.mockClear();

    // For the polyfillDeps
    path.join.mockImpl(function(a, b) {
      return b;
    });

    DependencyGraph.prototype.load.mockImpl(() => Promise.resolve());
  });

  class ResolutionResponseMock {
    constructor({dependencies, mainModuleId, asyncDependencies}) {
      this.dependencies = dependencies;
      this.mainModuleId = mainModuleId;
      this.asyncDependencies = asyncDependencies;
    }

    prependDependency(dependency) {
      this.dependencies.unshift(dependency);
    }

    finalize() {
      return Promise.resolve(this);
    }
  }

  function createModule(id, dependencies) {
    var module = new Module({});
    module.getName.mockImpl(() => Promise.resolve(id));
    module.getDependencies.mockImpl(() => Promise.resolve(dependencies));
    return module;
  }

  function createPolyfill(id, dependencies) {
    var polyfill = new Polyfill({});
    polyfill.getName.mockImpl(() => Promise.resolve(id));
    polyfill.getDependencies.mockImpl(() => Promise.resolve(dependencies));
    polyfill.isPolyfill.mockReturnValue(true);
    return polyfill;
  }

  describe('getDependencies', function() {
    pit('should get dependencies with polyfills', function() {
      var module = createModule('index');
      var deps = [module];

      var depResolver = new Resolver({
        projectRoot: '/root',
      });

      DependencyGraph.prototype.getDependencies.mockImpl(function() {
        return Promise.resolve(new ResolutionResponseMock({
          dependencies: deps,
          mainModuleId: 'index',
          asyncDependencies: [],
        }));
      });

      return depResolver.getDependencies('/root/index.js', { dev: false })
        .then(function(result) {
          expect(result.mainModuleId).toEqual('index');
          expect(result.dependencies[result.dependencies.length - 1]).toBe(module);
          expect(_.pluck(Polyfill.mock.calls, 0)).toEqual([
            { path: 'polyfills/polyfills.js',
              id: 'polyfills/polyfills.js',
              isPolyfill: true,
              dependencies: []
            },
            { id: 'polyfills/console.js',
              isPolyfill: true,
              path: 'polyfills/console.js',
              dependencies: [
                'polyfills/polyfills.js'
              ],
            },
            { id: 'polyfills/error-guard.js',
              isPolyfill: true,
              path: 'polyfills/error-guard.js',
              dependencies: [
                'polyfills/polyfills.js',
                'polyfills/console.js'
              ],
            },
            { id: 'polyfills/String.prototype.es6.js',
              isPolyfill: true,
              path: 'polyfills/String.prototype.es6.js',
              dependencies: [
                'polyfills/polyfills.js',
                'polyfills/console.js',
                'polyfills/error-guard.js'
              ],
            },
            { id: 'polyfills/Array.prototype.es6.js',
              isPolyfill: true,
              path: 'polyfills/Array.prototype.es6.js',
              dependencies: [
                'polyfills/polyfills.js',
                'polyfills/console.js',
                'polyfills/error-guard.js',
                'polyfills/String.prototype.es6.js',
              ],
            },
            { id: 'polyfills/Array.es6.js',
              isPolyfill: true,
              path: 'polyfills/Array.es6.js',
              dependencies: [
                'polyfills/polyfills.js',
                'polyfills/console.js',
                'polyfills/error-guard.js',
                'polyfills/String.prototype.es6.js',
                'polyfills/Array.prototype.es6.js',
              ],
            },
            { id: 'polyfills/Object.es7.js',
              isPolyfill: true,
              path: 'polyfills/Object.es7.js',
              dependencies: [
                'polyfills/polyfills.js',
                'polyfills/console.js',
                'polyfills/error-guard.js',
                'polyfills/String.prototype.es6.js',
                'polyfills/Array.prototype.es6.js',
                'polyfills/Array.es6.js',
              ],
            },
            { id: 'polyfills/babelHelpers.js',
              isPolyfill: true,
              path: 'polyfills/babelHelpers.js',
              dependencies: [
                'polyfills/polyfills.js',
                'polyfills/console.js',
                'polyfills/error-guard.js',
                'polyfills/String.prototype.es6.js',
                'polyfills/Array.prototype.es6.js',
                'polyfills/Array.es6.js',
                'polyfills/Object.es7.js',
              ],
            },
          ]);
        });
    });

    pit('should get dependencies with polyfills', function() {
      var module = createModule('index');
      var deps = [module];

      var depResolver = new Resolver({
        projectRoot: '/root',
      });

      DependencyGraph.prototype.getDependencies.mockImpl(function() {
        return Promise.resolve(new ResolutionResponseMock({
          dependencies: deps,
          mainModuleId: 'index',
          asyncDependencies: [],
        }));
      });

      return depResolver.getDependencies('/root/index.js', { dev: true })
        .then(function(result) {
          expect(result.mainModuleId).toEqual('index');
          expect(DependencyGraph.mock.instances[0].getDependencies)
              .toBeCalledWith('/root/index.js', undefined, true);
          expect(result.dependencies[0]).toBe(Polyfill.mock.instances[0]);
          expect(result.dependencies[result.dependencies.length - 1])
              .toBe(module);
        });
    });

    pit('should pass in more polyfills', function() {
      var module = createModule('index');
      var deps = [module];

      var depResolver = new Resolver({
        projectRoot: '/root',
        polyfillModuleNames: ['some module'],
      });

      DependencyGraph.prototype.getDependencies.mockImpl(function() {
        return Promise.resolve(new ResolutionResponseMock({
          dependencies: deps,
          mainModuleId: 'index',
          asyncDependencies: [],
        }));
      });

      return depResolver.getDependencies('/root/index.js', { dev: false })
        .then((result) => {
          expect(result.mainModuleId).toEqual('index');
          expect(Polyfill.mock.calls[result.dependencies.length - 2]).toEqual([
            { path: 'some module',
              id: 'some module',
              isPolyfill: true,
              dependencies: [
                'polyfills/polyfills.js',
                'polyfills/console.js',
                'polyfills/error-guard.js',
                'polyfills/String.prototype.es6.js',
                'polyfills/Array.prototype.es6.js',
                'polyfills/Array.es6.js',
                'polyfills/Object.es7.js',
                'polyfills/babelHelpers.js',
              ]
            },
          ]);
        });
    });
  });

  describe('wrapModule', function() {
    pit('should resolve modules', function() {
      var depResolver = new Resolver({
        projectRoot: '/root',
      });

      var dependencies = ['x', 'y', 'z', 'a', 'b'];

      /*eslint-disable */
      var code = [
        // single line import
        "import'x';",
        "import 'x';",
        "import 'x' ;",
        "import Default from 'x';",
        "import * as All from 'x';",
        "import {} from 'x';",
        "import { } from 'x';",
        "import {Foo} from 'x';",
        "import { Foo } from 'x';",
        "import { Foo, } from 'x';",
        "import {Foo as Bar} from 'x';",
        "import { Foo as Bar } from 'x';",
        "import { Foo as Bar, } from 'x';",
        "import { Foo, Bar } from 'x';",
        "import { Foo, Bar, } from 'x';",
        "import { Foo as Bar, Baz } from 'x';",
        "import { Foo as Bar, Baz, } from 'x';",
        "import { Foo, Bar as Baz } from 'x';",
        "import { Foo, Bar as Baz, } from 'x';",
        "import { Foo as Bar, Baz as Qux } from 'x';",
        "import { Foo as Bar, Baz as Qux, } from 'x';",
        "import { Foo, Bar, Baz } from 'x';",
        "import { Foo, Bar, Baz, } from 'x';",
        "import { Foo as Bar, Baz, Qux } from 'x';",
        "import { Foo as Bar, Baz, Qux, } from 'x';",
        "import { Foo, Bar as Baz, Qux } from 'x';",
        "import { Foo, Bar as Baz, Qux, } from 'x';",
        "import { Foo, Bar, Baz as Qux } from 'x';",
        "import { Foo, Bar, Baz as Qux, } from 'x';",
        "import { Foo as Bar, Baz as Qux, Norf } from 'x';",
        "import { Foo as Bar, Baz as Qux, Norf, } from 'x';",
        "import { Foo as Bar, Baz, Qux as Norf } from 'x';",
        "import { Foo as Bar, Baz, Qux as Norf, } from 'x';",
        "import { Foo, Bar as Baz, Qux as Norf } from 'x';",
        "import { Foo, Bar as Baz, Qux as Norf, } from 'x';",
        "import { Foo as Bar, Baz as Qux, Norf as Enuf } from 'x';",
        "import { Foo as Bar, Baz as Qux, Norf as Enuf, } from 'x';",
        "import Default, * as All from 'x';",
        "import Default, { } from 'x';",
        "import Default, { Foo } from 'x';",
        "import Default, { Foo, } from 'x';",
        "import Default, { Foo as Bar } from 'x';",
        "import Default, { Foo as Bar, } from 'x';",
        "import Default, { Foo, Bar } from 'x';",
        "import Default, { Foo, Bar, } from 'x';",
        "import Default, { Foo as Bar, Baz } from 'x';",
        "import Default, { Foo as Bar, Baz, } from 'x';",
        "import Default, { Foo, Bar as Baz } from 'x';",
        "import Default, { Foo, Bar as Baz, } from 'x';",
        "import Default, { Foo as Bar, Baz as Qux } from 'x';",
        "import Default, { Foo as Bar, Baz as Qux, } from 'x';",
        "import Default, { Foo, Bar, Baz } from 'x';",
        "import Default, { Foo, Bar, Baz, } from 'x';",
        "import Default, { Foo as Bar, Baz, Qux } from 'x';",
        "import Default, { Foo as Bar, Baz, Qux, } from 'x';",
        "import Default, { Foo, Bar as Baz, Qux } from 'x';",
        "import Default, { Foo, Bar as Baz, Qux, } from 'x';",
        "import Default, { Foo, Bar, Baz as Qux } from 'x';",
        "import Default, { Foo, Bar, Baz as Qux, } from 'x';",
        "import Default, { Foo as Bar, Baz as Qux, Norf } from 'x';",
        "import Default, { Foo as Bar, Baz as Qux, Norf, } from 'x';",
        "import Default, { Foo as Bar, Baz, Qux as Norf } from 'x';",
        "import Default, { Foo as Bar, Baz, Qux as Norf, } from 'x';",
        "import Default, { Foo, Bar as Baz, Qux as Norf } from 'x';",
        "import Default, { Foo, Bar as Baz, Qux as Norf, } from 'x';",
        "import Default, { Foo as Bar, Baz as Qux, Norf as NoMore } from 'x';",
        "import Default, { Foo as Bar, Baz as Qux, Norf as NoMore, } from 'x';",
        "import Default , { } from 'x';",
        'import "x";',
        'import Default from "x";',
        'import * as All from "x";',
        'import { } from "x";',
        'import { Foo } from "x";',
        'import { Foo, } from "x";',
        'import { Foo as Bar } from "x";',
        'import { Foo as Bar, } from "x";',
        'import { Foo, Bar } from "x";',
        'import { Foo, Bar, } from "x";',
        'import { Foo as Bar, Baz } from "x";',
        'import { Foo as Bar, Baz, } from "x";',
        'import { Foo, Bar as Baz } from "x";',
        'import { Foo, Bar as Baz, } from "x";',
        'import { Foo as Bar, Baz as Qux } from "x";',
        'import { Foo as Bar, Baz as Qux, } from "x";',
        'import { Foo, Bar, Baz } from "x";',
        'import { Foo, Bar, Baz, } from "x";',
        'import { Foo as Bar, Baz, Qux } from "x";',
        'import { Foo as Bar, Baz, Qux, } from "x";',
        'import { Foo, Bar as Baz, Qux } from "x";',
        'import { Foo, Bar as Baz, Qux, } from "x";',
        'import { Foo, Bar, Baz as Qux } from "x";',
        'import { Foo, Bar, Baz as Qux, } from "x";',
        'import { Foo as Bar, Baz as Qux, Norf } from "x";',
        'import { Foo as Bar, Baz as Qux, Norf, } from "x";',
        'import { Foo as Bar, Baz, Qux as Norf } from "x";',
        'import { Foo as Bar, Baz, Qux as Norf, } from "x";',
        'import { Foo, Bar as Baz, Qux as Norf } from "x";',
        'import { Foo, Bar as Baz, Qux as Norf, } from "x";',
        'import { Foo as Bar, Baz as Qux, Norf as NoMore } from "x";',
        'import { Foo as Bar, Baz as Qux, Norf as NoMore, } from "x";',
        'import Default, * as All from "x";',
        'import Default, { } from "x";',
        'import Default, { Foo } from "x";',
        'import Default, { Foo, } from "x";',
        'import Default, { Foo as Bar } from "x";',
        'import Default, { Foo as Bar, } from "x";',
        'import Default, { Foo, Bar } from "x";',
        'import Default, { Foo, Bar, } from "x";',
        'import Default, { Foo as Bar, Baz } from "x";',
        'import Default, { Foo as Bar, Baz, } from "x";',
        'import Default, { Foo, Bar as Baz } from "x";',
        'import Default, { Foo, Bar as Baz, } from "x";',
        'import Default, { Foo as Bar, Baz as Qux } from "x";',
        'import Default, { Foo as Bar, Baz as Qux, } from "x";',
        'import Default, { Foo, Bar, Baz } from "x";',
        'import Default, { Foo, Bar, Baz, } from "x";',
        'import Default, { Foo as Bar, Baz, Qux } from "x";',
        'import Default, { Foo as Bar, Baz, Qux, } from "x";',
        'import Default, { Foo, Bar as Baz, Qux } from "x";',
        'import Default, { Foo, Bar as Baz, Qux, } from "x";',
        'import Default, { Foo, Bar, Baz as Qux } from "x";',
        'import Default, { Foo, Bar, Baz as Qux, } from "x";',
        'import Default, { Foo as Bar, Baz as Qux, Norf } from "x";',
        'import Default, { Foo as Bar, Baz as Qux, Norf, } from "x";',
        'import Default, { Foo as Bar, Baz, Qux as Norf } from "x";',
        'import Default, { Foo as Bar, Baz, Qux as Norf, } from "x";',
        'import Default, { Foo, Bar as Baz, Qux as Norf } from "x";',
        'import Default, { Foo, Bar as Baz, Qux as Norf, } from "x";',
        'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf } from "x";',
        'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "x";',
        'import Default from "y";',
        'import * as All from \'z\';',
        // import with support for new lines
        "import { Foo,\n Bar }\n from 'x';",
        "import { \nFoo,\nBar,\n }\n from 'x';",
        "import { Foo as Bar,\n Baz\n }\n from 'x';",
        "import { \nFoo as Bar,\n Baz\n, }\n from 'x';",
        "import { Foo,\n Bar as Baz\n }\n from 'x';",
        "import { Foo,\n Bar as Baz,\n }\n from 'x';",
        "import { Foo as Bar,\n Baz as Qux\n }\n from 'x';",
        "import { Foo as Bar,\n Baz as Qux,\n }\n from 'x';",
        "import { Foo,\n Bar,\n Baz }\n from 'x';",
        "import { Foo,\n Bar,\n Baz,\n }\n from 'x';",
        "import { Foo as Bar,\n Baz,\n Qux\n }\n from 'x';",
        "import { Foo as Bar,\n Baz,\n Qux,\n }\n from 'x';",
        "import { Foo,\n Bar as Baz,\n Qux\n }\n from 'x';",
        "import { Foo,\n Bar as Baz,\n Qux,\n }\n from 'x';",
        "import { Foo,\n Bar,\n Baz as Qux\n }\n from 'x';",
        "import { Foo,\n Bar,\n Baz as Qux,\n }\n from 'x';",
        "import { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'x';",
        "import { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'x';",
        "import { Foo as Bar,\n Baz,\n Qux as Norf\n }\n from 'x';",
        "import { Foo as Bar,\n Baz,\n Qux as Norf,\n }\n from 'x';",
        "import { Foo,\n Bar as Baz,\n Qux as Norf\n }\n from 'x';",
        "import { Foo,\n Bar as Baz,\n Qux as Norf,\n }\n from 'x';",
        "import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf\n }\n from 'x';",
        "import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf,\n }\n from 'x';",
        "import Default,\n * as All from 'x';",
        "import Default,\n { } from 'x';",
        "import Default,\n { Foo\n }\n from 'x';",
        "import Default,\n { Foo,\n }\n from 'x';",
        "import Default,\n { Foo as Bar\n }\n from 'x';",
        "import Default,\n { Foo as Bar,\n }\n from 'x';",
        "import Default,\n { Foo,\n Bar\n } from\n 'x';",
        "import Default,\n { Foo,\n Bar,\n } from\n 'x';",
        "import Default,\n { Foo as Bar,\n Baz\n }\n from 'x';",
        "import Default,\n { Foo as Bar,\n Baz,\n }\n from 'x';",
        "import Default,\n { Foo,\n Bar as Baz\n }\n from 'x';",
        "import Default,\n { Foo,\n Bar as Baz,\n }\n from 'x';",
        "import Default,\n { Foo as Bar,\n Baz as Qux\n }\n from 'x';",
        "import Default,\n { Foo as Bar,\n Baz as Qux,\n }\n from 'x';",
        "import Default,\n { Foo,\n Bar,\n Baz\n }\n from 'x';",
        "import Default,\n { Foo,\n Bar,\n Baz,\n }\n from 'x';",
        "import Default,\n { Foo as Bar,\n Baz,\n Qux\n }\n from 'x';",
        "import Default,\n { Foo as Bar,\n Baz,\n Qux,\n }\n from 'x';",
        "import Default,\n { Foo,\n Bar as Baz,\n Qux\n }\n from 'x';",
        "import Default,\n { Foo,\n Bar as Baz,\n Qux,\n }\n from 'x';",
        "import Default,\n { Foo,\n Bar,\n Baz as Qux\n }\n from 'x';",
        "import Default,\n { Foo,\n Bar,\n Baz as Qux,\n }\n from 'x';",
        "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'x';",
        "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'x';",
        "import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf }\n from 'x';",
        "import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf, }\n from 'x';",
        "import Default,\n { Foo, Bar as Baz,\n Qux as Norf }\n from 'x';",
        "import Default,\n { Foo, Bar as Baz,\n Qux as Norf, }\n from 'x';",
        "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore\n }\n from 'x';",
        "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore,\n }\n from 'x';",
        "import Default\n , { } from 'x';",
        // single line export
        "export'x';",
        "export 'x';",
        "export 'x' ;",
        "export Default from 'x';",
        "export * as All from 'x';",
        "export {} from 'x';",
        "export { } from 'x';",
        "export {Foo} from 'x';",
        "export { Foo } from 'x';",
        "export { Foo, } from 'x';",
        "export {Foo as Bar} from 'x';",
        "export { Foo as Bar } from 'x';",
        "export { Foo as Bar, } from 'x';",
        "export { Foo, Bar } from 'x';",
        "export { Foo, Bar, } from 'x';",
        "export { Foo as Bar, Baz } from 'x';",
        "export { Foo as Bar, Baz, } from 'x';",
        "export { Foo, Bar as Baz } from 'x';",
        "export { Foo, Bar as Baz, } from 'x';",
        "export { Foo as Bar, Baz as Qux } from 'x';",
        "export { Foo as Bar, Baz as Qux, } from 'x';",
        "export { Foo, Bar, Baz } from 'x';",
        "export { Foo, Bar, Baz, } from 'x';",
        "export { Foo as Bar, Baz, Qux } from 'x';",
        "export { Foo as Bar, Baz, Qux, } from 'x';",
        "export { Foo, Bar as Baz, Qux } from 'x';",
        "export { Foo, Bar as Baz, Qux, } from 'x';",
        "export { Foo, Bar, Baz as Qux } from 'x';",
        "export { Foo, Bar, Baz as Qux, } from 'x';",
        "export { Foo as Bar, Baz as Qux, Norf } from 'x';",
        "export { Foo as Bar, Baz as Qux, Norf, } from 'x';",
        "export { Foo as Bar, Baz, Qux as Norf } from 'x';",
        "export { Foo as Bar, Baz, Qux as Norf, } from 'x';",
        "export { Foo, Bar as Baz, Qux as Norf } from 'x';",
        "export { Foo, Bar as Baz, Qux as Norf, } from 'x';",
        "export { Foo as Bar, Baz as Qux, Norf as Enuf } from 'x';",
        "export { Foo as Bar, Baz as Qux, Norf as Enuf, } from 'x';",
        "export Default, * as All from 'x';",
        "export Default, { } from 'x';",
        "export Default, { Foo } from 'x';",
        "export Default, { Foo, } from 'x';",
        "export Default, { Foo as Bar } from 'x';",
        "export Default, { Foo as Bar, } from 'x';",
        "export Default, { Foo, Bar } from 'x';",
        "export Default, { Foo, Bar, } from 'x';",
        "export Default, { Foo as Bar, Baz } from 'x';",
        "export Default, { Foo as Bar, Baz, } from 'x';",
        "export Default, { Foo, Bar as Baz } from 'x';",
        "export Default, { Foo, Bar as Baz, } from 'x';",
        "export Default, { Foo as Bar, Baz as Qux } from 'x';",
        "export Default, { Foo as Bar, Baz as Qux, } from 'x';",
        "export Default, { Foo, Bar, Baz } from 'x';",
        "export Default, { Foo, Bar, Baz, } from 'x';",
        "export Default, { Foo as Bar, Baz, Qux } from 'x';",
        "export Default, { Foo as Bar, Baz, Qux, } from 'x';",
        "export Default, { Foo, Bar as Baz, Qux } from 'x';",
        "export Default, { Foo, Bar as Baz, Qux, } from 'x';",
        "export Default, { Foo, Bar, Baz as Qux } from 'x';",
        "export Default, { Foo, Bar, Baz as Qux, } from 'x';",
        "export Default, { Foo as Bar, Baz as Qux, Norf } from 'x';",
        "export Default, { Foo as Bar, Baz as Qux, Norf, } from 'x';",
        "export Default, { Foo as Bar, Baz, Qux as Norf } from 'x';",
        "export Default, { Foo as Bar, Baz, Qux as Norf, } from 'x';",
        "export Default, { Foo, Bar as Baz, Qux as Norf } from 'x';",
        "export Default, { Foo, Bar as Baz, Qux as Norf, } from 'x';",
        "export Default, { Foo as Bar, Baz as Qux, Norf as NoMore } from 'x';",
        "export Default, { Foo as Bar, Baz as Qux, Norf as NoMore, } from 'x';",
        "export Default , { } from 'x';",
        'export "x";',
        'export Default from "x";',
        'export * as All from "x";',
        'export { } from "x";',
        'export { Foo } from "x";',
        'export { Foo, } from "x";',
        'export { Foo as Bar } from "x";',
        'export { Foo as Bar, } from "x";',
        'export { Foo, Bar } from "x";',
        'export { Foo, Bar, } from "x";',
        'export { Foo as Bar, Baz } from "x";',
        'export { Foo as Bar, Baz, } from "x";',
        'export { Foo, Bar as Baz } from "x";',
        'export { Foo, Bar as Baz, } from "x";',
        'export { Foo as Bar, Baz as Qux } from "x";',
        'export { Foo as Bar, Baz as Qux, } from "x";',
        'export { Foo, Bar, Baz } from "x";',
        'export { Foo, Bar, Baz, } from "x";',
        'export { Foo as Bar, Baz, Qux } from "x";',
        'export { Foo as Bar, Baz, Qux, } from "x";',
        'export { Foo, Bar as Baz, Qux } from "x";',
        'export { Foo, Bar as Baz, Qux, } from "x";',
        'export { Foo, Bar, Baz as Qux } from "x";',
        'export { Foo, Bar, Baz as Qux, } from "x";',
        'export { Foo as Bar, Baz as Qux, Norf } from "x";',
        'export { Foo as Bar, Baz as Qux, Norf, } from "x";',
        'export { Foo as Bar, Baz, Qux as Norf } from "x";',
        'export { Foo as Bar, Baz, Qux as Norf, } from "x";',
        'export { Foo, Bar as Baz, Qux as Norf } from "x";',
        'export { Foo, Bar as Baz, Qux as Norf, } from "x";',
        'export { Foo as Bar, Baz as Qux, Norf as NoMore } from "x";',
        'export { Foo as Bar, Baz as Qux, Norf as NoMore, } from "x";',
        'export Default, * as All from "x";',
        'export Default, { } from "x";',
        'export Default, { Foo } from "x";',
        'export Default, { Foo, } from "x";',
        'export Default, { Foo as Bar } from "x";',
        'export Default, { Foo as Bar, } from "x";',
        'export Default, { Foo, Bar } from "x";',
        'export Default, { Foo, Bar, } from "x";',
        'export Default, { Foo as Bar, Baz } from "x";',
        'export Default, { Foo as Bar, Baz, } from "x";',
        'export Default, { Foo, Bar as Baz } from "x";',
        'export Default, { Foo, Bar as Baz, } from "x";',
        'export Default, { Foo as Bar, Baz as Qux } from "x";',
        'export Default, { Foo as Bar, Baz as Qux, } from "x";',
        'export Default, { Foo, Bar, Baz } from "x";',
        'export Default, { Foo, Bar, Baz, } from "x";',
        'export Default, { Foo as Bar, Baz, Qux } from "x";',
        'export Default, { Foo as Bar, Baz, Qux, } from "x";',
        'export Default, { Foo, Bar as Baz, Qux } from "x";',
        'export Default, { Foo, Bar as Baz, Qux, } from "x";',
        'export Default, { Foo, Bar, Baz as Qux } from "x";',
        'export Default, { Foo, Bar, Baz as Qux, } from "x";',
        'export Default, { Foo as Bar, Baz as Qux, Norf } from "x";',
        'export Default, { Foo as Bar, Baz as Qux, Norf, } from "x";',
        'export Default, { Foo as Bar, Baz, Qux as Norf } from "x";',
        'export Default, { Foo as Bar, Baz, Qux as Norf, } from "x";',
        'export Default, { Foo, Bar as Baz, Qux as Norf } from "x";',
        'export Default, { Foo, Bar as Baz, Qux as Norf, } from "x";',
        'export Default, { Foo as Bar, Baz as Qux, Norf as Enuf } from "x";',
        'export Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "x";',
        'export Default from "y";',
        'export * as All from \'z\';',
        // export with support for new lines
        "export { Foo,\n Bar }\n from 'x';",
        "export { \nFoo,\nBar,\n }\n from 'x';",
        "export { Foo as Bar,\n Baz\n }\n from 'x';",
        "export { \nFoo as Bar,\n Baz\n, }\n from 'x';",
        "export { Foo,\n Bar as Baz\n }\n from 'x';",
        "export { Foo,\n Bar as Baz,\n }\n from 'x';",
        "export { Foo as Bar,\n Baz as Qux\n }\n from 'x';",
        "export { Foo as Bar,\n Baz as Qux,\n }\n from 'x';",
        "export { Foo,\n Bar,\n Baz }\n from 'x';",
        "export { Foo,\n Bar,\n Baz,\n }\n from 'x';",
        "export { Foo as Bar,\n Baz,\n Qux\n }\n from 'x';",
        "export { Foo as Bar,\n Baz,\n Qux,\n }\n from 'x';",
        "export { Foo,\n Bar as Baz,\n Qux\n }\n from 'x';",
        "export { Foo,\n Bar as Baz,\n Qux,\n }\n from 'x';",
        "export { Foo,\n Bar,\n Baz as Qux\n }\n from 'x';",
        "export { Foo,\n Bar,\n Baz as Qux,\n }\n from 'x';",
        "export { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'x';",
        "export { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'x';",
        "export { Foo as Bar,\n Baz,\n Qux as Norf\n }\n from 'x';",
        "export { Foo as Bar,\n Baz,\n Qux as Norf,\n }\n from 'x';",
        "export { Foo,\n Bar as Baz,\n Qux as Norf\n }\n from 'x';",
        "export { Foo,\n Bar as Baz,\n Qux as Norf,\n }\n from 'x';",
        "export { Foo as Bar,\n Baz as Qux,\n Norf as Enuf\n }\n from 'x';",
        "export { Foo as Bar,\n Baz as Qux,\n Norf as Enuf,\n }\n from 'x';",
        "export Default,\n * as All from 'x';",
        "export Default,\n { } from 'x';",
        "export Default,\n { Foo\n }\n from 'x';",
        "export Default,\n { Foo,\n }\n from 'x';",
        "export Default,\n { Foo as Bar\n }\n from 'x';",
        "export Default,\n { Foo as Bar,\n }\n from 'x';",
        "export Default,\n { Foo,\n Bar\n } from\n 'x';",
        "export Default,\n { Foo,\n Bar,\n } from\n 'x';",
        "export Default,\n { Foo as Bar,\n Baz\n }\n from 'x';",
        "export Default,\n { Foo as Bar,\n Baz,\n }\n from 'x';",
        "export Default,\n { Foo,\n Bar as Baz\n }\n from 'x';",
        "export Default,\n { Foo,\n Bar as Baz,\n }\n from 'x';",
        "export Default,\n { Foo as Bar,\n Baz as Qux\n }\n from 'x';",
        "export Default,\n { Foo as Bar,\n Baz as Qux,\n }\n from 'x';",
        "export Default,\n { Foo,\n Bar,\n Baz\n }\n from 'x';",
        "export Default,\n { Foo,\n Bar,\n Baz,\n }\n from 'x';",
        "export Default,\n { Foo as Bar,\n Baz,\n Qux\n }\n from 'x';",
        "export Default,\n { Foo as Bar,\n Baz,\n Qux,\n }\n from 'x';",
        "export Default,\n { Foo,\n Bar as Baz,\n Qux\n }\n from 'x';",
        "export Default,\n { Foo,\n Bar as Baz,\n Qux,\n }\n from 'x';",
        "export Default,\n { Foo,\n Bar,\n Baz as Qux\n }\n from 'x';",
        "export Default,\n { Foo,\n Bar,\n Baz as Qux,\n }\n from 'x';",
        "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'x';",
        "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'x';",
        "export Default,\n { Foo as Bar,\n Baz,\n Qux as Norf }\n from 'x';",
        "export Default,\n { Foo as Bar,\n Baz,\n Qux as Norf, }\n from 'x';",
        "export Default,\n { Foo, Bar as Baz,\n Qux as Norf }\n from 'x';",
        "export Default,\n { Foo, Bar as Baz,\n Qux as Norf, }\n from 'x';",
        "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore\n }\n from 'x';",
        "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore,\n }\n from 'x';",
        "export Default\n , { } from 'x';",
        // require
        'require("x")',
        'require("y")',
        'require( \'z\' )',
        'require( "a")',
        'require("b" )',
      ].join('\n');
      /*eslint-disable */

      const module = createModule('test module', ['x', 'y']);

      const resolutionResponse = new ResolutionResponseMock({
        dependencies: [module],
        mainModuleId: 'test module',
        asyncDependencies: [],
      });

      resolutionResponse.getResolvedDependencyPairs = (module) => {
        return [
          ['x', createModule('changed')],
          ['y', createModule('Y')],
        ];
      }

      return depResolver.wrapModule(
        resolutionResponse,
        createModule('test module', ['x', 'y']),
        code
      ).then(processedCode => {
        expect(processedCode.name).toEqual('test module');
        expect(processedCode.code).toEqual([
          '__d(\'test module\',function(global, require,' +
            ' module, exports) {  ' +
            // single line import
            "import'x';",
          "import 'changed';",
          "import 'changed' ;",
          "import Default from 'changed';",
          "import * as All from 'changed';",
          "import {} from 'changed';",
          "import { } from 'changed';",
          "import {Foo} from 'changed';",
          "import { Foo } from 'changed';",
          "import { Foo, } from 'changed';",
          "import {Foo as Bar} from 'changed';",
          "import { Foo as Bar } from 'changed';",
          "import { Foo as Bar, } from 'changed';",
          "import { Foo, Bar } from 'changed';",
          "import { Foo, Bar, } from 'changed';",
          "import { Foo as Bar, Baz } from 'changed';",
          "import { Foo as Bar, Baz, } from 'changed';",
          "import { Foo, Bar as Baz } from 'changed';",
          "import { Foo, Bar as Baz, } from 'changed';",
          "import { Foo as Bar, Baz as Qux } from 'changed';",
          "import { Foo as Bar, Baz as Qux, } from 'changed';",
          "import { Foo, Bar, Baz } from 'changed';",
          "import { Foo, Bar, Baz, } from 'changed';",
          "import { Foo as Bar, Baz, Qux } from 'changed';",
          "import { Foo as Bar, Baz, Qux, } from 'changed';",
          "import { Foo, Bar as Baz, Qux } from 'changed';",
          "import { Foo, Bar as Baz, Qux, } from 'changed';",
          "import { Foo, Bar, Baz as Qux } from 'changed';",
          "import { Foo, Bar, Baz as Qux, } from 'changed';",
          "import { Foo as Bar, Baz as Qux, Norf } from 'changed';",
          "import { Foo as Bar, Baz as Qux, Norf, } from 'changed';",
          "import { Foo as Bar, Baz, Qux as Norf } from 'changed';",
          "import { Foo as Bar, Baz, Qux as Norf, } from 'changed';",
          "import { Foo, Bar as Baz, Qux as Norf } from 'changed';",
          "import { Foo, Bar as Baz, Qux as Norf, } from 'changed';",
          "import { Foo as Bar, Baz as Qux, Norf as Enuf } from 'changed';",
          "import { Foo as Bar, Baz as Qux, Norf as Enuf, } from 'changed';",
          "import Default, * as All from 'changed';",
          "import Default, { } from 'changed';",
          "import Default, { Foo } from 'changed';",
          "import Default, { Foo, } from 'changed';",
          "import Default, { Foo as Bar } from 'changed';",
          "import Default, { Foo as Bar, } from 'changed';",
          "import Default, { Foo, Bar } from 'changed';",
          "import Default, { Foo, Bar, } from 'changed';",
          "import Default, { Foo as Bar, Baz } from 'changed';",
          "import Default, { Foo as Bar, Baz, } from 'changed';",
          "import Default, { Foo, Bar as Baz } from 'changed';",
          "import Default, { Foo, Bar as Baz, } from 'changed';",
          "import Default, { Foo as Bar, Baz as Qux } from 'changed';",
          "import Default, { Foo as Bar, Baz as Qux, } from 'changed';",
          "import Default, { Foo, Bar, Baz } from 'changed';",
          "import Default, { Foo, Bar, Baz, } from 'changed';",
          "import Default, { Foo as Bar, Baz, Qux } from 'changed';",
          "import Default, { Foo as Bar, Baz, Qux, } from 'changed';",
          "import Default, { Foo, Bar as Baz, Qux } from 'changed';",
          "import Default, { Foo, Bar as Baz, Qux, } from 'changed';",
          "import Default, { Foo, Bar, Baz as Qux } from 'changed';",
          "import Default, { Foo, Bar, Baz as Qux, } from 'changed';",
          "import Default, { Foo as Bar, Baz as Qux, Norf } from 'changed';",
          "import Default, { Foo as Bar, Baz as Qux, Norf, } from 'changed';",
          "import Default, { Foo as Bar, Baz, Qux as Norf } from 'changed';",
          "import Default, { Foo as Bar, Baz, Qux as Norf, } from 'changed';",
          "import Default, { Foo, Bar as Baz, Qux as Norf } from 'changed';",
          "import Default, { Foo, Bar as Baz, Qux as Norf, } from 'changed';",
          "import Default, { Foo as Bar, Baz as Qux, Norf as NoMore } from 'changed';",
          "import Default, { Foo as Bar, Baz as Qux, Norf as NoMore, } from 'changed';",
          "import Default , { } from 'changed';",
          'import "changed";',
          'import Default from "changed";',
          'import * as All from "changed";',
          'import { } from "changed";',
          'import { Foo } from "changed";',
          'import { Foo, } from "changed";',
          'import { Foo as Bar } from "changed";',
          'import { Foo as Bar, } from "changed";',
          'import { Foo, Bar } from "changed";',
          'import { Foo, Bar, } from "changed";',
          'import { Foo as Bar, Baz } from "changed";',
          'import { Foo as Bar, Baz, } from "changed";',
          'import { Foo, Bar as Baz } from "changed";',
          'import { Foo, Bar as Baz, } from "changed";',
          'import { Foo as Bar, Baz as Qux } from "changed";',
          'import { Foo as Bar, Baz as Qux, } from "changed";',
          'import { Foo, Bar, Baz } from "changed";',
          'import { Foo, Bar, Baz, } from "changed";',
          'import { Foo as Bar, Baz, Qux } from "changed";',
          'import { Foo as Bar, Baz, Qux, } from "changed";',
          'import { Foo, Bar as Baz, Qux } from "changed";',
          'import { Foo, Bar as Baz, Qux, } from "changed";',
          'import { Foo, Bar, Baz as Qux } from "changed";',
          'import { Foo, Bar, Baz as Qux, } from "changed";',
          'import { Foo as Bar, Baz as Qux, Norf } from "changed";',
          'import { Foo as Bar, Baz as Qux, Norf, } from "changed";',
          'import { Foo as Bar, Baz, Qux as Norf } from "changed";',
          'import { Foo as Bar, Baz, Qux as Norf, } from "changed";',
          'import { Foo, Bar as Baz, Qux as Norf } from "changed";',
          'import { Foo, Bar as Baz, Qux as Norf, } from "changed";',
          'import { Foo as Bar, Baz as Qux, Norf as NoMore } from "changed";',
          'import { Foo as Bar, Baz as Qux, Norf as NoMore, } from "changed";',
          'import Default, * as All from "changed";',
          'import Default, { } from "changed";',
          'import Default, { Foo } from "changed";',
          'import Default, { Foo, } from "changed";',
          'import Default, { Foo as Bar } from "changed";',
          'import Default, { Foo as Bar, } from "changed";',
          'import Default, { Foo, Bar } from "changed";',
          'import Default, { Foo, Bar, } from "changed";',
          'import Default, { Foo as Bar, Baz } from "changed";',
          'import Default, { Foo as Bar, Baz, } from "changed";',
          'import Default, { Foo, Bar as Baz } from "changed";',
          'import Default, { Foo, Bar as Baz, } from "changed";',
          'import Default, { Foo as Bar, Baz as Qux } from "changed";',
          'import Default, { Foo as Bar, Baz as Qux, } from "changed";',
          'import Default, { Foo, Bar, Baz } from "changed";',
          'import Default, { Foo, Bar, Baz, } from "changed";',
          'import Default, { Foo as Bar, Baz, Qux } from "changed";',
          'import Default, { Foo as Bar, Baz, Qux, } from "changed";',
          'import Default, { Foo, Bar as Baz, Qux } from "changed";',
          'import Default, { Foo, Bar as Baz, Qux, } from "changed";',
          'import Default, { Foo, Bar, Baz as Qux } from "changed";',
          'import Default, { Foo, Bar, Baz as Qux, } from "changed";',
          'import Default, { Foo as Bar, Baz as Qux, Norf } from "changed";',
          'import Default, { Foo as Bar, Baz as Qux, Norf, } from "changed";',
          'import Default, { Foo as Bar, Baz, Qux as Norf } from "changed";',
          'import Default, { Foo as Bar, Baz, Qux as Norf, } from "changed";',
          'import Default, { Foo, Bar as Baz, Qux as Norf } from "changed";',
          'import Default, { Foo, Bar as Baz, Qux as Norf, } from "changed";',
          'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf } from "changed";',
          'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "changed";',
          'import Default from "Y";',
          'import * as All from \'z\';',
          // import with support for new lines
          "import { Foo,\n Bar }\n from 'changed';",
          "import { \nFoo,\nBar,\n }\n from 'changed';",
          "import { Foo as Bar,\n Baz\n }\n from 'changed';",
          "import { \nFoo as Bar,\n Baz\n, }\n from 'changed';",
          "import { Foo,\n Bar as Baz\n }\n from 'changed';",
          "import { Foo,\n Bar as Baz,\n }\n from 'changed';",
          "import { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",
          "import { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",
          "import { Foo,\n Bar,\n Baz }\n from 'changed';",
          "import { Foo,\n Bar,\n Baz,\n }\n from 'changed';",
          "import { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",
          "import { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",
          "import { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",
          "import { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",
          "import { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",
          "import { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",
          "import { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",
          "import { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",
          "import { Foo as Bar,\n Baz,\n Qux as Norf\n }\n from 'changed';",
          "import { Foo as Bar,\n Baz,\n Qux as Norf,\n }\n from 'changed';",
          "import { Foo,\n Bar as Baz,\n Qux as Norf\n }\n from 'changed';",
          "import { Foo,\n Bar as Baz,\n Qux as Norf,\n }\n from 'changed';",
          "import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf\n }\n from 'changed';",
          "import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf,\n }\n from 'changed';",
          "import Default,\n * as All from 'changed';",
          "import Default,\n { } from 'changed';",
          "import Default,\n { Foo\n }\n from 'changed';",
          "import Default,\n { Foo,\n }\n from 'changed';",
          "import Default,\n { Foo as Bar\n }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n }\n from 'changed';",
          "import Default,\n { Foo,\n Bar\n } from\n 'changed';",
          "import Default,\n { Foo,\n Bar,\n } from\n 'changed';",
          "import Default,\n { Foo as Bar,\n Baz\n }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n Baz,\n }\n from 'changed';",
          "import Default,\n { Foo,\n Bar as Baz\n }\n from 'changed';",
          "import Default,\n { Foo,\n Bar as Baz,\n }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",
          "import Default,\n { Foo,\n Bar,\n Baz\n }\n from 'changed';",
          "import Default,\n { Foo,\n Bar,\n Baz,\n }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",
          "import Default,\n { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",
          "import Default,\n { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",
          "import Default,\n { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",
          "import Default,\n { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf, }\n from 'changed';",
          "import Default,\n { Foo, Bar as Baz,\n Qux as Norf }\n from 'changed';",
          "import Default,\n { Foo, Bar as Baz,\n Qux as Norf, }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore\n }\n from 'changed';",
          "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore,\n }\n from 'changed';",
          "import Default\n , { } from 'changed';",
          // single line export
          "export'x';",
          "export 'changed';",
          "export 'changed' ;",
          "export Default from 'changed';",
          "export * as All from 'changed';",
          "export {} from 'changed';",
          "export { } from 'changed';",
          "export {Foo} from 'changed';",
          "export { Foo } from 'changed';",
          "export { Foo, } from 'changed';",
          "export {Foo as Bar} from 'changed';",
          "export { Foo as Bar } from 'changed';",
          "export { Foo as Bar, } from 'changed';",
          "export { Foo, Bar } from 'changed';",
          "export { Foo, Bar, } from 'changed';",
          "export { Foo as Bar, Baz } from 'changed';",
          "export { Foo as Bar, Baz, } from 'changed';",
          "export { Foo, Bar as Baz } from 'changed';",
          "export { Foo, Bar as Baz, } from 'changed';",
          "export { Foo as Bar, Baz as Qux } from 'changed';",
          "export { Foo as Bar, Baz as Qux, } from 'changed';",
          "export { Foo, Bar, Baz } from 'changed';",
          "export { Foo, Bar, Baz, } from 'changed';",
          "export { Foo as Bar, Baz, Qux } from 'changed';",
          "export { Foo as Bar, Baz, Qux, } from 'changed';",
          "export { Foo, Bar as Baz, Qux } from 'changed';",
          "export { Foo, Bar as Baz, Qux, } from 'changed';",
          "export { Foo, Bar, Baz as Qux } from 'changed';",
          "export { Foo, Bar, Baz as Qux, } from 'changed';",
          "export { Foo as Bar, Baz as Qux, Norf } from 'changed';",
          "export { Foo as Bar, Baz as Qux, Norf, } from 'changed';",
          "export { Foo as Bar, Baz, Qux as Norf } from 'changed';",
          "export { Foo as Bar, Baz, Qux as Norf, } from 'changed';",
          "export { Foo, Bar as Baz, Qux as Norf } from 'changed';",
          "export { Foo, Bar as Baz, Qux as Norf, } from 'changed';",
          "export { Foo as Bar, Baz as Qux, Norf as Enuf } from 'changed';",
          "export { Foo as Bar, Baz as Qux, Norf as Enuf, } from 'changed';",
          "export Default, * as All from 'changed';",
          "export Default, { } from 'changed';",
          "export Default, { Foo } from 'changed';",
          "export Default, { Foo, } from 'changed';",
          "export Default, { Foo as Bar } from 'changed';",
          "export Default, { Foo as Bar, } from 'changed';",
          "export Default, { Foo, Bar } from 'changed';",
          "export Default, { Foo, Bar, } from 'changed';",
          "export Default, { Foo as Bar, Baz } from 'changed';",
          "export Default, { Foo as Bar, Baz, } from 'changed';",
          "export Default, { Foo, Bar as Baz } from 'changed';",
          "export Default, { Foo, Bar as Baz, } from 'changed';",
          "export Default, { Foo as Bar, Baz as Qux } from 'changed';",
          "export Default, { Foo as Bar, Baz as Qux, } from 'changed';",
          "export Default, { Foo, Bar, Baz } from 'changed';",
          "export Default, { Foo, Bar, Baz, } from 'changed';",
          "export Default, { Foo as Bar, Baz, Qux } from 'changed';",
          "export Default, { Foo as Bar, Baz, Qux, } from 'changed';",
          "export Default, { Foo, Bar as Baz, Qux } from 'changed';",
          "export Default, { Foo, Bar as Baz, Qux, } from 'changed';",
          "export Default, { Foo, Bar, Baz as Qux } from 'changed';",
          "export Default, { Foo, Bar, Baz as Qux, } from 'changed';",
          "export Default, { Foo as Bar, Baz as Qux, Norf } from 'changed';",
          "export Default, { Foo as Bar, Baz as Qux, Norf, } from 'changed';",
          "export Default, { Foo as Bar, Baz, Qux as Norf } from 'changed';",
          "export Default, { Foo as Bar, Baz, Qux as Norf, } from 'changed';",
          "export Default, { Foo, Bar as Baz, Qux as Norf } from 'changed';",
          "export Default, { Foo, Bar as Baz, Qux as Norf, } from 'changed';",
          "export Default, { Foo as Bar, Baz as Qux, Norf as NoMore } from 'changed';",
          "export Default, { Foo as Bar, Baz as Qux, Norf as NoMore, } from 'changed';",
          "export Default , { } from 'changed';",
          'export "changed";',
          'export Default from "changed";',
          'export * as All from "changed";',
          'export { } from "changed";',
          'export { Foo } from "changed";',
          'export { Foo, } from "changed";',
          'export { Foo as Bar } from "changed";',
          'export { Foo as Bar, } from "changed";',
          'export { Foo, Bar } from "changed";',
          'export { Foo, Bar, } from "changed";',
          'export { Foo as Bar, Baz } from "changed";',
          'export { Foo as Bar, Baz, } from "changed";',
          'export { Foo, Bar as Baz } from "changed";',
          'export { Foo, Bar as Baz, } from "changed";',
          'export { Foo as Bar, Baz as Qux } from "changed";',
          'export { Foo as Bar, Baz as Qux, } from "changed";',
          'export { Foo, Bar, Baz } from "changed";',
          'export { Foo, Bar, Baz, } from "changed";',
          'export { Foo as Bar, Baz, Qux } from "changed";',
          'export { Foo as Bar, Baz, Qux, } from "changed";',
          'export { Foo, Bar as Baz, Qux } from "changed";',
          'export { Foo, Bar as Baz, Qux, } from "changed";',
          'export { Foo, Bar, Baz as Qux } from "changed";',
          'export { Foo, Bar, Baz as Qux, } from "changed";',
          'export { Foo as Bar, Baz as Qux, Norf } from "changed";',
          'export { Foo as Bar, Baz as Qux, Norf, } from "changed";',
          'export { Foo as Bar, Baz, Qux as Norf } from "changed";',
          'export { Foo as Bar, Baz, Qux as Norf, } from "changed";',
          'export { Foo, Bar as Baz, Qux as Norf } from "changed";',
          'export { Foo, Bar as Baz, Qux as Norf, } from "changed";',
          'export { Foo as Bar, Baz as Qux, Norf as NoMore } from "changed";',
          'export { Foo as Bar, Baz as Qux, Norf as NoMore, } from "changed";',
          'export Default, * as All from "changed";',
          'export Default, { } from "changed";',
          'export Default, { Foo } from "changed";',
          'export Default, { Foo, } from "changed";',
          'export Default, { Foo as Bar } from "changed";',
          'export Default, { Foo as Bar, } from "changed";',
          'export Default, { Foo, Bar } from "changed";',
          'export Default, { Foo, Bar, } from "changed";',
          'export Default, { Foo as Bar, Baz } from "changed";',
          'export Default, { Foo as Bar, Baz, } from "changed";',
          'export Default, { Foo, Bar as Baz } from "changed";',
          'export Default, { Foo, Bar as Baz, } from "changed";',
          'export Default, { Foo as Bar, Baz as Qux } from "changed";',
          'export Default, { Foo as Bar, Baz as Qux, } from "changed";',
          'export Default, { Foo, Bar, Baz } from "changed";',
          'export Default, { Foo, Bar, Baz, } from "changed";',
          'export Default, { Foo as Bar, Baz, Qux } from "changed";',
          'export Default, { Foo as Bar, Baz, Qux, } from "changed";',
          'export Default, { Foo, Bar as Baz, Qux } from "changed";',
          'export Default, { Foo, Bar as Baz, Qux, } from "changed";',
          'export Default, { Foo, Bar, Baz as Qux } from "changed";',
          'export Default, { Foo, Bar, Baz as Qux, } from "changed";',
          'export Default, { Foo as Bar, Baz as Qux, Norf } from "changed";',
          'export Default, { Foo as Bar, Baz as Qux, Norf, } from "changed";',
          'export Default, { Foo as Bar, Baz, Qux as Norf } from "changed";',
          'export Default, { Foo as Bar, Baz, Qux as Norf, } from "changed";',
          'export Default, { Foo, Bar as Baz, Qux as Norf } from "changed";',
          'export Default, { Foo, Bar as Baz, Qux as Norf, } from "changed";',
          'export Default, { Foo as Bar, Baz as Qux, Norf as Enuf } from "changed";',
          'export Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "changed";',
          'export Default from "Y";',
          'export * as All from \'z\';',
          // export with support for new lines
          "export { Foo,\n Bar }\n from 'changed';",
          "export { \nFoo,\nBar,\n }\n from 'changed';",
          "export { Foo as Bar,\n Baz\n }\n from 'changed';",
          "export { \nFoo as Bar,\n Baz\n, }\n from 'changed';",
          "export { Foo,\n Bar as Baz\n }\n from 'changed';",
          "export { Foo,\n Bar as Baz,\n }\n from 'changed';",
          "export { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",
          "export { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",
          "export { Foo,\n Bar,\n Baz }\n from 'changed';",
          "export { Foo,\n Bar,\n Baz,\n }\n from 'changed';",
          "export { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",
          "export { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",
          "export { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",
          "export { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",
          "export { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",
          "export { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",
          "export { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",
          "export { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",
          "export { Foo as Bar,\n Baz,\n Qux as Norf\n }\n from 'changed';",
          "export { Foo as Bar,\n Baz,\n Qux as Norf,\n }\n from 'changed';",
          "export { Foo,\n Bar as Baz,\n Qux as Norf\n }\n from 'changed';",
          "export { Foo,\n Bar as Baz,\n Qux as Norf,\n }\n from 'changed';",
          "export { Foo as Bar,\n Baz as Qux,\n Norf as Enuf\n }\n from 'changed';",
          "export { Foo as Bar,\n Baz as Qux,\n Norf as Enuf,\n }\n from 'changed';",
          "export Default,\n * as All from 'changed';",
          "export Default,\n { } from 'changed';",
          "export Default,\n { Foo\n }\n from 'changed';",
          "export Default,\n { Foo,\n }\n from 'changed';",
          "export Default,\n { Foo as Bar\n }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n }\n from 'changed';",
          "export Default,\n { Foo,\n Bar\n } from\n 'changed';",
          "export Default,\n { Foo,\n Bar,\n } from\n 'changed';",
          "export Default,\n { Foo as Bar,\n Baz\n }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n Baz,\n }\n from 'changed';",
          "export Default,\n { Foo,\n Bar as Baz\n }\n from 'changed';",
          "export Default,\n { Foo,\n Bar as Baz,\n }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",
          "export Default,\n { Foo,\n Bar,\n Baz\n }\n from 'changed';",
          "export Default,\n { Foo,\n Bar,\n Baz,\n }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",
          "export Default,\n { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",
          "export Default,\n { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",
          "export Default,\n { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",
          "export Default,\n { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n Baz,\n Qux as Norf }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n Baz,\n Qux as Norf, }\n from 'changed';",
          "export Default,\n { Foo, Bar as Baz,\n Qux as Norf }\n from 'changed';",
          "export Default,\n { Foo, Bar as Baz,\n Qux as Norf, }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore\n }\n from 'changed';",
          "export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore,\n }\n from 'changed';",
          "export Default\n , { } from 'changed';",
          // require
          'require("changed")',
          'require("Y")',
          'require( \'z\' )',
          'require( "a")',
          'require("b" )',
          '});',
        ].join('\n'));
      });
    });

    pit('should resolve polyfills', function () {
      const depResolver = new Resolver({
        projectRoot: '/root',
      });
      const polyfill = createPolyfill('test polyfill', []);
      const code = [
        'global.fetch = () => 1;',
      ].join('');
      return depResolver.wrapModule(
        null,
        polyfill,
        code
      ).then(processedCode => {
        expect(processedCode.code).toEqual([
          '(function(global) {',
          'global.fetch = () => 1;',
          "\n})(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this);",
        ].join(''));
      });
    });
  });
});


text:
package es.tid.rsvp.objects.subobjects;

/**
 * Represents a ERO Subobject with the OBS Label defined in MAINS.
 * @author ogondio
 *
 */
public class OBSMAINSLabelEROSubobject extends LabelEROSubobject {

	byte[] label;

	public OBSMAINSLabelEROSubobject(){
		super();
		this.setCtype(SubObjectValues.ERO_SUBOBJECT_LABEL_CTYPE_OBS_MAINS_LABEL);
	}

	public OBSMAINSLabelEROSubobject(byte []bytes, int offset){
		super(bytes, offset);
		decode();
	}

	public void encode() {
		this.setErosolength(4+label.length);
		this.subobject_bytes=new byte[this.erosolength];
		this.setCtype(SubObjectValues.ERO_SUBOBJECT_LABEL_CTYPE_OBS_MAINS_LABEL);
		this.encodeLabelHeader();
		this.encodeSoHeader();
		System.arraycopy(this.label, 0, this.subobject_bytes, 4, this.label.length);

	}

	public void decode() {
		int labelLength=this.getErosolength()-4;
		label=new byte[labelLength];
		System.arraycopy(this.getSubobject_bytes(), 4, label, 0, labelLength);

	}

	public byte[] getLabel() {
		return label;
	}

	public void setLabel(byte[] label) {
		this.label = label;
	}

	public String toString(){
		String resp="/ELC: OBS Label";
		return resp;
	}

}

redpajama_set_name: RedPajamaGithub


text:
<?php
class alsopurchased_widgetView extends view {
    public function fieldsProducts($fields) {
        $fields .= ', '. frame::_()->getTable('products')->getTable(true). '.price';
        return $fields;
    }
    public function display($instance) {
        global $post;
        if(!empty($post) && !empty($post->ID) && $post->post_type == S_PRODUCT) {
            frame::_()->getTable('orders_items')->groupBy('product_id');
            $alsoPurchasedPids = frame::_()->getTable('orders_items')->get(
                    'product_id',
                    'order_id IN (SELECT order_id FROM '. frame::_()->getTable('orders_items')->getTable(). ' WHERE product_id = '. $post->ID. ') AND product_id != '. (int) $post->ID,
                    '',
                    'col');
            if(!empty($alsoPurchasedPids)) {
                $instance['number_of_products'] = (int) $instance['number_of_products'];
                $query = array('post_type' => S_PRODUCT, 'post__in' => $alsoPurchasedPids);
                if($instance['number_of_products']) {
                    $query['posts_per_page'] = $instance['number_of_products'];
                } else {
                    $query['nopaging'] = 1;
                }
                add_filter('posts_fields_request', array($this, 'fieldsProducts'));
                $queryObj = new WP_Query($query);
                $posts = $queryObj->get_posts();
                remove_filter('posts_fields_request', array($this, 'fieldsProducts'));
                foreach ($posts as $post) {
                    $product = array(
                        'price' => frame::_()->getModule('products')->getView()->getPrice($item['post_id'], $post->price),
                        'description' => $post->post_excerpt,
                        'title' => $post->post_title,
                        'image' => frame::_()->getModule('products')->getView()->getProductImage($post, true, false, 'all', 'catt'),
                        'productID' => $post->ID,
                        'guid' => get_permalink($post),
                        'actionButtons' => $this->addToCart($post),
                        'productContentAfter' => dispatcher::applyFilters('productContentAfter', '', $post),
                        'ratingBox' => dispatcher::applyFilters('productRating', '', $post),
						'sku' => $post->sku,
						'post' => $post,
                    );
                    $products[] = $product;
                }
                $this->assign('products', $products);
                $this->assign('uniqID', mt_rand(1, 99999));
                $this->assign('params', $instance);
                parent::display('list');
            }
        }
    }
    public function displayForm($data, $widget) {
        $this->displayWidgetForm($data, $widget);
    }
    public function addToCart($post) {
		// Ajax adding to cart
		$this->assign('post', $post);
		return dispatcher::applyFilters('prodActionButons', parent::getContent('addToCartBtn'), $post->ID, $post);
        //$output = ' $post->ID)).'">'.lang::_('Add').'';	//Old non-ajax way add to cart action
        //return $output;
    }
}
?>


text:
===========
ahps_alerts
===========

.. image:: https://img.shields.io/pypi/v/ahps_alerts.svg
        :target: https://pypi.python.org/pypi/ahps_alerts

.. image:: https://img.shields.io/travis/DavidHickman/ahps_alerts.svg
        :target: https://travis-ci.org/DavidHickman/ahps_alerts

.. image:: https://readthedocs.org/projects/ahps-alerts/badge/?version=latest
        :target: https://ahps-alerts.readthedocs.io/en/latest/?badge=latest
        :alt: Documentation Status

.. image:: https://pyup.io/repos/github/DavidHickman/ahps_alerts/shield.svg
     :target: https://pyup.io/repos/github/DavidHickman/ahps_alerts/
     :alt: Updates

Retrieve NWS AHPS alerts

* Free software: MIT license
* Documentation: https://ahps-alerts.readthedocs.io.

Features
--------

* TODO

Credits
---------

This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage


text:
package se.simonsoft.cms.indexing.xml.solr;

import java.time.Duration;
import java.time.Instant;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrQuery.ORDER;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.MessageFormatter;

import se.repos.indexing.IndexingDoc;
import se.repos.indexing.solrj.SolrAdd;
import se.repos.indexing.solrj.SolrDelete;
import se.repos.indexing.solrj.SolrDeleteByQuery;
import se.repos.indexing.solrj.SolrQueryOp;
import se.repos.indexing.twophases.IndexingDocIncrementalSolrj;
import se.simonsoft.cms.indexing.xml.XmlIndexAddSession;
import se.simonsoft.cms.indexing.xml.XmlIndexWriter;
import se.simonsoft.cms.indexing.xml.fields.XmlIndexIdAppendDepthFirstPosition;
import se.simonsoft.cms.item.CmsRepository;
import se.simonsoft.cms.item.events.change.CmsChangesetItem;

public class XmlIndexWriterSolrj implements Provider<XmlIndexAddSession>, XmlIndexWriter {

//	private static final long BATCH_SIZE_MAX = 500; // This is a quick fix for avoiding "java.lang.OutOfMemoryError: Java heap space" without really analyzing the problem. 1500 and above has proved too large.
//	// The occurrence of the above error might be because of text size, so resurrecting the old text length count could be a good idea.

	/**
	 * As element size varies a lot due to source and text indexing we can
	 * try to keep reasonably small batches by also checking total text+source length,
	 * triggering batchReady if above a certain limit instead of waiting for the number of elements.
	 */
	// Tests indicate that with a 300MB heap, the performance is optimal around 500 kB batch size.
	private static final long BATCH_TEXT_TOTAL_MAX = 500 * 1000;

	// Limit triggering logging of large element. Should likely be in range 4000-10000.
	private static final long SIZE_INFO_ABOVE = 8000;

	private static final Logger logger = LoggerFactory.getLogger(XmlIndexWriterSolrj.class);

	private SolrClient solrServer;

	private static final int ELEMENT_ID_LENGTH = XmlIndexIdAppendDepthFirstPosition.getElementId(1).length();
	private static final int DELETE_PAGE_SIZE = 1000;
	public static boolean deleteByQueryAllowed = true; // Used by testing to ensure the efficient delete is used.

	@Inject
	public XmlIndexWriterSolrj(@Named("reposxml") SolrClient core) {
		this.solrServer = core;
	}

	@Override
	public XmlIndexAddSession get() {
		return new Session();
	}

	protected void batchSend(Session session) {

		Collection<SolrInputDocument> pending = session.rotatePending();
		if (pending.size() == 0) {
			logger.warn("Send to solr attempted with empty document list");
			return;
		}
		logger.info("Sending {} elements size {} to Solr starting with id {}", pending.size(), session.sizeContentTotal(), pending.iterator().next().getFieldValue("id"));
		doBatchSend(pending);
	}

	protected void doBatchSend(Collection<SolrInputDocument> pending) {
		new SolrAdd(solrServer, pending).run();
	}

	protected void sessionEnd(Session session) {
		batchSend(session);
	}

	public void deletePath(CmsRepository repository, CmsChangesetItem c) {
		// Query for the id as well as number of elements.
		SolrQuery query = getDeleteQuery(repository, c);
		QueryResponse existing = new SolrQueryOp(solrServer, query).run();

		long count = existing.getResults().getNumFound();
		if (count == 0) {
			// TODO: Consider adding placeholder item for overwritten items and deletePathByQuery().
			logger.warn("No previous docs to delete (normal during batch indexing): {}", c);
			return;
		}

		String id1Base = getIdBase(existing.getResults().get(0), c);

		if (count > 1) {
			// Should have 2 rows in the response.
			// Would be a strange situation if they are from different revisions (using sort on depth).
			// Indicates that earlier delete operation has failed.
			String id2Base = getIdBase(existing.getResults().get(1), c);
			if (!id2Base.equals(id1Base)) {
				logger.warn("Delete query provided multiple revisions in reposxml: {}.. - {}..", id1Base, id2Base);
				deletePathByQuery(repository, c);
				return;
			}
		}
		logger.info("Deleting previous revision ({} docs): {}", count, id1Base);
		deleteIds(id1Base, count);
		logger.info("Deleted previous revision ({} docs): {}", count, id1Base);
	}

	/**
	 * @param idBase with separator '|'
	 * @param count number of elements, starting at 1.
	 */
	private void deleteIds(String idBase, long count) {
		// Paged delete for large documents, reverse order.
		// Not bothering with partial last page.
		Instant start = Instant.now();
		long pages = (count / DELETE_PAGE_SIZE) + 1; // Adding one page for the division remainder.
		for (long i = (pages-1); i >= 0 ; i--) { // Reverse to ensure that depth=1 is deleted last.
			deleteIdPage(idBase, i);
		}
		// TODO: Change to debug level
		Instant end = Instant.now();
		logger.info("Deleted previous revision ({} pages) in {} ms: {}", pages, Duration.between(start, end).toMillis(), idBase);
	}

	private void deleteIdPage(String idBase, long page) {
		LinkedList<String> ids = new LinkedList<>();
		for (long i = DELETE_PAGE_SIZE * page; i <= DELETE_PAGE_SIZE * (page+1) ; i++) { // overlap one
			ids.add(idBase + XmlIndexIdAppendDepthFirstPosition.getElementId(i));
		}
		new SolrDelete(solrServer, ids).run();
	}

	public static SolrQuery getDeleteQuery(CmsRepository repository, CmsChangesetItem c) {
		String pathfull = getPathFull(repository, c);
		SolrQuery query = new SolrQuery("pathfull:"+ quote(pathfull));
		// Ensure that the first element of multiple revisions are returned (if there are previous delete failures).
		query = query.addSort("depth", ORDER.asc); // Do NOT add a revision sort with higher priority.
		query = query.setFields("id");
		query = query.setRows(2); // Validating that 2 IDs relate to the same document revision.
		return query;
	}

	public static String getIdBase(SolrDocument fields, CmsChangesetItem c) {
		String id = (String) fields.getFieldValue("id");
		if (id == null || id.charAt(id.length() - ELEMENT_ID_LENGTH) == '|') {
			String msg = MessageFormatter.format("Delete query provided an illegal response: {} - {}", id, c).getMessage();
			logger.error(msg);
			throw new IllegalStateException(msg);
		}
		return id.substring(0, id.length() - ELEMENT_ID_LENGTH); // Keep the '|'.
	}

	private void deletePathByQuery(CmsRepository repository, CmsChangesetItem c) {
		// Keeping this method as fallback.
		logger.warn("Deleting previous revision using fallback to 'deleteByQuery' (slow): {}", c);
		if (!deleteByQueryAllowed) {
			throw new IllegalStateException("deleteByQuery is disabled by configuration");
		}

		// we can't use id to delete because it may contain revision, we could probably delete an exact item by hooking into the head=false update in item indexing
		// reposxml generates an unknown number of docs per cmsitem (at least for Release / Assist). Can not be deleted by a single ID.

		// DeleteByQuery turns out to be a significant performance issue, potentially more so in SolR 8 than SolR 4.
		// https://www.od-bits.com/2018/03/dbq-or-delete-by-query.html
		String pathfull = getPathFull(repository, c);
		String query = "pathfull:"+ quote(pathfull);
		logger.debug("Deleting previous revision of {} using query {}", c, query);
		new SolrDeleteByQuery(solrServer, query).run();
	}

	private static String getPathFull(CmsRepository repository, CmsChangesetItem c) {
		return repository.getPath() + c.getPath().toString();
	}

	@Override
	public void commit(boolean expungeDeletes) {

		// Unable to use retry in SolrOp unless this interface is changed.
		// Alternatively if the consumer of this interface would only use expungeDeletes after pure-delete changes.

		logger.warn("The per-document commit is now disabled.");
		//new SolrCommitExpunge(solrServer, expungeDeletes, false);
	}

	// Copied from QueryEscapeDefault in cms-reporting.
	public static String quote(String fieldValue) {
		return '"' + fieldValue.replace("\"", "\\\"") + '"';
	}

	class Session implements XmlIndexAddSession {

		private Collection<SolrInputDocument> pending = new LinkedList<SolrInputDocument>();

		private int contentSize = 0;

		@Override
		public void end() {
			sessionEnd(this);
		}

		private SolrInputDocument getSolrDoc(IndexingDoc doc) {
			if (doc instanceof IndexingDocIncrementalSolrj) {
				return ((IndexingDocIncrementalSolrj) doc).getSolrDoc();
			}
			throw new IllegalArgumentException("Unsupported IndexingDoc type " + doc.getClass());
		}

		public Collection<SolrInputDocument> rotatePending() {

			Collection<SolrInputDocument> returnPending = this.pending;
			pending = new LinkedList<SolrInputDocument>();
			return returnPending;
		}

		@Override
		public int size() {
			return pending.size();
		}

		@Override
		public int sizeContentTotal() {
			return contentSize;
		}

		private Entry<String, Integer> getLargestField(IndexingDoc e) {
			@SuppressWarnings("unused")
			final Set<String> largeCandidates = new HashSet<String>(Arrays.asList("id", "prop_abx.Dependencies", "source", "source_reuse"));
			// text is also large

			String name = null;
			int size = 0;
			for (String f : e.getFieldNames()) {
			//for (String f : largeCandidates) {
				int valSize = 0;
				Object val = e.getFieldValue(f);
				if (val instanceof String) {
					valSize = ((String) val).length();
				}
				if (valSize > size) {
					size = valSize;
					name = f;
				}
			}
			return new AbstractMap.SimpleEntry<String, Integer>(name, size);
		}

		@Override
		public boolean add(IndexingDoc e) {
			if (size() == 0) {
				contentSize = 0;
			}
			int s = e.getContentSize();
			if (s >= SIZE_INFO_ABOVE && ((Integer) e.getFieldValue("depth")) > 1) {
				Entry<String, Integer> l = getLargestField(e);
				logger.info("Large element '{}' {}, fields {}, total size {}, largest field {}:{}",
						new Object[] {e.getFieldValue("name"), e.getFieldValue("id"), e.size(), s, l.getKey(), l.getValue()});
			}
			if (!pending.add(getSolrDoc(e))) {
				throw new IllegalArgumentException("Doc add failed for " + e);
			}
			contentSize += s;
//TODO			// we have a rough measurement of total field size here and can trigger batch send to reduce risk of hitting memory limitations in webapp
//			if (batchTextTotal > BATCH_TEXT_TOTAL_MAX) {
//				logger.info("Sending batch because total source+text size {} indicates large update", batchTextTotal);
//				batchReady = true; // send batch
//				batchTextTotal = 0;
//			}
			if (contentSize >= BATCH_TEXT_TOTAL_MAX) {
				logger.info("Reached max batch add size {} after {} elements, forcing send to solr", BATCH_TEXT_TOTAL_MAX, pending.size());
				batchSend(this);
			}
			return true;
		}

		@Override
		public boolean addAll(Collection<? extends IndexingDoc> c) {
			boolean changed = false;
			for (IndexingDoc d : c) {
				changed = add(d) || changed;
			}
			return changed;
		}

		@Override
		public void clear() {
			throw new UnsupportedOperationException("Method not implemented for Solr add batch");
		}

		@Override
		public boolean contains(Object o) {
			throw new UnsupportedOperationException("Method not implemented for Solr add batch");
		}

		@Override
		public boolean containsAll(Collection<?> c) {
			throw new UnsupportedOperationException("Method not implemented for Solr add batch");
		}

		@Override
		public boolean isEmpty() {
			throw new UnsupportedOperationException("Method not implemented for Solr add batch");
		}

		@Override
		public Iterator<IndexingDoc> iterator() {
			throw new UnsupportedOperationException("Method not implemented for Solr add batch");
		}

		@Override
		public boolean remove(Object o) {
			throw new UnsupportedOperationException("Method not implemented for Solr add batch");
		}

		@Override
		public boolean removeAll(Collection<?> c) {
			throw new UnsupportedOperationException("Method not implemented for Solr add batch");
		}

		@Override
		public boolean retainAll(Collection<?> c) {
			throw new UnsupportedOperationException("Method not implemented for Solr add batch");
		}

		@Override
		public Object[] toArray() {
			throw new UnsupportedOperationException("Method not implemented for Solr add batch");
		}

		@Override
		public <T> T[] toArray(T[] a) {
			throw new UnsupportedOperationException("Method not implemented for Solr add batch");
		}

	}

}


text:
#ifndef Vca_VFilterDeviceFactory_Interface
#define Vca_VFilterDeviceFactory_Interface

/************************
 *****  Components  *****
 ************************/

#include "Vca_VRolePlayer.h"

/**************************
 *****  Declarations  *****
 **************************/

/*************************
 *****  Definitions  *****
 *************************/

namespace Vca {
    class IPipeSource;
    class IPipeSourceClient;
    class VDevice;

    class Vca_API VFilterDeviceFactory : public VRolePlayer {
	DECLARE_ABSTRACT_RTTLITE (VFilterDeviceFactory, VRolePlayer);

    //  Construction
    protected:
	VFilterDeviceFactory ();

    //  Destruction
    protected:
	~VFilterDeviceFactory ();

    //  Local Use
    protected:
	void supplyClient (IPipeSourceClient *pClient, VDevice *pDevice) const;
    };
}

#endif


text:
package org.apache.pojo.beaneditor.model.outline;

import org.apache.pojo.beaneditor.model.PBENodeValueMutator;

public class PBEOLeafNode extends PBEOAbstractNode {
    public PBEOLeafNode(String elemName, PBENodeValueMutator mutator, Object ctx) {
        super(elemName, mutator, ctx);
    }
}


text:
package org.spongepowered.common.mixin.api.minecraft.world.level.chunk;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.chunk.ChunkBiomeContainer;
import net.minecraft.world.level.chunk.ProtoChunk;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.entity.BlockEntity;
import org.spongepowered.api.util.PositionOutOfBoundsException;
import org.spongepowered.api.world.biome.Biome;
import org.spongepowered.api.world.generation.GenerationChunk;
import org.spongepowered.api.world.server.ServerLocation;
import org.spongepowered.api.world.volume.stream.StreamOptions;
import org.spongepowered.api.world.volume.stream.VolumeStream;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.common.data.holder.SpongeLocationBaseDataHolder;
import org.spongepowered.common.util.Constants;
import org.spongepowered.common.util.MissingImplementationException;
import org.spongepowered.common.world.storage.SpongeChunkLayout;
import org.spongepowered.math.vector.Vector3i;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

@Mixin(ProtoChunk.class)
public abstract class ProtoChunkMixin_API implements GenerationChunk, SpongeLocationBaseDataHolder {

    //@formatter:off
    @Shadow @javax.annotation.Nullable public abstract net.minecraft.world.level.block.state.BlockState shadow$setBlockState(final BlockPos param0,
            final net.minecraft.world.level.block.state.BlockState param1, final boolean param2);
    @Shadow public abstract Map<BlockPos, net.minecraft.world.level.block.entity.BlockEntity> shadow$getBlockEntities();
    @Shadow public abstract void shadow$setBlockEntity(final BlockPos param0, final net.minecraft.world.level.block.entity.BlockEntity param1);
    @Shadow public abstract void shadow$removeBlockEntity(final BlockPos param0);
    @Shadow @javax.annotation.Nullable private ChunkBiomeContainer biomes;
    //@formatter:on

    private @Nullable Vector3i api$blockMin;
    private @Nullable Vector3i api$blockMax;

    @Override
    public VolumeStream<GenerationChunk, Biome> biomeStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
        throw new UnsupportedOperationException("Cannot stream biomes on ProtoChunk");
    }

    @Override
    public VolumeStream<GenerationChunk, BlockState> blockStateStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
        throw new UnsupportedOperationException("Cannot stream block states on ProtoChunk");
    }

    @Override
    public VolumeStream<GenerationChunk, BlockEntity> blockEntityStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
        throw new UnsupportedOperationException("Cannot stream block entities on ProtoChunk");
    }

    @Override
    public Vector3i min() {
        if (this.api$blockMin == null) {
            this.api$blockMin = SpongeChunkLayout.INSTANCE.forceToWorld(this.chunkPosition());
        }
        return this.api$blockMin;
    }

    @Override
    public Vector3i max() {
        if (this.api$blockMax == null) {
            this.api$blockMax = this.min().add(SpongeChunkLayout.CHUNK_SIZE).sub(1, 1, 1);
        }
        return this.api$blockMax;
    }

    @Override
    public boolean setBlock(final int x, final int y, final int z, final BlockState block) {
        return false;
    }

    @Override
    public boolean removeBlock(final int x, final int y, final int z) {
        return false;
    }

    @Override
    public Collection<? extends BlockEntity> blockEntities() {
        return (Collection) Collections.unmodifiableCollection(this.shadow$getBlockEntities().values());
    }

    @Override
    public void addBlockEntity(final int x, final int y, final int z, final BlockEntity blockEntity) {
        this.shadow$setBlockEntity(new BlockPos(x, y, z), (net.minecraft.world.level.block.entity.BlockEntity) blockEntity);
    }

    @Override
    public void removeBlockEntity(final int x, final int y, final int z) {
        this.shadow$removeBlockEntity(new BlockPos(x, y, z));
    }

    @Override
    public Biome biome(int x, int y, int z) {
        if (!this.contains(x, y, z)) {
            throw new PositionOutOfBoundsException(new Vector3i(x, y, z), Constants.World.BLOCK_MIN, Constants.World.BLOCK_MAX);
        }
        if (this.biomes != null) {
            return (Biome) (Object) this.biomes.getNoiseBiome(x, y, z);
        }
        return null;
    }

    @Override
    public ServerLocation impl$dataholder(int x, int y, int z) {
        throw new MissingImplementationException("ProtoChunk", "impl$dataholder");
    }

}


text:
We love contributions from everyone.
By participating in this project, you agree to abide by our [code of conduct](https://github.com/ThatGuyHughesy/creddit/blob/master/CODE_OF_CONDUCT.md).

We expect everyone to follow the code of conduct throughout Creddit, from the project's codebase to issue trackers.

## Contributing Code

Fork the repo.

When adding a new function/feature, please follow this checklist before submitting a pull request:

1) Test your code and ensure all tests are passing.

2) Update the README.md documentation.

3) [Squash your commits](https://git-scm.com/docs/git-rebase#_interactive_mode).


text:
layout: post
title: "Día 11: Enslaved — Slaget I Skogen Bortenfor"
---

*De los lejanos páramos llegaron a batallar.
El epílogo fue en las estrellas, retornando al ciclo infinito, para volver a empezar a escribir la historia.*

Enslaved es la banda de bandas, mi ingreso definitivo al black metal como género musical y el posterior involucramiento a un mundo nuevo, donde la filosofía alrededor de la vida y muerte son hechos cíclicos y la trascendencia van de la mano con la identidad. Definitivamente uno de mis favoritos.

## Día 11/28:

![Portada del Álbum](/images/enslaved-hordanesland.jpg)

**Álbum:** Hordanes Land
**Año:** 1993
**Sello:** Candlelight Records

**Enslaved** es una fuerza fundamental de la naturaleza en Noruega, Enslaved es una banda que tomó los pasajes de las *Eddas* vikingas y lo trasladaron a épicos pasajes musicales desde el principio de los 90's.

Referentes de Emperor cuando lanzaron el split conjunto *Hordanes Land/Emperor*, Emperor aún buscaba un sonido propio, mientras Enslaved mostraba signos de saber lo que irían a hacer por varios años a continuación.

Con menos de 20 años en el cuerpo, Grutle Kjellson e Ivar Bjørnson, con 17 y 13 años respectivamente, formularon una combinación que nace de las raíces del death metal sueco, sonidos básicos de teclado y por supuesto, la adición del sucio sonido del pionero **Mayhem**, para empezar la carrera musical de la primera banda denominable como *black metal progresivo*. Si bien la propuesta no es única en su especie, se vio el día 09 que **Borknagar** es otro exponente de este género, pero esto viene causado por la directa influencia de Bjørnson en primer lugar.

Enslaved mantiene una línea lírica que partió en el paganismo vikingo, sosteniendo temáticas de las eddas, guerras y batallas en las tierras frías del norte. Pero conforme el tiempo pasaba, la propuesta amplió sus horizontes con discos como *Blodhemn*, donde el sonido cambia del prototípico sonido blacker, por uno un poco más pulcro y composición más enrevesada, de a poco insertándose en el pensamiento humano, así como su interacción con su enfrentar psíquico a eventos como el caos, la incertidumbre, largos viajes, misticismo de la vida y la muerte, los sueños y pesadillas.

El cambio radical ocurre en *Mardraum: Beyond the Within* y termina de concretarse en *Below the Lights*, pasando por el cósmico *Monumension* entre medio. Enslaved se sumerge por completo en la influencia del rock psicodélico de los 70's, **Pink Floyd**, **Deep Purple** y **Led Zepellin** son primas de sonidos desconcertantes, cambio de ritmos, pasajes a ratos confusos, ambientación onírica, los recursos de la influencia Hendrix, implementados en la forma desgarradora y castigadora del sonido nórdico.

Enslaved para algunos es considerable el *Opeth del Black Metal*, una banda siempre cambiante, experimental, buscando rutas inesperadas, sosteniendo temáticas y líricas abstractas, combinadas a sonidos que impactan al ritmo de la batería, intercalados al fluir de cuerdas y la escaramuza de voces tanto limpias como la implacable voz de Kjellson, quien prolifera en guturales cuales ladridos y rugir de lobos iracundos.

Con humildes puestas en escena y colaborando con muchas bandas hoy en día en término de producción, así como presentar a leyendas del black en escenario como a Nocturno Culto y Attila Csihar, Enslaved preserva su orgullo nórdico, mantiene sus violentas raíces, a la par de avanzar a grandes pasos, diferenciándose a ratos de sus pares, pero jamás haciendo paso al lado de ellos, al contrario, honrando la memoria de quienes fueron parte de la brutal historia blacker noruega.

**All hail Enslaved! Masters of mystical chaos.**

### Bonus track:
**Canción: Større Enn Tid, Tyngre Enn Natt**
**Álbum: Mardraum: Beyond the Within**

El cambio de Enslaved pasa por tomar propuestas psicodélicas de los años 70's, usar pasajes más complejos y mayor destaque entre los instrumentos. De hecho la introducción musical so prolonga hasta los 4 minutos, recién empezando las voces en el minuto 4 con 30 segundos, partiendo ya con voz limpia, con transiciones al gutural de forma coherente al flujo de la música misma.

10 minutos que valen la pena invertir, para recién comenzar un disco que es un salto estrepitoso a nuevos horizontes musicales.


text:
from utils import read_aloud
from twython import TwythonStreamer

class StreamReader(TwythonStreamer):
    def on_success(self, data):
        if 'text' in data:
            read_aloud("{0}".format(data['text']))

    def on_error(self, status_code, data):
        print(status_code)

if __name__=="__main__":
    with open('apikey', 'r') as f:
        app_key, app_secret, oauth_token, oauth_token_secret = [s.strip() for s in f.readlines()]

    stream = StreamReader(app_key, app_secret, oauth_token, oauth_token_secret)
    stream.statuses.filter(track='SomeLivingRoom')

    read_aloud("Uh oh, the filter stream stopped!")


text:
package org.carlspring.strongbox.cron.jobs;

import org.carlspring.strongbox.cron.domain.CronTaskConfigurationDto;
import org.carlspring.strongbox.cron.jobs.fields.*;
import org.carlspring.strongbox.repository.NpmRepositoryFeatures;

import javax.inject.Inject;
import java.util.Set;

import com.google.common.collect.ImmutableSet;
import org.springframework.core.env.Environment;

/**
 * @author Sergey Bespalov
 */
public class FetchRemoteNpmChangesFeedCronJob
        extends JavaCronJob
{

    private static final String PROPERTY_STORAGE_ID = "storageId";

    private static final String PROPERTY_REPOSITORY_ID = "repositoryId";

    private static final Set<CronJobField> FIELDS = ImmutableSet.of(
            new CronJobStorageIdAutocompleteField(new CronJobStringTypeField(
                    new CronJobOptionalField(new CronJobNamedField(PROPERTY_STORAGE_ID)))),
            new CronJobRepositoryIdAutocompleteField(new CronJobStringTypeField(
                    new CronJobOptionalField(new CronJobNamedField(PROPERTY_REPOSITORY_ID)))));

    @Inject
    private NpmRepositoryFeatures features;

    @Override
    public void executeTask(CronTaskConfigurationDto config)
            throws Throwable
    {
        String storageId = config.getProperty(PROPERTY_STORAGE_ID);
        String repositoryId = config.getProperty(PROPERTY_REPOSITORY_ID);

        features.fetchRemoteChangesFeed(storageId, repositoryId);
    }

    public static String calculateJobName(String storageId,
                                          String repositoryId)
    {
        return String.format("Fetch Remote Changes feed for %s:%s", storageId, repositoryId);
    }

    @Override
    public boolean enabled(CronTaskConfigurationDto configuration,
                           Environment env)
    {
        if (!super.enabled(configuration, env))
        {
            return false;
        }

        return shouldDownloadRemoteChangesFeed();
    }

    @Override
    public CronJobDefinition getCronJobDefinition()
    {
        return CronJobDefinition.newBuilder()
                                .jobClass(FetchRemoteNpmChangesFeedCronJob.class.getName())
                                .name("Fetch Remote Npm Changes Feed Cron Job")
                                .description("Fetch Remote Npm Changes Feed Cron Job")
                                .fields(FIELDS)
                                .build();
    }

    public static boolean shouldDownloadRemoteChangesFeed()
    {
        return System.getProperty("strongbox.npm.remote.changes.enabled") == null ||
               Boolean.parseBoolean(System.getProperty("strongbox.npm.remote.changes.enabled"));
    }
}