import assert from 'power-assert';
import itEach from '../lib';

/* Sample code using 'itEach' */
describe('Example', () => {
  function add(a, b) {
    return parseInt(a) + parseInt(b);
  }

  /* Basic use */
  describe('add()', () => {
    itEach('adds two numbers', [
      [[1, 1], 2],
      [[2, -2], 0],
      [[140, 48], 188]
    ], (args, expected) => {
      assert.equal(add.apply(null, args), expected);
    });

    context('with invalid arguments', () => {
      itEach('returns NaN value', [
        [1, 'foo'],
        [null, 10],
        [undefined, undefined],
        [{}, []]
      ], (left, right) => {
        const value = add(left, right);
        assert(isNaN(value));
      });
    });
  });

  function letCry(animal) {
    switch(animal) {
    case 'dog': return 'bowow';
    case 'cat': return 'meow';
    case 'cow': return 'mow';
    default: return '...';
    }
  }

  /* Generate test case name dynamically */
  describe('letCry()', () => {
    itEach(
      (animal, cry) => `A ${animal} should cry '${cry}'`,
      [
        ['dog', 'bowow'],
        ['cat', 'meow'],
        ['cow', 'mow'],
        ['nothing', '...']
      ], (animal, cry) => {
        assert.equal(cry, letCry(animal));
      }
    );
  });

  function asBool(value) {
    return Boolean(value);
  }

  /* Omit test case name */
  describe('asBool()', () => {
    itEach([
      'string',
      100,
      true,
      {}
    ], value => {
      assert.equal(asBool(value), true);
    });
  });

  function delayGreet(name, callback) {
    setTimeout(() => {
      callback(`Hi, ${name}!`);
    }, 30);
  }

  /* With asynchronous code */
  describe('delayGreet()', () => {
    itEach('greets will be delayed', [
      'Alis', 'Bob', 'Caroline'
    ], (name, done) => {
      delayGreet(name, greet => {
        assert.equal(greet, `Hi, ${name}!`);
        done();
      });
    });
  });
});


@@ -35,18 +35,19 @@
 %0Aimport 
-it
+for
 Each fro
@@ -55,16 +55,27 @@
  '../lib
+/mocha-each
 ';%0A%0A/* S
@@ -251,43 +251,24 @@
     
-it
+for
 Each(
-'adds two numbers', 
 %5B%0A      
 %5B%5B1,
@@ -267,15 +267,13 @@
     
-%5B
 %5B1, 1
-%5D
 , 2%5D
@@ -284,16 +284,14 @@
     
-%5B
 %5B2, -2
-%5D
 , 0%5D
@@ -302,17 +302,16 @@
     
-%5B
 %5B140, 48
 %5D, 1
@@ -306,17 +306,16 @@
 %5B140, 48
-%5D
 , 188%5D%0A 
@@ -322,15 +322,50 @@
    %5D
-, (args
+)%0A    .it('adds two numbers', (left, right
 , ex
@@ -403,25 +403,20 @@
 (add
-.apply(null, args
+(left, right
 ), e
@@ -490,36 +490,16 @@
     
-it
+for
 Each(
-'returns NaN value', 
 %5B%0A  
@@ -592,16 +592,47 @@
 %0A      %5D
+)%0A      .it('returns NaN value'
 , (left,
@@ -1002,84 +1002,18 @@
     
-it
+for
 Each(
+%5B
 %0A
-      (animal, cry) =%3E %60A $%7Banimal%7D should cry '$%7Bcry%7D'%60,%0A      %5B%0A  
     
@@ -1038,18 +1038,16 @@
 ,%0A      
-  
 %5B'cat', 
@@ -1051,26 +1051,24 @@
 ', 'meow'%5D,%0A
-  
       %5B'cow'
@@ -1083,18 +1083,16 @@
 ,%0A      
-  
 %5B'nothin
@@ -1106,20 +1106,91 @@
 .'%5D%0A    
+%5D)%0A    .it(%0A      (animal, cry) =%3E %60A $%7Banimal%7D should cry '$%7Bcry%7D'%60,%0A   
   
-%5D,
  (animal
@@ -1384,26 +1384,27 @@
 () =%3E %7B%0A    
-it
+for
 Each(%5B%0A     
@@ -1451,16 +1451,69 @@
 %7B%7D%0A    %5D
+)%0A    .it(value =%3E %60handles $%7BJSON.stringify(value)%7D%60
 , value 
@@ -1759,41 +1759,16 @@
     
-it
+for
 Each(
-'greets will be delayed', 
 %5B%0A  
@@ -1802,16 +1802,50 @@
 e'%0A    %5D
+)%0A    .it('greets will be delayed'
 , (name,

Rewrite examples using new module