<commit_before>require File.dirname(__FILE__) + '/test_helper'

class FDBTest <  Test::Unit::TestCase
  include SproutTestCase
  
  def setup
    @start                  = Dir.pwd
    fixture                 = File.join(fixtures, 'fdb')
    @swf                    = 'SomeProject-debug.swf'
    Dir.chdir fixture
  end
  
  def teardown
    Dir.chdir @start
    clear_tasks
  end

  def test_instantiated
    debugger = fdb :debug
    assert debugger.is_a?(Sprout::FDBTask)
  end
  
  def create_buffer(str=nil)
    process = MockProcess.new
    output = MockProcess.new
    buffer = FDBBufferStub.new(process, output)

    process.print str unless str.nil?
    sleep(0.2)

    return [process, output, buffer]
  end

  def test_simple_buffer
    str = "Adobe"
    process, output, buffer = create_buffer(str)
    assert_equal(str, output)
  end

  def test_fdb_buffer
    str = "Adobe fdb (Flash Player Debugger) [build 3.0.0.477]\n"
    str << "Copyright (c) 2004-2007 Adobe, Inc. All rights reserved.\n"
    str << "(fdb) "
    
    process, output, buffer = create_buffer str
    assert_equal(str, output)
  end

  def test_fdb_buffer_wait_for_prompt
    str = "Adobe fdb (Flash Player Debugger) [build 3.0.0.477]\n"
    str << "Copyright (c) 2004-2007 Adobe, Inc. All rights reserved.\n"
    str << "(fdb) "

    process, output, buffer = create_buffer
    process.print str

    timeout 1 do
      buffer.wait_for_prompt
    end
  end

  def test_fdb_confirmation_prompt
    str = "Adobe fdb (Flash Player Debugger) [build 3.0.0.477]\n"
    str << "Copyright (c) 2004-2007 Adobe, Inc. All rights reserved.\n"
    str << "The program is running.  Exit anyway? (y or n) "

    process, output, buffer = create_buffer
    process.print str

    timeout 1 do
      buffer.wait_for_prompt
    end
    
  end

=begin
  def test_launch_player
    debugger = fdb :debug do |t|
      t.file = @swf
      t.run
      t.continue
      t.sleep_until('SomeProject instantiated!')
#      t.break = "SomeProject.as#1"
#      t.continue
#      t.quit
#      t.pwd<commit_msg>Worked on fdb test<commit_after>require File.dirname(__FILE__) + '/test_helper'

class FDBTest <  Test::Unit::TestCase
  include SproutTestCase
  
  def setup
    @start                  = Dir.pwd
    fixture                 = File.join(fixtures, 'fdb')
    @swf                    = 'SomeProject-debug.swf'
    Dir.chdir fixture
  end
  
  def teardown
    Dir.chdir @start
    clear_tasks
  end

  def test_instantiated
    debugger = fdb :debug
    assert debugger.is_a?(Sprout::FDBTask)
  end
  
  def create_buffer(str=nil)
    process = MockProcess.new
    output = MockProcess.new
    buffer = FDBBufferStub.new(process, output)

    process.print str unless str.nil?
    sleep(0.2)

    return [process, output, buffer]
  end

  def test_simple_buffer
    str = "Adobe"
    process, output, buffer = create_buffer(str)
    assert_equal(str, output)
  end

  def test_fdb_buffer
    str = "Adobe fdb (Flash Player Debugger) [build 3.0.0.477]\n"
    str << "Copyright (c) 2004-2007 Adobe, Inc. All rights reserved.\n"
    str << "(fdb) "
    
    process, output, buffer = create_buffer str
    assert_equal(str, output)
  end

  def test_fdb_buffer_wait_for_prompt
    str = "Adobe fdb (Flash Player Debugger) [build 3.0.0.477]\n"
    str << "Copyright (c) 2004-2007 Adobe, Inc. All rights reserved.\n"
    str << "(fdb) "

    process, output, buffer = create_buffer
    process.print str

    timeout 1 do
      buffer.wait_for_prompt
    end
  end

  def test_fdb_confirmation_prompt
    str = "Adobe fdb (Flash Player Debugger) [build 3.0.0.477]\n"
    str << "Copyright (c) 2004-2007 Adobe, Inc. All rights reserved.\n"
    str << "The program is running.  Exit anyway? (y or n) "

    process, output, buffer = create_buffer
    process.print str

    timeout 1 do
      buffer.wait_for_prompt
    end
    
  end
  
=begin

  def test_launch_player
    debugger = fdb :debug do |t|
      t.file = @swf
      t.run
      t.break = "SomeProject.as#4"
#      t.continue
#      t.sleep_until('SomeProject instantiated!')
#      t.continue
#      t.quit
#      t.pwd
{'fraction_non_alphanumeric': 0.09978255617298865, 'fraction_numerical': 0.0227107997100749, 'mean_word_length': 2.447127393838468, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '94528', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1399, 'n_words': 374}