<commit_before>require 'test_helper'

class IRBTest < ActiveSupport::TestCase
  setup do
    @irb1 = @irb = WebConsole::REPL::IRB.new
    @irb2 = WebConsole::REPL::IRB.new
  end

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

  test 'preserves the session in the binding' do
    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 undefined_var_or_method('foo'), irb2.send_input('foo')
  end

  test 'session preservation requires same bindings' do
    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 'multiline sessions' do
    irb = WebConsole::REPL::IRB.new(Object.new.instance_eval { binding })
    irb.send('class A')
    irb.send('end')
    assert_equal sprintf(return_prompt, "42\n"), irb.send_input('A')
  end

  test 'prompt is the globally selected one' do
    assert_equal input_prompt, @irb.prompt
  end

  test "prompt isn't nil" do<commit_msg>Use string eval to get the binding<commit_after>require 'test_helper'

class IRBTest < ActiveSupport::TestCase
  setup do
    @irb1 = @irb = WebConsole::REPL::IRB.new
    @irb2 = WebConsole::REPL::IRB.new
  end

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

  test 'preserves the session in the binding' do
    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 undefined_var_or_method('foo'), irb2.send_input('foo')
  end

  test 'session preservation requires same bindings' do
    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 'multiline sessions' do
    irb = WebConsole::REPL::IRB.new(Object.new.instance_eval { binding })
    irb.send('class A')
    irb.send('end')
    assert_equal sprintf(return_prompt, "42\n"), irb.send_input('A')
  end

  test 'prompt is the globally selected one' do
    assert_equal input_prompt, @irb.prompt
  end

  test "prompt isn't nil" do
{'fraction_non_alphanumeric': 0.13183826027862725, 'fraction_numerical': 0.021066938498131158, 'mean_word_length': 4.523452157598499, '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': '1537017', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1018, 'n_words': 239}