<commit_before># encoding: utf-8
require File.expand_path('../watirspec_helper', __FILE__)

# keyboard input
# ---------------
describe '#keys' do

  after :each do
    browser.keys.release
  end

  describe '#send' do
    before :each do
      browser.url = fixture('two_input_fields.html')
      @one = window.find_by_name('one')
      @two = window.find_by_name('two')
      @one.click!
    end

    it 'types a single character' do
      browser.keys.send 'A'
      @one.value.should == 'A'
    end

    it 'types a mixed-case string' do
      browser.keys.send 'ABC abc'
      @one.value.should == 'ABC abc'
    end

    it 'types a string containing multi-byte characters' do
      browser.keys.send 'ルビー 水'
      @one.value.should == 'ルビー 水'
    end

    it 'types many single characters in sequence' do
      browser.keys.send 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
      'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
      'W', 'X', 'Y', 'Z'
      @one.value.should == 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    end

    it 'moves the caret using arrow keys' do
      browser.keys.send 'AC', :left, 'B'
      @one.value.should == 'ABC'
    end

    it 'switches to a different input element with tab' do
      browser.keys.send 'AB', :tab, 'C'
      @one.value.should == 'AB'
      @two.value.should == 'C'
    end

    it 'uses modifier keys' do
      browser.keys.send [:shift, 'a'], 'bc'
      @one.value.should == 'Abc'
    end

    it 'uses multiple modifier keys to manipulate selection' do
      browser.keys.send 'ABC 123'

      # Selection using keys works differently on OS X
      if Config::CONFIG['host_os'] =~ /darwin|mac os/
        browser.keys.send [:shift, :alt, :left], :backspace
      else
        browser.keys.send [:shift, :control, :left], :backspace
      end

      @one.value.should == 'ABC '
    end

    it 'presses an invalid key' do
      p browser.driver.key('hoobaflooba')
      browser.keys.send(:hoobaflooba).should raise_error InvalidKeyException
    end
  end

  describe '#down' do
    it 'types a mixed-case string by holding shift' do
      browser.url = fixture('two_input_fields.html')
      window.find_by_name('one').click!
      browser.keys.send 'a'
      browser.keys.down :shift
      browser.keys.send 'b'
      window.find_by_name('one').value.should == 'aB'
      browser.keys.up :shift
    end

    it 'holds down a non-modifier key for one second' do
      browser.url = fixture('two_input_fields.html')
      window.find_by_name('one').click!
      browser.keys.down 'a'
      sleep 1
      browser.keys.up 'a'
      window.find_by_name('one').value.should include 'aa'  # Two or more characters are expected.
    end<commit_msg>Removed a remaining debugging line and renamed the test suite to match object's name<commit_after># -*- coding: utf-8 -*-
require File.expand_path('../watirspec_helper', __FILE__)

# keyboard input
# ---------------
describe 'Keys' do
  after :each do
    browser.keys.release
  end

  describe '#send' do
    before :each do
      browser.url = fixture('two_input_fields.html')
      @one = window.find_by_name('one')
      @two = window.find_by_name('two')
      @one.click!
    end

    it 'types a single character' do
      browser.keys.send 'A'
      @one.value.should == 'A'
    end

    it 'types a mixed-case string' do
      browser.keys.send 'ABC abc'
      @one.value.should == 'ABC abc'
    end

    it 'types a string containing multi-byte characters' do
      browser.keys.send 'ルビー 水'
      @one.value.should == 'ルビー 水'
    end

    it 'types many single characters in sequence' do
      browser.keys.send 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
      'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
      'W', 'X', 'Y', 'Z'
      @one.value.should == 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    end

    it 'moves the caret using arrow keys' do
      browser.keys.send 'AC', :left, 'B'
      @one.value.should == 'ABC'
    end

    it 'switches to a different input element with tab' do
      browser.keys.send 'AB', :tab, 'C'
      @one.value.should == 'AB'
      @two.value.should == 'C'
    end

    it 'uses modifier keys' do
      browser.keys.send [:shift, 'a'], 'bc'
      @one.value.should == 'Abc'
    end

    it 'uses multiple modifier keys to manipulate selection' do
      browser.keys.send 'ABC 123'

      # Selection using keys works differently on OS X
      if Config::CONFIG['host_os'] =~ /darwin|mac os/
        browser.keys.send [:shift, :alt, :left], :backspace
      else
        browser.keys.send [:shift, :control, :left], :backspace
      end

      @one.value.should == 'ABC '
    end

    it 'presses an invalid key' do
      browser.keys.send(:hoobaflooba).should raise_error InvalidKeyException
    end
  end

  describe '#down' do
    it 'types a mixed-case string by holding shift' do
      browser.url = fixture('two_input_fields.html')
      window.find_by_name('one').click!
      browser.keys.send 'a'
      browser.keys.down :shift
      browser.keys.send 'b'
      window.find_by_name('one').value.should == 'aB'
      browser.keys.up :shift
    end

    it 'holds down a non-modifier key for one second' do
      browser.url = fixture('two_input_fields.html')
      window.find_by_name('one').click!
      browser.keys.down 'a'
      sleep 1
      browser.keys.up 'a'
      window.find_by_name('one').value.should include 'aa'  # Two or more characters are expected.
    end
{'fraction_non_alphanumeric': 0.14681592952835382, 'fraction_numerical': 0.0018351991191044228, 'mean_word_length': 2.4779834077855774, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1816352', 'n_tokens_mistral': 1884, 'n_tokens_neox': 1821, 'n_words': 530}