<commit_before>-- from C
pdtest = {}

-- pdtest_init
pdtest.suite = function(suite)
  currentSuite = {name=suite, queue={}, dones={}}
  
  currentSuite.before = function() end
  currentSuite.after = function() end
  currentSuite.setup = function(setup)
    if type(setup) == "function" then
      currentSuite.before = setup
      return currentSuite
    end
  end
  currentSuite.teardown = function(teardown)
    if type(teardown) == "function" then
      currentSuite.after = teardown
      return currentSuite
    end
  end
  
  currentSuite.case = function(case)
    currentCase = {name=case, queue={}, dones={}}
    
    currentCase.before = function() end
    currentCase.after = function() end
    currentCase.setup = function(setup)
      if type(setup) == "function" then
        currentCase.before = setup
        return currentCase
      end
    end
    currentCase.teardown = function(teardown)
      if type(teardown) == "function" then
        currentCase.after = teardown
        return currentCase
      end
    end
    
    currentCase.test = function(test)
      currentTest = {test=test, suite=currentSuite, case=currentCase}
      
      cmpmet = {}
      cmpmet.report = function(self,okmsg,failmsg,success,should,result)
        if type(should) == "table" then should = table.concat(should, ", ") end
        if type(should) == "function" then should = "" end
        if self.invert then
          if success then
            return false, ""..table.concat(result,", ")..okmsg..should..""
          else
            return true, ""..table.concat(result,", ")..failmsg..should..""
          end
        else
          if success then
            return true, ""..table.concat(result,", ")..okmsg..should..""
          else
            return false, ""..table.concat(result,", ")..failmsg..should..""
          end
        end
      end
      
      cmpmet.equal = function(self,should)
        currentTest.try = function(result)
          same = true
          if type(should) == "table" and type(result) == "table" then
            for i,v in ipairs(should) do
              if v ~= result[i] then
                same = false
              end
            end
          elseif type(should) == "string" and type(result) == "table" then
            if table.getn(result) == 1 then
              same = should == result[1]
            else
              same = false
            end
          else
            return false, "Comparison data needs to be tables: should is '"..type(should).."', result is '"..type(result).."'"
          end
          return self:report(" is equal to "," is not equal to ",same,should,result)
        end
        return currentCase
      end
      
      cmpmet.be_nil = function(self)
        currentTest.try = function(result)
          if type(result) == "table" then
            same = true
            for i,v in ipairs(result) do
              if result[i] ~= nil then
                same = false
              end
            end
            return self:report(" is nil "," is not nil ",same,"nil",result)
          else
            return false, "Comparison data needs to be table: result is '"..type(result).."'"
          end
        end
        return currentCase
      end
      
      cmpmet.match = function(self,match)
        currentTest.try = function(result)
          if type(match) == "string" and type(result) == "table" then
            same = false
            for i,v in ipairs(result) do
              if string.find(result[i],match) ~= nil then
                same = true
              end
            end
            return self:report(" does match "," does not match ",same,match,result)
          else
            return false, "Comparison data needs to be string and table: should is '"..type(should).."', result is '"..type(result).."'"
          end
        end
        return currentCase
      end
      
      cmpmet.be_true = function(self,should)
        currentTest.try = function(result)
          if type(should) == "function" and type(result) == "table" then
            same = should(result)
            return self:report(" is true "," is not true ",same,should,result)
          else
            return false, "Comparison data needs to be function and table: should is '"..type(should).."', result is '"..type(result).."'"
          end
        end
        return currentCase
      end
      
      currentTest.should = {invert=false}
      currentTest.should.nt = {invert=true}
      for k,v in pairs(cmpmet) do
        currentTest.should[k] = v
        currentTest.should.nt[k] = v
      end
      
      table.insert(currentCase.queue,currentTest)
      return currentTest
    end
    
    table.insert(currentSuite.queue,currentCase)
    return currentCase
  end
  
  table.insert(pdtest.queue,currentSuite)
  return currentSuite
end

