<commit_before>require 'helper'

class TestAutomate < MiniTest::Test

  def test_single_element_chain
    c = Automate::Chain.which("Has a single element") do
      go "Set some variable" do
        pass :foo, 42
      end
    end
    assert_equal({:foo => 42}, c.run)
  end


  def test_multiple_element_chain
    c = Automate::Chain.which("Has multiple elements") do
      go "Link #1" do
        pass :out, [1]
      end

      go "Link #2" do
        _out.push(2)
        pass :out, _out
      end

      go "Link #3" do
        _out.push(3)
        pass :out, _out
      end
    end

    result = c.run({:in => 42})
    assert_equal([1,2,3], result[:out])
    assert_equal(42, result[:in])
  end


  def test_command_error
    c = Automate::Chain.which("Has an error") do
      go "Fail" do
        run "this_doesnt_even_exist___"
      end
    end

    assert_equal false, c.run
  end


  def test_unmet_demand_error
    c = Automate::Chain.which("Has an error") do
      go "Fail" do
        demand :not_given
      end
    end

    assert_equal false, c.run
  end


  def test_met_demand
    c = Automate::Chain.which("Met demand") do
      go "Pass arg" do
        demand :input
        pass :output, _input + 1
      end

      go "Check args" do
        demand :output
      end
    end

    result = c.run({:input => 42})
    assert_equal 42, result[:input]
    assert_equal 43, result[:output]
  end


  def test_method_missing_in_chain_link
    assert_raises(NameError) do
      c = Automate::Chain.which("checks method missing") do
        go "Raise name error" do
          wobblewobble
        end
      end
      c.run
    end
  end


  def test_run_successful_command
    c = Automate::Chain.which("Run shell command") do
      go "run the command" do
        demand :input<commit_msg>Adapt unit test to exception handling changes<commit_after>require 'helper'

class TestAutomate < MiniTest::Test

  def test_single_element_chain
    c = Automate::Chain.which("Has a single element") do
      go "Set some variable" do
        pass :foo, 42
      end
    end
    assert_equal({:foo => 42}, c.run)
  end


  def test_multiple_element_chain
    c = Automate::Chain.which("Has multiple elements") do
      go "Link #1" do
        pass :out, [1]
      end

      go "Link #2" do
        _out.push(2)
        pass :out, _out
      end

      go "Link #3" do
        _out.push(3)
        pass :out, _out
      end
    end

    result = c.run({:in => 42})
    assert_equal([1,2,3], result[:out])
    assert_equal(42, result[:in])
  end


  def test_command_error
    c = Automate::Chain.which("Has an error") do
      go "Fail" do
        run "this_doesnt_even_exist___"
      end
    end

    assert_equal false, c.run
  end


  def test_unmet_demand_error
    c = Automate::Chain.which("Has an error") do
      go "Fail" do
        demand :not_given
      end
    end

    assert_equal false, c.run
  end


  def test_met_demand
    c = Automate::Chain.which("Met demand") do
      go "Pass arg" do
        demand :input
        pass :output, _input + 1
      end

      go "Check args" do
        demand :output
      end
    end

    result = c.run({:input => 42})
    assert_equal 42, result[:input]
    assert_equal 43, result[:output]
  end


  def test_exception_in_chain_link
    c = Automate::Chain.which("checks method missing") do
      go "Raise name error" do
        wobblewobble
      end
    end
    assert_equal false, c.run
  end


  def test_run_successful_command
    c = Automate::Chain.which("Run shell command") do
      go "run the command" do
        demand :input
{'fraction_non_alphanumeric': 0.09408825978351373, 'fraction_numerical': 0.013322231473771857, 'mean_word_length': 2.1503496503496504, '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': '5248367', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1174, 'n_words': 352}