DocsTest.prototype.testObjectsVsFunctionList = function()

in jones-test/lib/DocsTest.js [186:249]


DocsTest.prototype.testObjectsVsFunctionList = function(functionList) {
  var docFunction, testObject, func, name, msg, _class;
  var verified = {};
  var missing = 0;
  var firstMissing = null;
  var i;

  function verify(docFunc) {
    if(! verified[docFunc.className]) {
      verified[docFunc.className] = {};
    }
    verified[docFunc.className][docFunc.functionName] = true;
    udebug.log_detail("verified %s.%s", docFunc.className, docFunc.functionName);
  }

  /* Iterate the functions found in the documentation.
     For each one, try to find a corresponding member of the testObject.
  */
  for(i = 0 ; i < functionList.length ; i++) {
    docFunction = functionList[i];

    if(this.topLevel) {
      testObject = this.testClassMap[0];
    } else {
      testObject = this.testClassMap[docFunction.className];
    }
    if(testObject) {
      func = testObject[docFunction.functionName];
      if(typeof func === 'function') {
        verify(docFunction);
      } else {
        udebug.log_detail("Missing", docFunction);
        if(! firstMissing) { firstMissing = name; }
        missing += 1;      
      }
    } else {
      udebug.log("No %s in object", name);
      missing += 1;
    }
  }

  if(missing) {
    msg = "Missing " + firstMissing;
    if(missing > 1)  { msg += " and " + (missing-1) + " other function"; }
    if(missing > 2)  { msg += "s"; }
    this.appendErrorMessage(msg);
  }
  
  // Test undocumented functions
  for(_class in this.undocMap) {
    if(this.undocMap.hasOwnProperty(_class)) {
      testObject = this.undocMap[_class];
      for(name in testObject) { 
        if(testObject.hasOwnProperty(name)) {
          if(typeof testObject[name] === 'function') {
            if((! verified[_class]) || (!verified[_class][name])) {
              this.appendErrorMessage(_class + "." + name + " undocumented");    
            }
          }
        }
      }
    }
  }
};