'use strict'

import context from './context'
import describer from './describer'

const frameworkFns = {
  describeFn: describe,
  itFn: it
}

let _ctx;

const test = (testFn, definerFn) => {
  // TODO: throw if they're not functions
  _ctx = context.init(testFn)
  definerFn()
  describer(_ctx, frameworkFns)
}

const given = (...args) => {
  const { caseIndex, context: ctx } = context.addCase(_ctx, args)
  _ctx = ctx
  return newTestCase(caseIndex)
}

const newTestCase = (caseIndex) => {
  return {
    ___caseIndex: caseIndex,
    expect: getExpectFn(caseIndex)
  }
}

const getExpectFn = (caseIndex) => {
  return (expectedValue) => {
    _ctx = context.addExpectedValue(_ctx, caseIndex, expectedValue)
    return newTestCase(caseIndex)
  }
}

export { test, given }
export default { test, given }

/*
const givenFn = (ctx) => {
  return (...args) => {
    const newCtx = context.addCase(ctx, args)
    return chain(newCtx)
  }
}

const expectFn = (ctx) => {
  return (expectedVal) => {
    const newCtx = context.addExpectedValue(ctx, expectedVal)
    return chain(newCtx)
  }
}

const describeFn = (ctx, applyToAll) => {
  return (message) => {
    const newCtx = context.setDescribeMessage(ctx, applyToAll, message);
    return chain(newCtx)
  }
}
*/

/*const runFn = (ctx) => {
  return () => {
    describer(ctx, frameworkFns)
  }
}

const chain = (ctx) => {
  return {
    test: test,
    given: givenFn(ctx),
    expect: expectFn(ctx),
    run: runFn(ctx),
    describe: describeFn(ctx),
    all: {
      describe: describeFn(ctx, true)
    }
  }
}*/

@@ -803,764 +803,4 @@
 n %7D%0A
-%0A/*%0Aconst givenFn = (ctx) =%3E %7B%0A  return (...args) =%3E %7B%0A    const newCtx = context.addCase(ctx, args)%0A    return chain(newCtx)%0A  %7D%0A%7D%0A%0Aconst expectFn = (ctx) =%3E %7B%0A  return (expectedVal) =%3E %7B%0A    const newCtx = context.addExpectedValue(ctx, expectedVal)%0A    return chain(newCtx)%0A  %7D%0A%7D%0A%0Aconst describeFn = (ctx, applyToAll) =%3E %7B%0A  return (message) =%3E %7B%0A    const newCtx = context.setDescribeMessage(ctx, applyToAll, message);%0A    return chain(newCtx)%0A  %7D%0A%7D%0A*/%0A%0A/*const runFn = (ctx) =%3E %7B%0A  return () =%3E %7B%0A    describer(ctx, frameworkFns)%0A  %7D%0A%7D%0A%0Aconst chain = (ctx) =%3E %7B%0A  return %7B%0A    test: test,%0A    given: givenFn(ctx),%0A    expect: expectFn(ctx),%0A    run: runFn(ctx),%0A    describe: describeFn(ctx),%0A    all: %7B%0A      describe: describeFn(ctx, true)%0A    %7D%0A  %7D%0A%7D*/%0A

Remove commented chain code