<commit_before>#! /usr/bin/env ruby
# coding: utf-8

require 'helper'

require "test/unit"
require "filerenamer/commander.rb"
require "stringio"
require "rubygems"
gem "capture_stdout"
require "capture_stdout"

module FileRenamer
  class Commander
    public :check_new_names
    public :ask_yes?
    public :run
    public :make_new_names
    public :paths
    attr_reader :options
  end
end

class TC_Commander < Test::Unit::TestCase
  EXIST_FILE = "test/filerenamer/dummy.txt"

  A_0 = "test/filerenamer/a0.txt"
  A_1 = "test/filerenamer/a1.txt"

  def setup
    options = {}
    @fr00 = FileRenamer::Commander.new(options, [])

    options = {:copy => true, :yes => true}
    @fr01 = FileRenamer::Commander.new(options, [])
  end

  def test_initialize
    # yes and no
    options = {
      :yes => true,
      :no => true,
    }
    assert_raise(FileRenamer::Commander::OptionError){ FileRenamer::Commander.new(options, []) }

    # ファイル操作モードがどれか1つのみ true なら OK。
    options = { :copy => true, }
    assert_nothing_raised{ FileRenamer::Commander.new(options, []) }

    options = { :move => true, }
    assert_nothing_raised{ FileRenamer::Commander.new(options, []) }

    options = { :hardlink => true, }
    assert_nothing_raised{ FileRenamer::Commander.new(options, []) }

    options = { :symlink => true, }
    assert_nothing_raised{ FileRenamer::Commander.new(options, []) }

    # ファイル操作モードが空でも OK で、その場合は :move が true として扱われる。
    options = { }
    fr00 = FileRenamer::Commander.new(options, [])
    assert_equal( {:move => true}, fr00.options )

    # ファイル操作モードで矛盾する2つ以上が true なら例外。
    options = {
      :move => true,
      :copy => true,
    }
    assert_raise(FileRenamer::Commander::OptionError){ FileRenamer::Commander.new(options, []) }

    options = {
      :move => true,
      :hardlink => true,
    }
    assert_raise(FileRenamer::Commander::OptionError){ FileRenamer::Commander.new(options, []) }

    options = {
      :move => true,
      :symlink => true,
    }
    assert_raise(FileRenamer::Commander::OptionError){ FileRenamer::Commander.new(options, []) }

    # :quiet が立てられれば、自動的に :yes も true になる。
    options = {:quiet => true}
    fr00 = FileRenamer::Commander.new(options, [])
    assert_equal( {:quiet => true, :yes => true, :move => true}, fr00.options )

    # :quiet が立てられれば、:yes が明示的に立っていても問題なし。
    options = {:quiet => true, :yes => true}
    fr00 = FileRenamer::Commander.new(options, [])
    assert_equal( {:quiet => true, :yes => true, :move => true}, fr00.options )

    # :quiet が立てられれば、:no が立っていれば例外。
    options = {:quiet => true, :no => true}
    assert_raise(FileRenamer::Commander::OptionError){ FileRenamer::Commander.new(options, []) }
  end

  def test_execute
    # :yes
    # pre-process
    FileUtils.rm(A_1) if FileTest.exist?(A_1)
    #
    options = {:copy => true, :yes => true}
    fr01 = FileRenamer::Commander.new(options, [A_0])
    str = capture_stdout{fr01.execute{ A_1 }}
    assert_equal(true, FileTest.exist?(A_0))
    assert_equal(true, FileTest.exist?(A_1))
    FileUtils.rm(A_1)
    #
    correct = 
      "Enable files:\n" +
      "  cp -r #{A_0} #{A_1}\n" +
      "Execute? yes\n" +
      "  cp -r #{A_0} #{A_1}\n"
    t = str<commit_msg>daily change<commit_after>#! /usr/bin/env ruby
# coding: utf-8

require 'helper'

