<commit_before>require 'helper'

describe "Pry::CommandProcessor" do
  before do
    @pry = Pry.new
    @pry.commands = Pry::CommandSet.new
    @command_processor = Pry::CommandProcessor.new(@pry)
  end

  after do
    @pry.commands = Pry::CommandSet.new
  end

  it 'should accurately determine if a command is valid' do
    @pry.commands.command("test-command") {}
    valid = @command_processor.valid_command? "test-command"
    valid.should == true

    valid = @command_processor.valid_command? "blah"
    valid.should == false

    a = "test-command"
    lambda { @command_processor.valid_command? '#{a}' }.should.raise NameError
  end

  it 'should correctly match a simple string command' do
    @pry.commands.command("test-command") {}
    command, captures, pos = @command_processor.command_matched "test-command", binding

    command.name.should == "test-command"
    captures.should == []
    pos.should == "test-command".length
  end

  it 'should correctly match a simple string command with parameters' do
    @pry.commands.command("test-command") { |arg|}
    command, captures, pos = @command_processor.command_matched "test-command hello", binding

    command.name.should == "test-command"
    captures.should == []
    pos.should == "test-command".length
  end<commit_msg>added tests for optional binding paramter to CommandProcessor#valid_command?<commit_after>require 'helper'

describe "Pry::CommandProcessor" do
  before do
    @pry = Pry.new
    @pry.commands = Pry::CommandSet.new
    @command_processor = Pry::CommandProcessor.new(@pry)
  end

  after do
    @pry.commands = Pry::CommandSet.new
  end

  it 'should accurately determine if a command is valid' do
    @pry.commands.command("test-command") {}
    valid = @command_processor.valid_command? "test-command"
    valid.should == true

    valid = @command_processor.valid_command? "blah"
    valid.should == false


    a = "test-command"

    # not passing in a binding so 'a' shoudn't exist and should cause error
    lambda { @command_processor.valid_command? '#{a}' }.should.raise NameError

    # passing in the optional binding (against which interpolation is performed)
    valid = @command_processor.valid_command? '#{a}', binding
    valid.should == true
  end

  it 'should correctly match a simple string command' do
    @pry.commands.command("test-command") {}
    command, captures, pos = @command_processor.command_matched "test-command", binding

    command.name.should == "test-command"
    captures.should == []
    pos.should == "test-command".length
  end

  it 'should correctly match a simple string command with parameters' do
    @pry.commands.command("test-command") { |arg|}
    command, captures, pos = @command_processor.command_matched "test-command hello", binding

    command.name.should == "test-command"
    captures.should == []
    pos.should == "test-command".length
  end
{'fraction_non_alphanumeric': 0.11878453038674033, 'fraction_numerical': 0.0, 'mean_word_length': 3.7648026315789473, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4308517', 'n_tokens_mistral': 882, 'n_tokens_neox': 850, 'n_words': 227}