<commit_before>require 'minitest_helper'
# overload all necessary methods of iohelper
module IOHelper
  extend self
  attr_accessor :output, :keys
  def render sth
    @output += sth
  end
  def clear
    @output = ""
  end
  def rerender sth
    @output = sth
  end
  def read_key_while &block
    Array(@keys).each{|key| block.(key)}
  end
end

describe List do
  before :each do
    IOHelper.output = ""
    IOHelper.keys = nil
  end

  it "doesn't render the dialog with 0 items" do
    List.ask "select", [], clear: false
    IOHelper.output.must_equal ""
  end

  it "renders the dialog with 3 items" do
    List.ask "select", ["one","two","three"], clear: false
    IOHelper.output.must_equal "select:\n\e[36m‣\e[0m \e[36mone\e[0m\n  two\n  three\n"
  end

  it "it finishes selection on pressing enter" do
    IOHelper.keys = "enter"
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 0
  end

  it "selects other items correctly (press down, press up, cycle)" do
    IOHelper.keys = ["down","enter"]
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 1

    IOHelper.keys = ["down","down","enter"]
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 2

    IOHelper.keys = ["down","down","down","enter"]
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 0

    IOHelper.keys = ["down","up","enter"]
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 0

    IOHelper.keys = ["up","enter"]
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 2
  end

end<commit_msg>added checks for rendering during selection to specs<commit_after>require 'minitest_helper'
# overload all necessary methods of iohelper
module IOHelper
  extend self
  attr_accessor :output, :keys
  def render sth
    @output += sth
  end
  def clear
    @output = ""
  end
  def rerender sth
    @output = sth
  end
  def read_key_while &block
    Array(@keys).each{|key| block.(key)}
  end
end

describe List do
  before :each do
    IOHelper.output = ""
    IOHelper.keys = nil
  end

  it "doesn't render the dialog with 0 items" do
    List.ask "select", [], clear: false
    IOHelper.output.must_equal ""
  end

  it "renders the dialog with 3 items" do
    List.ask "select", ["one","two","three"], clear: false
    IOHelper.output.must_equal "select:\n\e[36m‣\e[0m \e[36mone\e[0m\n  two\n  three\n"
  end

  it "it finishes selection on pressing enter" do
    IOHelper.keys = "enter"
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 0
  end

  it "selects and renders other items correctly (press down, press up, cycle)" do
    IOHelper.keys = ["down","enter"]
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 1
    IOHelper.output.must_equal "select:\n  one\n\e[36m‣\e[0m \e[36mtwo\e[0m\n  three\n"

    IOHelper.keys = ["down","down","enter"]
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 2
    IOHelper.output.must_equal "select:\n  one\n  two\n\e[36m‣\e[0m \e[36mthree\e[0m\n"

    IOHelper.keys = ["down","down","down","enter"]
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 0
    IOHelper.output.must_equal "select:\n\e[36m‣\e[0m \e[36mone\e[0m\n  two\n  three\n"

    IOHelper.keys = ["down","up","enter"]
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 0
    IOHelper.output.must_equal "select:\n\e[36m‣\e[0m \e[36mone\e[0m\n  two\n  three\n"

    IOHelper.keys = ["up","enter"]
    List.ask( "select", ["one","two","three"], clear: false
      ).must_equal 2
    IOHelper.output.must_equal "select:\n  one\n  two\n\e[36m‣\e[0m \e[36mthree\e[0m\n"
  end

end
{'fraction_non_alphanumeric': 0.16759480243967118, 'fraction_numerical': 0.015380535666931849, 'mean_word_length': 3.2621468926553674, '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': '6687207', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1343, 'n_words': 349}