var trimIndentationFactory = require('../../services/trimIndentation');

describe("trimIndentation", function() {
  var trimIndentation;
  beforeEach(function() {
    trimIndentation = trimIndentationFactory();
  });
  it("should trim simple leading white-space from a single line of text", function() {
    expect(trimIndentation('   abc  ')).toEqual('abc  ');
  });
  it("should trim excess indentation from multi-line text ", function() {
    expect(trimIndentation('abc\n     xyz\n     123\n\n')).toEqual('abc\nxyz\n123');
    expect(trimIndentation('  abc\n     xyz\n     123\n\n')).toEqual('abc\n   xyz\n   123');
    expect(trimIndentation(' abc\n  xyz\n   123\n\n')).toEqual('abc\n xyz\n  123');
  });
  it("should remove leading empty lines", function() {
    expect(trimIndentation('\n\n\nabc')).toEqual('abc');
    expect(trimIndentation('\n\n\n   abc')).toEqual('abc');
  });
  it("should remove trailing empty lines", function() {
    expect(trimIndentation('abc\n\n\n')).toEqual('abc');
  });

  describe("calcIndent", function() {
    it("should calculate simple leading white-space from a single line of text", function() {
      expect(trimIndentation.calcIndent('   abc  ')).toEqual(3);
    });
    it("should trim excess indentation from multi-line text ", function() {
      expect(trimIndentation.calcIndent('abc\n     xyz\n     123\n\n')).toEqual(5);
      expect(trimIndentation.calcIndent('  abc\n     xyz\n     123\n\n')).toEqual(2);
      expect(trimIndentation.calcIndent(' abc\n  xyz\n   123\n\n')).toEqual(1);
    });
  });

  describe("reindent", function() {
    it("should add whitespace to the start of each line", function() {
      expect(trimIndentation.reindent('abc\n  xyz', 4)).toEqual('    abc\n      xyz');
    });
  });
});
var mockPackage = require('dgeni-packages/base/spec/mockPackage');
var Dgeni = require('dgeni');

describe("trimIndentation", function() {
  var trimIndentation;
  beforeEach(function() {
    var dgeni = new Dgeni([mockPackage()]);
    var injector = dgeni.configureInjector();
    trimIndentation = injector.get('trimIndentation');
  });
  it("should trim simple leading white-space from a single line of text", function() {
    expect(trimIndentation('   abc  ')).toEqual('abc  ');
  });
  it("should trim excess indentation from multi-line text ", function() {
    expect(trimIndentation('abc\n     xyz\n     123\n\n')).toEqual('abc\nxyz\n123');
    expect(trimIndentation('  abc\n     xyz\n     123\n\n')).toEqual('abc\n   xyz\n   123');
    expect(trimIndentation(' abc\n  xyz\n   123\n\n')).toEqual('abc\n xyz\n  123');
  });
  it("should remove leading empty lines", function() {
    expect(trimIndentation('\n\n\nabc')).toEqual('abc');
    expect(trimIndentation('\n\n\n   abc')).toEqual('abc');
  });
  it("should remove trailing empty lines", function() {
    expect(trimIndentation('abc\n\n\n')).toEqual('abc');
  });

  describe("calcIndent", function() {
    it("should calculate simple leading white-space from a single line of text", function() {
      expect(trimIndentation.calcIndent('   abc  ')).toEqual(3);
    });
    it("should trim excess indentation from multi-line text ", function() {
      expect(trimIndentation.calcIndent('abc\n     xyz\n     123\n\n')).toEqual(5);
      expect(trimIndentation.calcIndent('  abc\n     xyz\n     123\n\n')).toEqual(2);
      expect(trimIndentation.calcIndent(' abc\n  xyz\n   123\n\n')).toEqual(1);
    });
  });

  describe("reindent", function() {
    it("should add whitespace to the start of each line", function() {
      expect(trimIndentation.reindent('abc\n  xyz', 4)).toEqual('    abc\n      xyz');
    });
  });
});
use configureInjector and mockPackage