All files / src/dsl/fp combine.js

94.44% Statements 34/36
84.62% Branches 22/26
100% Functions 1/1
93.55% Lines 29/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 511x   1x 400x 400x   400x 2467x   2467x 557x   1910x   1910x 1910x 1910x 1910x 1803x 408x   1395x 1395x 1395x 543x   852x 852x         107x 107x 107x 107x 107x   107x 107x                   400x  
const {invalidTypesInArgument, nonMatchingArgumentTypes, invalidOptionsListInCombine} = require('../../errors')
 
module.exports = (...options) => {
  let errs   = []
  const args = {}
 
  for (let i = 0; i < options.length; i++) {
    const {errs: ERRS = [], args: ARGS} = options[i]
 
    if (ERRS.length > 0) {
      errs = errs.concat(ERRS)
    } else {
      const keys = Object.keys(ARGS)
 
      for (let j = 0; j < keys.length; j++) {
        const arg  = keys[j]
        const list = ARGS[arg]
        if (typeof args[arg] === 'undefined') {
          if (typeof list === 'undefined' || list === null || list.length === 0) {
            errs.push(invalidOptionsListInCombine({list, arg, option: options[i]}))
          } else {
            for (let k = 0; k < list.length; k++) {
              const argument = list[k]
              if (!(Array.isArray(argument.types) || argument.types === null)) {
                errs.push(invalidTypesInArgument({types: argument.types, argument}))
              } else {
                Eif (typeof args[arg] === 'undefined') args[arg] = []
                args[arg].push(argument)
              }
            }
          }
        } else {
          const ref   = args[arg][0]
          const types = ref.types
          for (let k = 0; k < list.length; k++) {
            const argument = list[k]
            Iif (!(Array.isArray(argument.types) || argument.types === null)) {
              errs.push(invalidTypesInArgument({types: argument.types, argument}))
            } else Eif ((argument.types || []).length === (types || []).length) {
              args[arg].push(argument)
            } else {
              errs.push(nonMatchingArgumentTypes({arg, ref, argument}))
            }
          }
        }
      }
    }
  }
 
  return {errs, args}
}