<commit_before>local s = require 'say'

local __assertion_meta = {
  __call = function(self, ...)
    local state = self.state
    local val = self.callback(state, ...)
    local data_type = type(val)

    if data_type == "boolean" then
      if val ~= state.mod then
        if state.mod then
          error(s(self.positive_message, {...}) or "assertion failed!")
        else
          error(s(self.negative_message, {...}) or "assertion failed!")
        end
      else
        return state
      end
    end
    return val
  end
}

local __state_meta = {

  __call = function(self, payload, callback)
    self.payload = payload or rawget(self, "payload")
    if callback then callback(self) end
    return self
  end,

  __index = function(self, key)
    if rawget(self.parent, "modifier")[key] then
      rawget(self.parent, "modifier")[key].state = self
      return self(nil,
      rawget(self.parent, "modifier")[key]
      )
    else
      rawget(self.parent, "assertion")[key].state = self
      return rawget(self.parent, "assertion")[key]
    end
  end

}

local obj = {
  -- list of registered assertions
  assertion = {},

  state = function(obj) return setmetatable({mod=true, payload=nil, parent=obj}, __state_meta) end,

  -- list of registered modifiers
  modifier = {},

  -- registers a function in namespace
  register = function(self, namespace, name, callback, positive_message, negative_message)
    -- register
    local lowername = name:lower()
    if not self[namespace] then
      self[namespace] = {}
    end
    self[namespace][lowername] = setmetatable({
      callback = callback,
      name = lowername,
      positive_message=positive_message,
      negative_message=negative_message
    }, __assertion_meta)
  end

}

local __meta = {

  __call = function(self, bool, message)
    if not bool then
      error(message or "assertion failed!")
    end
    return bool
  end,

  __index = function(self, key) return self.state(self)[key] end,

}

return setmetatable(obj, __meta)<commit_msg>If an assertion fails the error is now given 1 level up, so instead of pointing to 'luassert/assert.lua' (line 12 or 76). It will now point to the exact line of the assert command that failed in the testfile.<commit_after>local s = require 'say'

local __assertion_meta = {
  __call = function(self, ...)
    local state = self.state
    local val = self.callback(state, ...)
    local data_type = type(val)

    if data_type == "boolean" then
      if val ~= state.mod then
        if state.mod then
          error(s(self.positive_message, {...}) or "assertion failed!", 2)
        else
          error(s(self.negative_message, {...}) or "assertion failed!", 2)
        end
      else
        return state
      end
    end
    return val
  end
}

local __state_meta = {

  __call = function(self, payload, callback)
    self.payload = payload or rawget(self, "payload")
    if callback then callback(self) end
    return self
  end,

  __index = function(self, key)
    if rawget(self.parent, "modifier")[key] then
      rawget(self.parent, "modifier")[key].state = self
      return self(nil,
      rawget(self.parent, "modifier")[key]
      )
    else
      rawget(self.parent, "assertion")[key].state = self
      return rawget(self.parent, "assertion")[key]
    end
  end

}

local obj = {
  -- list of registered assertions
  assertion = {},

  state = function(obj) return setmetatable({mod=true, payload=nil, parent=obj}, __state_meta) end,

  -- list of registered modifiers
  modifier = {},

  -- registers a function in namespace
  register = function(self, namespace, name, callback, positive_message, negative_message)
    -- register
    local lowername = name:lower()
    if not self[namespace] then
      self[namespace] = {}
    end
    self[namespace][lowername] = setmetatable({
      callback = callback,
      name = lowername,
      positive_message=positive_message,
      negative_message=negative_message
    }, __assertion_meta)
  end

}

local __meta = {

  __call = function(self, bool, message)
    if not bool then
      error(message or "assertion failed!", 2)
    end
    return bool
  end,

  __index = function(self, key) return self.state(self)[key] end,

}

return setmetatable(obj, __meta)
{'fraction_non_alphanumeric': 0.11100658513640639, 'fraction_numerical': 0.0018814675446848542, 'mean_word_length': 2.8804744525547443, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3165645', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1294, 'n_words': 374}