"use strict";

var random = require("./random");
var compilers_setup = require("../lib/compilers");

describe("compilers", function() {

  it("compiles file", function () {
    var file_name = random.word();
    var content = random.word();

    var compile = compilers_setup({
      read_content: function (file) { if (file === file_name) return content; },
    });

    expect(compile(file_name)).toEqual(content);
  });

  it("executes compilers in configured order", function () {
    var compile = compilers_setup({
      read_content: function () { return ""; },
      compilers: [{
        compile: function (x) { return x + "asdf"; },
        applies_to: function (input_file) { return true; }
      }, {
        compile: function (x) { return x + "qwer"; },
        applies_to: function (input_file) { return true; }
      }]
    });

    expect(compile()).toEqual("asdfqwer");
  });

  it("executes only matching compilers", function () {
    var compile = compilers_setup({
      read_content: function () { return ""; },
      compilers: [{
        compile: function (x) { return x + "asdf"; },
        applies_to: function (input_file) { return false; }
      }, {
        compile: function (x) { return x + "qwer"; },
        applies_to: function (input_file) { return true; }
      }]
    });

    expect(compile()).toEqual("qwer");
  });

  it("passes extra params to compilers", function () {
    var compile = compilers_setup({
      read_content: function () { return "asdf"; },
      compilers: [{
        compile: function (x, params) { return x + params; },
        applies_to: function (input_file) { return true; }
      }]
    });

    expect(compile(null, "qwer")).toEqual("asdfqwer");
  });

});

@@ -130,16 +130,125 @@
 on() %7B%0A%0A
+  var prefix, affix;%0A  beforeEach(function() %7B%0A    prefix = random.word();%0A    affix = random.word();%0A  %7D);%0A%0A
   it(%22co
@@ -726,38 +726,37 @@
 x) %7B return x + 
-%22asdf%22
+affix
 ; %7D,%0A        app
@@ -849,34 +849,34 @@
 x) %7B return 
-x + %22qwer%22
+prefix + x
 ; %7D,%0A       
@@ -971,34 +971,38 @@
 ()).toEqual(
-%22asdfqwer%22
+prefix + affix
 );%0A  %7D);%0A%0A  
@@ -1201,22 +1201,21 @@
 urn x + 
-%22asdf%22
+affix
 ; %7D,%0A   
@@ -1325,18 +1325,18 @@
 urn 
-x + %22qwer%22
+prefix + x
 ; %7D,
@@ -1443,22 +1443,22 @@
 toEqual(
-%22qwer%22
+prefix
 );%0A  %7D);
@@ -1506,32 +1506,96 @@
 , function () %7B%0A
+    var content = random.word();%0A    var param = random.word();%0A
     var compile 
@@ -1659,14 +1659,15 @@
 urn 
-%22asdf%22
+content
 ; %7D,
@@ -1855,14 +1855,13 @@
 ll, 
-%22qwer%22
+param
 )).t
@@ -1871,18 +1871,23 @@
 ual(
-%22asdfqwer%22
+content + param
 );%0A 

Use random.word() to get compiler prefixes and affixes and file params and contents