 assert = require('chai').assert
+fs = require('fs')
+path = require('path')
+
+isAn = require('../dist/is-an.coffee')
 
 suite('coverage', () ->
-  isAn = null
-
-  setup(() ->
-    isAn = require('../dist/is-an.coffee')
-  )
-
   class Base
   class Derived extends Base
 

    () -> new Float64Array(1)
  ]

  test('generate chart', () ->
    rows = [['javascript']]

    # Create header row
    head = (func, names = []) ->
      if names.length == 0
        rows[0].push('type name')
      else
        rows[0].push("`#{names.join('.')}`")

      for own subName, subFunc of func
        if isAn.Function(subFunc)
          head(subFunc, names.concat([subName]))

      return
    head(isAn)

    # Result rows
    for input in inputs
      row = []
      rows.push(row)

      # javascript value (extracted from function body)
      row.push(input.toString().replace(/^function \(\) {\s*(?:return)?\s*(.*?)(?:;)?\s*}$/, '`$1`'))

      # value
      value = input()

      # Result cells
      check = (func, names = []) ->
        if names.length == 0
          typeName = func(value)
          row.push(if typeName then "`#{typeName}`" else '<undefined>')
        else
          row.push(if func(value) then 'TRUE' else '')

        for own subName, subFunc of func
          if isAn.Function(subFunc)
            check(subFunc, names.concat([subName]))

        return

      check(isAn)

    columnWidths = rows[0].map(
      (element, iColumn) ->
        Math.max(
          (
            for row in rows
              row[iColumn].length
          )...
        ) + 2
    )

    padd = (x, width, p = '                        ') ->
      while x.length < width
        x += p
      return x.slice(0, width)

    for row,irow in rows
      console.log(
        row.map((element, iElement) -> padd(element, columnWidths[iElement])).join(' | ')
      )
      if irow == 0
        console.log(columnWidths.map((width) -> padd('', width, '-')).join('-|-'))

    #console.log(rows)
  )
)

    () -> new RegExp()
    () -> new RegExp('a')

    () -> new Error()
    () -> `try { eval('}') } catch (ex) { return ex; }`; return

    () -> Math

    () -> new Int8Array(1)