function pdtest_next()
  if table.getn(pdtest.queue) == 0 then
    return false
  elseif table.getn(pdtest.queue[1].queue) == 0 then
    table.insert(pdtest.dones, table.remove(pdtest.queue,1))
  elseif table.getn(pdtest.queue[1].queue[1].queue) == 0 then
    table.insert(pdtest.queue[1].dones, table.remove(pdtest.queue[1].queue,1))
  else
    current = pdtest.queue[1].queue[1].queue[1]
    current.suite.before()
    current.case.before()
    if type(current.test) == "function" then
      current.name = "function"
      current.test()
    elseif type(current.test) == "table" then
      current.name = table.concat(current.test, ", ")
      pdtest.message(current.test)
    else
      pdtest.error("wrong test data type -- "..type(current.test).." -- should have been function or table")
    end
    current.suite.after()
    current.case.after()
    table.insert(pdtest.currents, current)
    table.insert(pdtest.queue[1].queue[1].dones, table.remove(pdtest.queue[1].queue[1].queue,1))
  end
  return true
end

function pdtest_yield()
  if table.getn(pdtest.currents) > 0 and table.getn(pdtest.results) > 0 then
    current = table.remove(pdtest.currents,1)
    result = table.remove(pdtest.results,1)
    current.result = result
    current.success, current.detail = current.try(current.result)
    nametag = ""..current.suite.name.." -> "..current.case.name.." < "..current.name.." > "
    if current.success then
      pdtest.post(nametag)
      pdtest.post("-> OK")
    else
      pdtest.post(nametag)
      pdtest.post("x> FAILED |> "..current.detail)
    end
    return true
  elseif table.getn(pdtest.currents) == 0 and table.getn(pdtest.results) == 0 and table.getn(pdtest.queue) == 0 then
    return false
  end
end

function pdtest_report()
  if table.getn(pdtest.currents) > 0 then
    return false
  else
    pdtest.post("!!! Test Completed !!!")
    tests = 0
    cases = 0
    suites = 0
    ok = 0
    fail = 0
    for si, suite in ipairs(pdtest.dones) do
      suites = suites + 1
      for ci, case in ipairs(suite.dones) do
        cases = cases + 1
        for ti, test in ipairs(case.dones) do
          tests = tests + 1
          if test.success then
            ok = ok + 1
          else
            fail = fail + 1
          end
        end
      end
    end
    pdtest.post(""..suites.." Suites | "..cases.." Cases | "..tests.." Tests")
    pdtest.post(""..ok.." tests passed")
    pdtest.post(""..fail.." tests failed")
  end
  return true<commit_msg>pdtest.yield() return true even when no conditions are met<commit_after>-- from C
pdtest = {}

-- pdtest_init
pdtest.suite = function(suite)
  currentSuite = {name=suite, queue={}, dones={}}
  
  currentSuite.before = function() end
  currentSuite.after = function() end
  currentSuite.setup = function(setup)
    if type(setup) == "function" then
      currentSuite.before = setup
      return currentSuite
    end
  end
  currentSuite.teardown = function(teardown)
    if type(teardown) == "function" then
      currentSuite.after = teardown
      return currentSuite
    end
  end
  
  currentSuite.case = function(case)
    currentCase = {name=case, queue={}, dones={}}
    
    currentCase.before = function() end
    currentCase.after = function() end
    currentCase.setup = function(setup)
      if type(setup) == "function" then
        currentCase.before = setup
        return currentCase
      end
    end
    currentCase.teardown = function(teardown)
      if type(teardown) == "function" then
        currentCase.after = teardown
        return currentCase
      end
    end
    
    currentCase.test = function(test)
      currentTest = {test=test, suite=currentSuite, case=currentCase}
      
      cmpmet = {}
      cmpmet.report = function(self,okmsg,failmsg,success,should,result)
        if type(should) == "table" then should = table.concat(should, ", ") end
        if type(should) == "function" then should = "" end
        if self.invert then
          if success then
            return false, ""..table.concat(result,", ")..okmsg..should..""
          else
            return true, ""..table.concat(result,", ")..failmsg..should..""
          end
        else
          if success then
            return true, ""..table.concat(result,", ")..okmsg..should..""
          else
            return false, ""..table.concat(result,", ")..failmsg..should..""
          end
        end
      end
      
      cmpmet.equal = function(self,should)
        currentTest.try = function(result)
          same = true
          if type(should) == "table" and type(result) == "table" then
            for i,v in ipairs(should) do
              if v ~= result[i] then
                same = false
              end
            end
          elseif type(should) == "string" and type(result) == "table" then
            if table.getn(result) == 1 then
              same = should == result[1]
            else
              same = false
            end
          else
            return false, "Comparison data needs to be tables: should is '"..type(should).."', result is '"..type(result).."'"
          end
          return self:report(" is equal to "," is not equal to ",same,should,result)
        end
        return currentCase
      end
      
      cmpmet.be_nil = function(self)
        currentTest.try = function(result)
          if type(result) == "table" then
            same = true
            for i,v in ipairs(result) do
              if result[i] ~= nil then
                same = false
              end
            end
            return self:report(" is nil "," is not nil ",same,"nil",result)
          else
            return false, "Comparison data needs to be table: result is '"..type(result).."'"
          end
        end
        return currentCase
      end
      
      cmpmet.match = function(self,match)
        currentTest.try = function(result)
          if type(match) == "string" and type(result) == "table" then
            same = false
            for i,v in ipairs(result) do
              if string.find(result[i],match) ~= nil then
                same = true
              end
            end
            return self:report(" does match "," does not match ",same,match,result)
          else
            return false, "Comparison data needs to be string and table: should is '"..type(should).."', result is '"..type(result).."'"
          end
        end
        return currentCase
      end
      
      cmpmet.be_true = function(self,should)
        currentTest.try = function(result)
          if type(should) == "function" and type(result) == "table" then
            same = should(result)
            return self:report(" is true "," is not true ",same,should,result)
          else
            return false, "Comparison data needs to be function and table: should is '"..type(should).."', result is '"..type(result).."'"
          end
        end
        return currentCase
      end
      
      currentTest.should = {invert=false}
      currentTest.should.nt = {invert=true}
      for k,v in pairs(cmpmet) do
        currentTest.should[k] = v
        currentTest.should.nt[k] = v
      end
      
      table.insert(currentCase.queue,currentTest)
      return currentTest
    end
    
    table.insert(currentSuite.queue,currentCase)
    return currentCase
  end
  
  table.insert(pdtest.queue,currentSuite)
  return currentSuite
