<commit_before>require 'test_helper'

class IRBTest < ActiveSupport::TestCase
  test 'initialization with default binding' do
    assert_nothing_raised { WebConsole::REPL::IRB.new }
  end

  test 'sending input returns the result as output' do
    irb = WebConsole::REPL::IRB.new
    assert_equal sprintf(return_prompt, "42\n"), irb.send_input('foo = 42')
  end

  test 'preserves the session in the binding' do
    irb = WebConsole::REPL::IRB.new
    assert_equal sprintf(return_prompt, "42\n"), irb.send_input('foo = 42')
    assert_equal sprintf(return_prompt, "50\n"), irb.send_input('foo + 8')
  end

  test 'session isolation requires own bindings' do
    irb1 = WebConsole::REPL::IRB.new(Object.new.instance_eval { binding })
    irb2 = WebConsole::REPL::IRB.new(Object.new.instance_eval { binding })
    assert_equal sprintf(return_prompt, "42\n"), irb1.send_input('foo = 42')
    assert_match %r{undefined local variable or method `foo'}, irb2.send_input('foo')
  end

  test 'session preservation requires same bindings' do
    irb1 = WebConsole::REPL::IRB.new
    irb2 = WebConsole::REPL::IRB.new
    assert_equal sprintf(return_prompt, "42\n"), irb1.send_input('foo = 42')
    assert_equal sprintf(return_prompt, "42\n"), irb2.send_input('foo')
  end

  test 'prompt is the globally selected one' do
    irb = WebConsole::REPL::IRB.new
    assert_equal input_prompt, irb.prompt
  end

  private
    def currently_selected_prompt
      ::IRB.conf[:PROMPT][::IRB.conf[:PROMPT_MODE]]
    end

    def return_prompt<commit_msg>Add prompt not nil test<commit_after>require 'test_helper'

class IRBTest < ActiveSupport::TestCase
  test 'initialization with default binding' do
    assert_nothing_raised { WebConsole::REPL::IRB.new }
  end

  test 'sending input returns the result as output' do
    irb = WebConsole::REPL::IRB.new
    assert_equal sprintf(return_prompt, "42\n"), irb.send_input('foo = 42')
  end

  test 'preserves the session in the binding' do
    irb = WebConsole::REPL::IRB.new
    assert_equal sprintf(return_prompt, "42\n"), irb.send_input('foo = 42')
    assert_equal sprintf(return_prompt, "50\n"), irb.send_input('foo + 8')
  end

  test 'session isolation requires own bindings' do
    irb1 = WebConsole::REPL::IRB.new(Object.new.instance_eval { binding })
    irb2 = WebConsole::REPL::IRB.new(Object.new.instance_eval { binding })
    assert_equal sprintf(return_prompt, "42\n"), irb1.send_input('foo = 42')
    assert_match %r{undefined local variable or method `foo'}, irb2.send_input('foo')
  end

  test 'session preservation requires same bindings' do
    irb1 = WebConsole::REPL::IRB.new
    irb2 = WebConsole::REPL::IRB.new
    assert_equal sprintf(return_prompt, "42\n"), irb1.send_input('foo = 42')
    assert_equal sprintf(return_prompt, "42\n"), irb2.send_input('foo')
  end

  test 'prompt is the globally selected one' do
    irb = WebConsole::REPL::IRB.new
    assert_equal input_prompt, irb.prompt
  end

  test "prompt isn't nil" do
    assert_not_nil WebConsole::REPL::IRB.new.prompt
  end

  private
    def currently_selected_prompt
      ::IRB.conf[:PROMPT][::IRB.conf[:PROMPT_MODE]]
    end

    def return_prompt
{'fraction_non_alphanumeric': 0.11963383838383838, 'fraction_numerical': 0.018308080808080808, 'mean_word_length': 4.371186440677966, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7537521', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1066, 'n_words': 253}