require "test/unit"
require "filerenamer/commander.rb"
require "stringio"
require "rubygems"
gem "capture_stdout"
require "capture_stdout"

module FileRenamer
  class Commander
    public :check_new_names
    public :ask_yes?
    public :run
    public :make_new_names
    public :paths
    attr_reader :options
  end
end

class TC_Commander < Test::Unit::TestCase
  EXIST_FILE = "test/filerenamer/dummy.txt"

  A_0 = "test/filerenamer/a0.txt"
  A_1 = "test/filerenamer/a1.txt"

  def setup
    options = {}
    @fr00 = FileRenamer::Commander.new(options, [])

    options = {:copy => true, :yes => true}
    @fr01 = FileRenamer::Commander.new(options, [])
  end

  def test_initialize
    # yes and no
    options = {
      :yes => true,
      :no => true,
    }
    assert_raise(FileRenamer::Commander::OptionError){ FileRenamer::Commander.new(options, []) }

    # ファイル操作モードがどれか1つのみ true なら OK。
    options = { :copy => true, }
    assert_nothing_raised{ FileRenamer::Commander.new(options, []) }

    options = { :move => true, }
    assert_nothing_raised{ FileRenamer::Commander.new(options, []) }

    options = { :hardlink => true, }
    assert_nothing_raised{ FileRenamer::Commander.new(options, []) }

    options = { :symlink => true, }
    assert_nothing_raised{ FileRenamer::Commander.new(options, []) }

    # ファイル操作モードが空でも OK で、その場合は :move が true として扱われる。
    options = { }
    fr00 = FileRenamer::Commander.new(options, [])
    assert_equal( {:move => true}, fr00.options )

    # ファイル操作モードで矛盾する2つ以上が true なら例外。
    options = {
      :move => true,
      :copy => true,
    }
    assert_raise(FileRenamer::Commander::OptionError){ FileRenamer::Commander.new(options, []) }

    options = {
      :move => true,
      :hardlink => true,
    }
    assert_raise(FileRenamer::Commander::OptionError){ FileRenamer::Commander.new(options, []) }

    options = {
      :move => true,
      :symlink => true,
    }
    assert_raise(FileRenamer::Commander::OptionError){ FileRenamer::Commander.new(options, []) }

    # :quiet が立てられれば、自動的に :yes も true になる。
    options = {:quiet => true}
    fr00 = FileRenamer::Commander.new(options, [])
    assert_equal( {:quiet => true, :yes => true, :move => true}, fr00.options )

    # :quiet が立てられれば、:yes が明示的に立っていても問題なし。
    options = {:quiet => true, :yes => true}
    fr00 = FileRenamer::Commander.new(options, [])
    assert_equal( {:quiet => true, :yes => true, :move => true}, fr00.options )

    # :quiet が立てられれば、:no が立っていれば例外。
    options = {:quiet => true, :no => true}
    assert_raise(FileRenamer::Commander::OptionError){ FileRenamer::Commander.new(options, []) }
  end

  def test_execute
    # :yes
    # pre-process
    FileUtils.rm(A_1) if FileTest.exist?(A_1)
    #
    options = {:copy => true, :yes => true}
    fr01 = FileRenamer::Commander.new(options, [A_0])
    str = capture_stdout{fr01.execute{ A_1 }}
    assert_equal(true, FileTest.exist?(A_0))
    assert_equal(true, FileTest.exist?(A_1))
    FileUtils.rm(A_1)
    correct = 
      "Enable files:\n" +
      "  cp -r #{A_0} #{A_1}\n" +
      "Execute? yes\n" +
      "  cp -r #{A_0} #{A_1}\n"
    t = str
{'fraction_non_alphanumeric': 0.15352309846010265, 'fraction_numerical': 0.01182143412661378, 'mean_word_length': 3.3358057990559677, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '3791247', 'n_tokens_mistral': 2586, 'n_tokens_neox': 2416, 'n_words': 438}