Sha256: 1044bf01bbc7a3a1f36096136c954d39f84f160d5df8a1e266241637047ef0dc

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

# Copyright (C) 2003-2007 Kouichirou Eto, All rights reserved.
# License: Ruby License

module QP #:nodoc:
  module VERSION #:nodoc:
    MAJOR = 1
    MINOR = 0
    TINY  = 0
    STRING = [MAJOR, MINOR, TINY].join('.')
  end

  def caller_msg(ca) #:nodoc:
    file, linenum, msg = ca.first.split(/:([0-9]+):/)
    msg = $1 if /\Ain \`(.+)\'\z/ =~ msg
    File.basename(file)+':'+linenum.to_s+':'+msg.to_s
  end

  def ar_inspect(ar) #:nodoc:
    '['+ar.map {|arg| arg.inspect }.join(', ')+']'
  end

  def runtime #:nodoc:
    $__qp_t__ = Time.now unless defined? $__qp_t__
    sprintf('%.1f', Time.now - $__qp_t__)
  end

  def qp(ca, *args)
    QP.caller_msg(ca)+"\t"+QP.ar_inspect(args)
  end

  def tp(ca, *args)
    QP.runtime+':'+QP.qp(ca, *args)
  end

  module_function :caller_msg, :ar_inspect, :runtime, :qp, :tp
end

def qp(*args)
  $stdout.print QP.qp(caller(1), *args)+"\n"
end

def tp(*args)
  print QP.tp(caller(1), *args)+"\n"
end

if $0 == __FILE__
  $LOAD_PATH.unshift '..' unless $LOAD_PATH.include? '..'
  $__test_qp__ = true
end

if defined?($__test_qp__) && $__test_qp__
  require 'test/unit'
  require 'test/unit/ui/console/testrunner'

  class TestQP < Test::Unit::TestCase #:nodoc:
    def test_all
      #assert_match(/testcase.rb:\d\d:_*send_*/, QP.caller_msg(caller(1)))
      assert_equal("[1, \"a\"]", QP.ar_inspect([1, 'a']))
      assert_match(/\d+\.\d/, QP.runtime)
      #assert_match(/\d+\.\d:testcase.rb:\d\d:_*send_*	\[1, 'a'\]/, QP.tp(caller(1), 1, 'a'))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cutep-1.0.0 lib/qp.rb