var vows = require('vows');
var assert = require('assert');
var path = require('path');
var vm = require('vm');
var bundle = require('../lib/bundle');
var parseConfig = require('../lib/parse-config');

vows.describe('bundle').addBatch({
  "all": {
    topic: bundle(parseConfig(__dirname + '/fixtures/config.json', null)).src,

    "find all modules": function(bundled) {
      assert.match(bundled, /moduleFns\["[^"]+abc.js"\]/);
      assert.match(bundled, /moduleFns\["[^"]+def.js"\]/);
      assert.match(bundled, /moduleFns\["[^"]+ghi.js"\]/);
      assert.match(bundled, /moduleFns\["[^"]+underscore.js"\]/);
    },

    "execute bundled code": function(bundled) {
      var env = {};
      vm.runInNewContext(bundled, env);
      assert.equal(env.output, 'output from module "def"');
    }
  }
}).export(module);


@@ -233,19 +233,32 @@
 ch(%7B%0A  %22
-all
+no mangled names
 %22: %7B%0A   
@@ -547,32 +547,32 @@
 %22%5D+ghi.js%22%5C%5D/);%0A
-
       assert.mat
@@ -629,16 +629,390 @@
     %7D,%0A%0A
+    %22execute bundled code%22: function(bundled) %7B%0A      var env = %7B%7D;%0A      vm.runInNewContext(bundled, env);%0A      assert.equal(env.output, 'output from module %22def%22');%0A    %7D%0A  %7D,%0A%0A  %22mangled names%22: %7B%0A    topic: function() %7B%0A      var config = parseConfig(__dirname + '/fixtures/config.json', null);%0A      config.mangleNames = true;%0A      return bundle(config).src;%0A    %7D,%0A%0A
     %22exe

add test for mangled names