<commit_before># encoding: utf-8

require 'tokyocabinet'
require File.expand_path('../spec_helper', __FILE__)
require 'myaso/tokyo_cabinet'

module Myaso
  describe TokyoCabinet do
  end
end<commit_msg>Tests for TokyoCabinet adapter<commit_after># encoding: utf-8

require 'tokyocabinet'

require File.expand_path('../spec_helper', __FILE__)
require 'myaso/tokyo_cabinet'

module Myaso
  describe TokyoCabinet do
    it 'has storages array' do
      TokyoCabinet::STORAGES.must_be_kind_of Array
    end

    describe 'Read mode' do
      let(:tmpdir) { Dir.mktmpdir }
      let(:myaso) { Myaso::TokyoCabinet.new(tmpdir) }

      subject { myaso }

      before do
      end

      after do
        myaso.close!
        FileUtils.remove_entry_secure tmpdir
      end
    end

    describe 'Management mode' do
      let(:tmpdir) { Dir.mktmpdir }
      let(:myaso) { Myaso::TokyoCabinet.new(tmpdir, :manage) }

      subject { myaso }

      before { populate_tokyo_cabinet! myaso }

      after do
        myaso.close!
        FileUtils.remove_entry_secure tmpdir
      end

      it 'has initialized storages' do
        subject.storages.keys.must_equal TokyoCabinet::STORAGES

        subject.storages.values.each do |storage|
          storage.must_be_kind_of TokyoCabinet::TDB
        end
      end

      it 'can be reindexed' do
        subject.reindex!.must_be_nil
      end

      it 'can be closed' do
        subject.close!.must_be_nil
        TokyoCabinet::STORAGES.each do |storage|
          proc { subject.send(storage).find(1) }.must_raise NoMethodError
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08400746733042937, 'fraction_numerical': 0.001866832607342875, 'mean_word_length': 2.5812917594654787, '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': '6688603', 'n_tokens_mistral': 564, 'n_tokens_neox': 546, 'n_words': 121}