<commit_before>require File.expand_path("../../../test_helper", __FILE__)
require "shell_test/pty/session"

class SessionTest < Test::Unit::TestCase
  Session = ShellTest::Pty::Session

  attr_accessor :session

  def setup
    super
    @session = Session.new
  end

  #
  # capture test
  #

  def test_capture_captures_output_and_sets_exit_status
    session.on(/\$ /, "echo hello world\n")
    session.on(/\$ /, "exit 8\n")

    assert_equal "$ echo hello world\nhello world\n$ exit 8\nexit\n", session.capture
    assert_equal 8, $?.exitstatus
  end

  def test_capture_preserves_crlf_if_specified
    session.on(/\$ /, "exit\n")

    assert_equal "$ exit\r\nexit\r\n", session.capture(:crlf => true)
    assert_equal 0, $?.exitstatus
  end

  def test_capture_for_multiline_commands
    session.on(/\$ /, "echo ab\\\n")
    session.on(/\> /, "c\n")
    session.on(/\$ /, "exit\n")

    assert_equal "$ echo ab\\\n> c\nabc\n$ exit\nexit\n", session.capture
    assert_equal 0, $?.exitstatus
  end
end<commit_msg>add test for differnt ps1,ps2<commit_after>require File.expand_path("../../../test_helper", __FILE__)
require "shell_test/pty/session"

class SessionTest < Test::Unit::TestCase
  Session = ShellTest::Pty::Session

  attr_accessor :session

  def setup
    super
    @session = Session.new
  end

  #
  # capture test
  #

  def test_capture_captures_output_and_sets_exit_status
    session.on(/\$ /, "echo hello world\n")
    session.on(/\$ /, "exit 8\n")

    assert_equal "$ echo hello world\nhello world\n$ exit 8\nexit\n", session.capture
    assert_equal 8, $?.exitstatus
  end

  def test_capture_preserves_crlf_if_specified
    session.on(/\$ /, "exit\n")

    assert_equal "$ exit\r\nexit\r\n", session.capture(:crlf => true)
    assert_equal 0, $?.exitstatus
  end

  def test_capture_for_multiline_commands
    session.on(/\$ /, "echo ab\\\n")
    session.on(/\> /, "c\n")
    session.on(/\$ /, "exit\n")

    assert_equal "$ echo ab\\\n> c\nabc\n$ exit\nexit\n", session.capture
    assert_equal 0, $?.exitstatus
  end

  def test_capture_with_different_ps1_and_ps2
    session.env['PS1'] = '% '
    session.env['PS2'] = ': '
    session.on(/\% /, "echo ab\\\n")
    session.on(/\: /, "c\n")
    session.on(/\% /, "exit\n")

    assert_equal "% echo ab\\\n: c\nabc\n% exit\nexit\n", session.capture
    assert_equal 0, $?.exitstatus
  end
end
{'fraction_non_alphanumeric': 0.16286919831223629, 'fraction_numerical': 0.007172995780590718, 'mean_word_length': 3.01864406779661, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1768551', 'n_tokens_mistral': 915, 'n_tokens_neox': 863, 'n_words': 170}