<commit_before>
require 'rib/test'
require 'rib/core/history_file'

describe Rib::HistoryFile do
  behaves_like :rib

  before do
    Rib::HistoryFile.enable
    @history = "/tmp/test_rib_#{rand}"
    @shell   = Rib::Shell.new(:history_file => @history).before_loop
  end

  after do
    FileUtils.rm_f(@history)
  end

  should '#after_loop save history' do
    inputs = %w[blih blah]
    @shell.history.replace(inputs)
    @shell.after_loop
    File.read(@history).should.eq "#{inputs.join("\n")}\n"
  end

  should '#before_loop load previous history' do
    File.open(@history, 'w'){ |f| f.write "check\nthe\nmike" }
    @shell.before_loop
    @shell.history.to_a.should.eq %w[check the mike]
  end

  should '#before_loop have empty history if no history file exists' do
    @shell.before_loop
    @shell.history.to_a.should.eq []
  end

  should '#read_history be accessible to plugins in #before_loop' do
    mod = Module.new do
      def read_history
        config[:history] = ['pong_read_history']
      end
    end
    shell = Rib::Shell.dup
    shell.use(mod)
    shell.new.before_loop.history.should.eq ['pong_read_history']
  end

  should '#write_history be accessible to plugins in #after_loop' do
    mod = Module.new do
      def write_history
        config[:history] = ['pong_write_history']
      end
    end
    shell = Rib::Shell.dup
    shell.use(mod)
    shell.new.before_loop.after_loop.history.should.eq ['pong_write_history']
  end
end
<commit_msg>test_history_file.rb: rename history to history_file to avoid confusion<commit_after>
require 'rib/test'
require 'rib/core/history_file'

describe Rib::HistoryFile do
  behaves_like :rib

  before do
    Rib::HistoryFile.enable
    @history_path = "/tmp/test_rib_#{rand}"
    @shell        = Rib::Shell.new(:history_file => @history_path).before_loop
  end

  after do
    FileUtils.rm_f(@history_path)
  end

  should '#after_loop save history' do
    inputs = %w[blih blah]
    @shell.history.replace(inputs)
    @shell.after_loop
    File.read(@history_path).should.eq "#{inputs.join("\n")}\n"
  end

  should '#before_loop load previous history' do
    File.open(@history_path, 'w'){ |f| f.write "check\nthe\nmike" }
    @shell.before_loop
    @shell.history.to_a.should.eq %w[check the mike]
  end

  should '#before_loop have empty history if no history file exists' do
    @shell.before_loop
    @shell.history.to_a.should.eq []
  end

  should '#read_history be accessible to plugins in #before_loop' do
    mod = Module.new do
      def read_history
        config[:history] = ['pong_read_history']
      end
    end
    shell = Rib::Shell.dup
    shell.use(mod)
    shell.new.before_loop.history.should.eq ['pong_read_history']
  end

  should '#write_history be accessible to plugins in #after_loop' do
    mod = Module.new do
      def write_history
        config[:history] = ['pong_write_history']
      end
    end
    shell = Rib::Shell.dup
    shell.use(mod)
    shell.new.before_loop.after_loop.history.should.eq ['pong_write_history']
  end
end

{'fraction_non_alphanumeric': 0.11578947368421053, 'fraction_numerical': 0.0, 'mean_word_length': 3.271067415730337, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6791031', 'n_tokens_mistral': 1044, 'n_tokens_neox': 1018, 'n_words': 239}