end

function pdtest_next()
  if table.getn(pdtest.queue) == 0 then
    return false
  elseif table.getn(pdtest.queue[1].queue) == 0 then
    table.insert(pdtest.dones, table.remove(pdtest.queue,1))
  elseif table.getn(pdtest.queue[1].queue[1].queue) == 0 then
    table.insert(pdtest.queue[1].dones, table.remove(pdtest.queue[1].queue,1))
  else
    current = pdtest.queue[1].queue[1].queue[1]
    current.suite.before()
    current.case.before()
    if type(current.test) == "function" then
      current.name = "function"
      current.test()
    elseif type(current.test) == "table" then
      current.name = table.concat(current.test, ", ")
      pdtest.message(current.test)
    else
      pdtest.error("wrong test data type -- "..type(current.test).." -- should have been function or table")
    end
    current.suite.after()
    current.case.after()
    table.insert(pdtest.currents, current)
    table.insert(pdtest.queue[1].queue[1].dones, table.remove(pdtest.queue[1].queue[1].queue,1))
  end
  return true
end

function pdtest_yield()
  if table.getn(pdtest.currents) > 0 and table.getn(pdtest.results) > 0 then
    current = table.remove(pdtest.currents,1)
    result = table.remove(pdtest.results,1)
    current.result = result
    current.success, current.detail = current.try(current.result)
    nametag = ""..current.suite.name.." -> "..current.case.name.." < "..current.name.." > "
    if current.success then
      pdtest.post(nametag)
      pdtest.post("-> OK")
    else
      pdtest.post(nametag)
      pdtest.post("x> FAILED |> "..current.detail)
    end
  elseif table.getn(pdtest.currents) == 0 and table.getn(pdtest.results) == 0 and table.getn(pdtest.queue) == 0 then
    return false
  end
  return true
end

function pdtest_report()
  if table.getn(pdtest.currents) > 0 then
    return false
  else
    pdtest.post("!!! Test Completed !!!")
    tests = 0
    cases = 0
    suites = 0
    ok = 0
    fail = 0
    for si, suite in ipairs(pdtest.dones) do
      suites = suites + 1
      for ci, case in ipairs(suite.dones) do
        cases = cases + 1
        for ti, test in ipairs(case.dones) do
          tests = tests + 1
          if test.success then
            ok = ok + 1
          else
            fail = fail + 1
          end
        end
      end
    end
    pdtest.post(""..suites.." Suites | "..cases.." Cases | "..tests.." Tests")
    pdtest.post(""..ok.." tests passed")
    pdtest.post(""..fail.." tests failed")
  end
  return true
{'fraction_non_alphanumeric': 0.12306749301913777, 'fraction_numerical': 0.005176053939930532, 'mean_word_length': 2.0477376504773765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7109208', 'n_tokens_mistral': 4424, 'n_tokens_neox': 4348, 'n_words': 1143}