import * as assert_ from 'power-assert';
const assert = assert_.default;
import attrconv_ from '../index';
const attrconv = attrconv_.default; // HACK for default by TypeScript 1.5 Alpha

describe('main', () => {
  function parameterized(input, expected, pattern) {
    it(`${input} to be ${expected}`, (done) => {
      attrconv(input, pattern).then((actual) => {
        assert(actual === expected);
        done();
      });
    });
  }

  parameterized(
    `<p>Text</p>`,
    `<p>Text</p>`
  );

  parameterized(
    `<p><span>Text</span></p>`,
    `<p><span>Text</span></p>`
  );

  parameterized(
    `<a href="./">Text</a>`,
    `<a href="./">Text</a>`
  );

  parameterized(
    `<p><span><!-- comment --></span></p>`,
    `<p><span><!-- comment --></span></p>`
  );

  parameterized(
    `<a href="./">Text</a>`,
    `<a conv="./">Text</a>`,
    {'href': 'conv'}
  );

  parameterized(
    `<a href="foo">Text</a>`,
    `<a conv="bar">Text</a>`,
    {href: ['conv', {foo: 'bar'}]}
  );

  parameterized(
    `<a href="foo">Text</a><a href="baz">Text</a>`,
    `<a conv="bar">Text</a><a conv="qux">Text</a>`,
    {href: ['conv', {foo: 'bar', baz: 'qux'}]}
  );

  parameterized(
    `<input (click)="action()"></input>`,
    `<input ng-click="action()"></input>`,
    {'^\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)$': 'ng-$1'}
  );

  parameterized(
    `<input #name></input>`,
    `<input ng-model="name"></input>`,
    {'^#(.*)$': ['ng-model', {'.*': '%1'}]}
  );

  parameterized(
    `<input #aaa #bbb></input>`,
    `<input ng-model="aaa" ng-model="bbb"></input>`,
    {'^#(.*)$': ['ng-model', {'.*': '%1'}]}
  );

  parameterized(
    `<input #abcde></input>`,
    `<input ng-model="c"></input>`,
    {'^#.(.)(.)(.).*$': ['ng-model', {'.*': '%2'}]}
  );

  parameterized(
    `<input #abcde></input>`,
    `<input ng-model="d"></input>`,
    {'^#.(.)(.)(.).*$': ['ng-model', {'.*': '%3'}]}
  );

  parameterized(
    `<div [innertext]="textbox.value"></div>`,
    `<div innertext="{{textbox.value}}"></div>`,
    {'^\\[([a-zA-Z_][a-zA-Z0-9_]*)\\]$': ['$1', {'^(.*)$': '{{$1}}'}]}
  );

  parameterized(
    `<li *foreach="#todo of todos"></li>`,
    `<li ng-repeat="todo in todos"></li>`,
    {'^\\*foreach$': ['ng-repeat', {'^#(.*)(\\s+)of(\\s+)(.*)$': '$1$2in$3$4'}]}
  );

  parameterized(
    `<div class="view" [class.hidden]="todoEdit == todo"></div>`,
    `<div class="view" ng-class="{hidden: todoEdit == todo}"></div>`,
    {'^\\[class\\.(.*)\\]$': ['ng-class', {'^(.*)$': '{%1: $1}'}]}
  );

  it(`Long HTML test`, (done) => {
    const input    = `<div [innertext]="textbox.value" (click)="action()" #name><!-- comment --></div>`;
    const expected = `<div innertext="{{textbox.value}}" ng-click="action()" ng-model="name"><!-- comment --></div>`;
    const pattern = {
      '^\\[([a-zA-Z_][a-zA-Z0-9_]*)\\]$': ['$1', {'^(.*)$': '{{$1}}'}],
      '^#(.*)$': ['ng-model', {'.*': '%1'}],
      '^\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)$': 'ng-$1'
    };
    attrconv(input, pattern).then((actual) => {
      assert(actual === expected);
      done();
    });
  });
});
@@ -1208,32 +1208,24 @@
 =%22action()%22%3E
-%3C/input%3E
 %60,%0A    %60%3Cinp
@@ -1247,24 +1247,16 @@
 tion()%22%3E
-%3C/input%3E
 %60,%0A    %7B
@@ -1341,24 +1341,16 @@
 t #name%3E
-%3C/input%3E
 %60,%0A    %60
@@ -1372,24 +1372,16 @@
 =%22name%22%3E
-%3C/input%3E
 %60,%0A    %7B
@@ -1464,24 +1464,16 @@
 aa #bbb%3E
-%3C/input%3E
 %60,%0A    %60
@@ -1509,24 +1509,16 @@
 l=%22bbb%22%3E
-%3C/input%3E
 %60,%0A    %7B
@@ -1594,32 +1594,24 @@
 nput #abcde%3E
-%3C/input%3E
 %60,%0A    %60%3Cinp
@@ -1626,24 +1626,16 @@
 del=%22c%22%3E
-%3C/input%3E
 %60,%0A    %7B
@@ -1723,24 +1723,16 @@
  #abcde%3E
-%3C/input%3E
 %60,%0A    %60
@@ -1755,16 +1755,8 @@
 %22d%22%3E
-%3C/input%3E
 %60,%0A 

fix fixtures, remove unnecessary </input>