xeluxee / competitest.nvim

CompetiTest.nvim is a Neovim plugin for Competitive Programming: it can manage and check testcases, download problems and contests from online judges and much more
GNU Lesser General Public License v3.0
381 stars 15 forks source link

feat: filtering output before comparing. #15

Closed shadmansaleh closed 1 year ago

shadmansaleh commented 1 year ago

Are you interested in exposing a filter function in config that is applied on output before comparing it to check if it's matches with the desired one or not?

I have a debugging function that always prints lines starting with "DBG )>". If competitest compares the output with these removed I can observe the debug output while also check if the test is passing.

I can currently achieve it by injecting a custom compare method like this.

local compare_methods = require('competitest.compare').methods
function compare_methods.filter_squish(output, expout)
  local strs = {}
  for str in vim.gsplit(output, '\n') do
    if not vim.startswith(str, 'DBG )>') then
      table.insert(strs, str)
    end
  end
  return compare_methods.squish(table.concat(strs, '\n'), expout)
end

require('competitest').setup {
  output_compare_method = 'filter_squish',
}

But it's kind of hacky. So I think it'd be nice If competitest allows me to provide a filter function is config.

xeluxee commented 1 year ago

Why not printing debug statements on stderr?

shadmansaleh commented 1 year ago

Why not printing debug statements on stderr?

On tests that contain multiple cases. It's easier to understand which debug output is from which case.

shadmansaleh commented 1 year ago

You should have just told me output_compare_method can be a function.

custom function: you can use a function accepting two arguments, two strings representing output and expected output. It should return true if the given output is acceptable, false otherwise. Example:

require('competitest').setup {
  output_compare_method = function(output, expected_output)
      if output == expected_output then
          return true
      else
          return false
      end
  end
}