<commit_before># encoding: utf-8

RSpec.describe TTY::File, '#chmod' do
  context 'when octal permisssions' do
    it "adds permissions to file - user executable" do
      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.executable?(file)).to eq(false)

      TTY::File.chmod(file, mode | TTY::File::U_X, verbose: false)

      expect(File.lstat(file).mode).to eq(mode | TTY::File::U_X)
    end

    it "logs status when :verbose flag is true" do
      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.executable?(file)).to eq(false)

      expect {
        TTY::File.chmod(file, mode | TTY::File::U_X)
      }.to output(/chmod/).to_stdout_from_any_process

      expect(File.lstat(file).mode).to eq(mode | TTY::File::U_X)
    end

    it "doesn't change permission when :noop flag is true" do
      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.executable?(file)).to eq(false)

      TTY::File.chmod(file, mode | TTY::File::U_X, verbose: false, noop: true)

      expect(File.lstat(file).mode).to eq(mode)
    end
  end

  context 'when human readable permissions' do
    it "adds permisions to file - user executable" do
      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.executable?(file)).to eq(false)

      TTY::File.chmod(file, 'u+x', verbose: false)

      expect(File.lstat(file).mode).to eq(mode | TTY::File::U_X)
    end

    it "removes permission for user executable" do
      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.writable?(file)).to eq(true)

      TTY::File.chmod(file, 'u-w', verbose: false)

      expect(File.lstat(file).mode).to eq(mode ^ TTY::File::U_W)
      expect(File.writable?(file)).to eq(false)
    end

    it "adds multiple permissions separated by comma" do
      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.executable?(file)).to eq(false)

      TTY::File.chmod(file, 'u+x,g+x', verbose: false)

      expect(File.lstat(file).mode).to eq(mode | TTY::File::U_X | TTY::File::G_X)
    end
  end
end
<commit_msg>Change to exlude from windows tests<commit_after># encoding: utf-8

RSpec.describe TTY::File, '#chmod' do
  context 'when octal permisssions' do
    it "adds permissions to file - user executable",
      unless: RSpec::Support::OS.windows? do

      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.executable?(file)).to eq(false)

      TTY::File.chmod(file, mode | TTY::File::U_X, verbose: false)

      expect(File.lstat(file).mode).to eq(mode | TTY::File::U_X)
    end

    it "logs status when :verbose flag is true",
      unless: RSpec::Support::OS.windows? do

      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.executable?(file)).to eq(false)

      expect {
        TTY::File.chmod(file, mode | TTY::File::U_X)
      }.to output(/chmod/).to_stdout_from_any_process

      expect(File.lstat(file).mode).to eq(mode | TTY::File::U_X)
    end

    it "doesn't change permission when :noop flag is true" do
      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.executable?(file)).to eq(false)

      TTY::File.chmod(file, mode | TTY::File::U_X, verbose: false, noop: true)

      expect(File.lstat(file).mode).to eq(mode)
    end
  end

  context 'when human readable permissions' do
    it "adds permisions to file - user executable",
      unless: RSpec::Support::OS.windows? do

      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.executable?(file)).to eq(false)

      TTY::File.chmod(file, 'u+x', verbose: false)

      expect(File.lstat(file).mode).to eq(mode | TTY::File::U_X)
    end

    it "removes permission for user executable" do
      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.writable?(file)).to eq(true)

      TTY::File.chmod(file, 'u-w', verbose: false)

      expect(File.lstat(file).mode).to eq(mode ^ TTY::File::U_W)
      expect(File.writable?(file)).to eq(false)
    end

    it "adds multiple permissions separated by comma",
      unless: RSpec::Support::OS.windows? do

      file = tmp_path('script.sh')
      mode = File.lstat(file).mode
      expect(File.executable?(file)).to eq(false)

      TTY::File.chmod(file, 'u+x,g+x', verbose: false)

      expect(File.lstat(file).mode).to eq(mode | TTY::File::U_X | TTY::File::G_X)
    end
  end
end

{'fraction_non_alphanumeric': 0.15265486725663716, 'fraction_numerical': 0.0004424778761061947, 'mean_word_length': 3.1174863387978142, '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': '4857479', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1581, 'n_words': 339}