var vows = require('vows'),
    assert = require('assert'),
    jsdom = require('jsdom');

/*
 * Don't require d3 in a var declaration so the name is available to
 * d3-transform. This makes it global, which should probably be avoided but
 * ???
 */
d3 = require('d3');
var transform = require("../src/d3-transform.js");

vows.describe('d3-transform').addBatch({
  'the initial object' : {
    topic : function() {
      return d3.svg.transform();
    },
    'is an identity transform' : function(topic) {
      assert.equal(topic(), "");
    }
  },
  'calling translate' : {
    'works for one argument' : function() {
      var transform = d3.svg.transform()
          .translate(1);

      assert.equal(transform(), 'translate(1)');
    },
    'works for two arguments' : function() {
      var transform = d3.svg.transform()
          .translate(1, 2);

      assert.equal(transform(), 'translate(1,2)');
    },
    'works for a function argument' : function() {
      var transform = d3.svg.transform()
          .translate(function() { return [3, 5]; });

      assert.equal(transform(), 'translate(3,5)');
    },
    'works for a function argument, given arguments' : function() {
      var transform = d3.svg.transform()
          .translate(function(x) { return [x, 13]; });

      assert.equal(transform(8), 'translate(8,13)');
    },
    'works for a function argument, as a method' : function() {
      var transform = d3.svg.transform()
          .translate(function() { return [this.x, 34]; });
      var cxt = { 'x' : 21 };

      assert.equal(transform.call(cxt), 'translate(21,34)');
    }
  },
  'composing transforms' : {
    'works' : function() {
      var transform = d3.svg.transform()
          .translate(1, 1)
          .rotate(2);
      assert.equal(transform(), 'translate(1,1) rotate(2)');
    }
  }
}).export(module);

@@ -1818,16 +1818,631 @@
 ;%0A    %7D%0A
+  %7D,%0A  'composing multiple transform objects' : %7B%0A    'works' : function() %7B%0A      var t1 = d3.svg.transform()%0A        .translate(1,1)%0A        .rotate(2)%0A      var t2 = d3.svg%0A        .transform(t1)%0A        .scale(3,3);%0A      assert.equal(t2(),%22translate(1,1) rotate(2) scale(3,3)%22);%0A    %7D,%0A    'works with functions at any point' : function() %7B%0A      var t1 = d3.svg.transform()%0A        .translate(function(d) %7B return %5Bd,1%5D;%7D)%0A        .rotate(2)%0A      var t2 = d3.svg%0A        .transform(t1)%0A        .scale(function(d) %7B return %5Bd+1,4%5D;%7D);%0A      assert.equal(t2(10),%22translate(10,1) rotate(2) scale(11,4)%22);%0A    %7D%0A
   %7D%0A%7D).e

test for object composition