var Promise = require('bluebird'),
    fs = Promise.promisifyAll(require('fs')),
    LIB = require('../lib'),
    fixtures = require('./fixtures.json'),
    expect = require('expect.js'),
    should = require('should');




describe("Integration Tests", function () {
  run("nothing");
  run("simple");
  run("page");
  run("page-with-content");
  run("repeat");
  run("repeat-simple");
  run("repeat-with-index");
  run("repeat-object");
  run("sanitize");
  run("bind");
  run("bind-with-alias");
  run("layout");
  run("optional");
  run("filter");
});


function run (name) {
  it("should process " + name + ".html", function () {
    return Promise.all([
      fs.readFileAsync(__dirname + '/input/page.html', 'utf8'),
      fs.readFileAsync(__dirname + '/input/' + name + '.html', 'utf8'),
      fs.readFileAsync(__dirname + '/expected/' + name + '.html', 'utf8')
    ])
    .spread(function (layout, input, expected) {
      var template = LIB.string(input);
      template.layouts.set('page.html', LIB.string(layout));
      //console.log(template.render+'')
      // console.log(template.render(fixtures));
      var content = '';
      if (/-with-content$/.test(name)) {
        content = '<p>Content</p>';
      }

      template.toCase = function (direction, input) {
        return input['to' + direction.charAt(0).toUpperCase() + direction.slice(1) + 'Case']();
      };

      template.reverse = function (input) {
        return input.split('').reverse().join('');
      };
      template.render(fixtures, content).should.equal(expected);
    });
  });
}
@@ -261,16 +261,111 @@
 on () %7B%0A
+  var collection;%0A  before(function () %7B%0A    collection = LIB.dir(__dirname + '/input');%0A  %7D);%0A
   run(%22n
@@ -644,14 +644,13 @@
 %22);%0A
-%7D);
 %0A%0A%0A
+  
 func
@@ -667,16 +667,18 @@
 name) %7B%0A
+  
   it(%22sh
@@ -720,24 +720,26 @@
 nction () %7B%0A
+  
     return P
@@ -757,142 +757,8 @@
 %5B%0A  
-    fs.readFileAsync(__dirname + '/input/page.html', 'utf8'),%0A      fs.readFileAsync(__dirname + '/input/' + name + '.html', 'utf8'),%0A
     
@@ -835,11 +835,15 @@
     
+  
 %5D)%0A
+  
     
@@ -864,23 +864,8 @@
 on (
-layout, input, 
 expe
@@ -868,24 +868,26 @@
 expected) %7B%0A
+  
       var te
@@ -899,88 +899,43 @@
 e = 
-LIB.string(input);%0A      template.layouts.set('page.html', LIB.string(layout));%0A
+collection.get(name + '.html');%0A%0A  
     
@@ -976,16 +976,18 @@
 )%0A      
+  
 // conso
@@ -1023,24 +1023,26 @@
 es));%0A      
+  
 var content 
@@ -1053,16 +1053,18 @@
 ;%0A      
+ 
+ 
 if (/-wi
@@ -1098,16 +1098,18 @@
         
+  
 content 
@@ -1138,11 +1138,15 @@
     
+ 
+ 
 %7D%0A%0A
+  
     
@@ -1187,32 +1187,34 @@
 ction, input) %7B%0A
+  
         return i
@@ -1299,16 +1299,18 @@
 ;%0A      
+  
 %7D;%0A%0A    
@@ -1307,24 +1307,26 @@
   %7D;%0A%0A      
+ 
+ 
 template.rev
@@ -1343,32 +1343,34 @@
 ction (input) %7B%0A
+  
         return i
@@ -1404,16 +1404,18 @@
 in('');%0A
+  
       %7D;
@@ -1417,24 +1417,26 @@
    %7D;%0A      
+  
 template.ren
@@ -1482,16 +1482,26 @@
 ected);%0A
+      %7D);%0A
     %7D);%0A
@@ -1507,8 +1507,8 @@
 %0A  %7D
-);
 %0A%7D
+);

refactor tests to use collections