/*global describe,it,expect*/

import {match, MatchError} from '../src';

describe('match', () => {
  it('matches a key, and runs its callback immediately', () => {
    const obj = { grant: 'denasty' };
    /* Assigning to this will be a detectable side-effect, knowing for sure
     * the callback was called. */
    var wildcard;

    match(obj, {
      trevor() {
        wildcard = 'vampire killer';
      },

      sypha() {
        wildcard = 'magic';
      },

      grant() {
        wildcard = 'daggers';
      }
    });

    expect(wildcard).toBe('daggers');
  });

  it("matches a key, and returns its callback's result", () => {
    const obj = { sypha: 'belnades' };

    const value = match(obj, {
      trevor: () => 'vampire killer',
      sypha: () => 'magic',
      grant: () => 'daggers'
    });

    expect(value).toBe('magic');
  });

  it('throws a MatchError when no key matches in the map', () => {
    const obj = { alucard: 'dracula' };

    expect(() => {
      match(obj, {
        trevor: () => 'vampire killer',
        sypha: () => 'magic',
        grant: () => 'daggers'
      });
    }).toThrowError(MatchError);
  });
});

@@ -20,19 +20,27 @@
 t,expect
+,pending
 */%0A
-
 %0Aimport 
@@ -853,24 +853,635 @@
 c');%0A  %7D);%0A%0A
+  it('calls the matching callback with its value and key, respectively', () =%3E %7B%0A    const obj = %7B trevor: 'belmont' %7D;%0A%0A    const title = name =%3E %7B%0A      expect(name).toBeDefined();%0A      expect(typeof name).toBe('string');%0A      return name.substr(0, 1).toUpperCase() + name.substr(1);%0A    %7D;%0A%0A    const value = match(obj, %7B%0A      trevor: (val, key) =%3E %60$%7Btitle(key)%7D %22Vampire Killer%22 $%7Btitle(val)%7D%60,%0A      sypha: (val, key) =%3E %60%22Magic%22 $%7Btitle(key)%7D $%7Btitle(val)%7D%60,%0A      grant: (val, key) =%3E %60$%7Btitle(key)%7D %22Daggers%22 $%7Btitle(val)%7D%60%0A    %7D);%0A%0A    expect(value).toBe('Trevor %22Vampire Killer%22 Belmont');%0A  %7D);%0A%0A
   it('throws
@@ -1567,15 +1567,13 @@
 d: '
-dracula
+tepes
 ' %7D;
@@ -1723,16 +1723,16 @@
     %7D);%0A
-
     %7D).t
@@ -1761,13 +1761,418 @@
 );%0A  %7D);
+%0A%0A  it('calls the third argument when no match is made', () =%3E %7B%0A    const obj = %7B alucard: 'tepes' %7D;%0A%0A    const answer = match(obj,%0A      %7B%0A        trevor: () =%3E 'vampire killer',%0A        sypha: () =%3E 'magic',%0A        grant: () =%3E 'daggers'%0A      %7D,%0A      (value, key) =%3E %60I don't know what to do with $%7Bkey%7D $%7Bvalue%7D%60%0A    );%0A%0A    expect(answer).toBe(%22I don't know what to do with alucard tepes%22);%0A  %7D);
 %0A%7D);%0A

Add spec for match() features.