<commit_before>-- SPDX-FileCopyrightText: Copyright 2022-present <NAME> and contributors.
-- SPDX-License-Identifier: BSD-2-Clause

local ffi = require('ffi')

describe('matcher.c', function()
  local lib = require'wincent.commandt.lib'

  local get_matcher = function(paths, options)
    local scanner = lib.scanner_new_copy(paths)
    local matcher = lib.commandt_matcher_new(scanner, options)
    return {
      match = function(query)
        local results = lib.commandt_matcher_run(matcher, query)
        local strings = {}
        for k = 0, results.count - 1 do
          local str = results.matches[k]
          table.insert(strings, ffi.string(str.contents, str.length))
        end
        return strings
      end,
      _scanner = scanner, -- Prevent premature GC.
      _matcher = matcher, -- Prevent premature GC.
    }
  end

  context('with an empty scanner', function()
    local matcher = nil

    before(function()
      matcher = get_matcher({})
    end)

    it('returns an empty list given an empty query', function()
      expect(matcher.match('')).to_equal({})
    end)

    it('returns an empty list given a non-empty query', function()
      expect(matcher.match('foo')).to_equal({})
    end)
  end)
end)<commit_msg>test(lua): add some more tests<commit_after>-- SPDX-FileCopyrightText: Copyright 2022-present <NAME> and contributors.
-- SPDX-License-Identifier: BSD-2-Clause

local ffi = require('ffi')

describe('matcher.c', function()
  local lib = require'wincent.commandt.lib'

  local get_matcher = function(paths, options)
    local scanner = lib.scanner_new_copy(paths)
    local matcher = lib.commandt_matcher_new(scanner, options)
    return {
      match = function(query)
        local results = lib.commandt_matcher_run(matcher, query)
        local strings = {}
        for k = 0, results.count - 1 do
          local str = results.matches[k]
          table.insert(strings, ffi.string(str.contents, str.length))
        end
        return strings
      end,
      _scanner = scanner, -- Prevent premature GC.
      _matcher = matcher, -- Prevent premature GC.
    }
  end

  context('with an empty scanner', function()
    local matcher = nil

    before(function()
      matcher = get_matcher({})
    end)

    it('returns an empty list given an empty query', function()
      expect(matcher.match('')).to_equal({})
    end)

    it('returns an empty list given a non-empty query', function()
      expect(matcher.match('foo')).to_equal({})
    end)
  end)

  context('with a non-empty scanner', function()
    it('returns empty list when no matches', function()
      local matcher = get_matcher({'foo/bar', 'foo/baz', 'bing'})
      expect(matcher.match('xyz')).to_equal({})
    end)

    it('returns matching paths', function()
      local matcher = get_matcher({'foo/bar', 'foo/baz', 'bing'})
      expect(matcher.match('z')).to_equal({'foo/baz'})
      expect(matcher.match('bg')).to_equal({'bing'})
    end)

    it('performs case-insensitive matching', function()
      local matcher = get_matcher({'Foo'})
      expect(matcher.match('f')).to_equal({'Foo'})
    end)
  end)
end)
{'fraction_non_alphanumeric': 0.1339085969958453, 'fraction_numerical': 0.0044742729306487695, 'mean_word_length': 3.049159120310479, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3503177', 'n_tokens_mistral': 1006, 'n_tokens_neox': 968, 'n_words': 244}