From 862bc9aa6b002f6b29cf74f93ca66e63cf370819 Mon Sep 17 00:00:00 2001 From: murphy Date: Wed, 31 Mar 2010 22:17:06 +0000 Subject: Upporting changes from 0.9.2 (vs. 0.9.1). --- Changes.textile | 12 +++- Rakefile | 93 ++++++++------------------ etc/coderay-lib.tmproj | 8 +-- lib/README | 10 ++- lib/coderay/encoders/html.rb | 4 +- lib/coderay/encoders/terminal.rb | 24 ++++++- lib/coderay/for_redcloth.rb | 14 +++- lib/coderay/scanners/php.rb | 1 + lib/coderay/scanners/yaml.rb | 4 +- lib/coderay/tokens.rb | 30 +++++---- rake_helpers/del_vim_orphans.rb | 43 ------------ rake_helpers/ftp.rb | 47 ------------- rake_tasks/documentation.rake | 26 +++---- rake_tasks/example.rake | 25 ------- rake_tasks/gem.rake | 50 ++++++++------ rake_tasks/ruby-versions.rake | 48 +++++++++++++ rake_tasks/rubyforge.rake | 33 --------- rake_tasks/test.rake | 12 ++-- test/functional/basic.rb | 6 +- test/functional/for_redcloth.rb | 20 ++---- test/functional/load_plugin_scanner.rb | 4 +- test/functional/suite.rb | 14 ++-- test/functional/word_list.rb | 4 +- test/lib/README | 3 +- test/scanners/coderay_suite.rb | 9 +++ test/scanners/debug/class.expected.raydebug | 1 + test/scanners/php/namespaces.expected.raydebug | 9 +++ test/scanners/php/namespaces.in.php | 9 +++ 28 files changed, 245 insertions(+), 318 deletions(-) delete mode 100644 rake_helpers/del_vim_orphans.rb delete mode 100644 rake_helpers/ftp.rb delete mode 100644 rake_tasks/example.rake create mode 100644 rake_tasks/ruby-versions.rake delete mode 100644 rake_tasks/rubyforge.rake create mode 100644 test/scanners/php/namespaces.expected.raydebug create mode 100644 test/scanners/php/namespaces.in.php diff --git a/Changes.textile b/Changes.textile index 78cdfce..7e1aa49 100644 --- a/Changes.textile +++ b/Changes.textile @@ -121,11 +121,14 @@ h3. Internal API changes h2. Changes in 0.9.2 +* *NEW* Basic tests and a _Rakefile_ are now included in the Gem. [Flameeyes] + A @doc@ task is also included. * *FIXED* Use @$CODERAY_DEBUG@ for debugging instead of @$DEBUG@. [Trans] ("#192":http://redmine.rubychan.de/issues/192) * *REMOVED* @Term::Ansicolor@ was bundled under _lib/_, but not used. [Flameeyes] - ("#195":http://redmine.rubychan.de/issues/195) -* *NEW* Basic tests and a _Rakefile_ are now included in the Gem. [Flameeyes] + ("#205":http://redmine.rubychan.de/issues/205) +* *WORKAROUND* for Ruby bug + "#2745":http://redmine.ruby-lang.org/issues/show/2745 h3. @Encoders::Term@ @@ -146,6 +149,11 @@ h3. @Scanners::Groovy@ * *FIXED* token kind of closing brackets is @:operator@ instead of @nil@ ("#148":http://redmine.rubychan.de/issues/148) +h3. @Scanners::PHP@ + +* *FIXED* allow @\@ operator (namespace separator) + ("#209":http://redmine.rubychan.de/issues/209) + h3. @Scanners::YAML@ * *FIXED* doesn't send debug tokens when @$DEBUG@ is true [Trans] diff --git a/Rakefile b/Rakefile index 93fcd29..b238cb1 100644 --- a/Rakefile +++ b/Rakefile @@ -1,71 +1,36 @@ $: << File.dirname(__FILE__) unless $:.include? '.' -require 'rake_helpers/ftp.rb' - -verbose false +require 'rake/rdoctask' ROOT = '.' LIB_ROOT = File.join ROOT, 'lib' -RUBY = ENV.fetch 'ruby', 'ruby' - -EXTRA_FILES = %w(lib/README FOLDERS) -def EXTRA_FILES.in folder - map do |file_name| - File.join folder, file_name - end -end +EXTRA_RDOC_FILES = %w(lib/README FOLDERS) task :default => :test -task :upload => %w( gem:upload doc:upload example:upload ) - -def ruby command - params = - if RUBY == 'rbx' - '-I/usr/local/lib/ruby/1.8' - else - '-w' - end - cmd = "#{RUBY} #{params} #{command}" - puts cmd if verbose - system cmd -end - -task '19' do - RUBY.replace 'ruby19' -end - -task '18' do - RUBY.replace 'ruby18' -end - -task '187' do - RUBY.replace 'ruby187' -end - -task 'jruby' do - RUBY.replace 'jruby' -end -task :j => :jruby - -task 'jruby19' do - RUBY.replace 'jruby --1.9' -end -task :j19 => :jruby19 - -task 'jruby-nailgun' do - RUBY.replace 'jruby --ng' -end -task :jng => :'jruby-nailgun' - -task 'rubinius' do - RUBY.replace 'rbx' -end - -task 'ee' do - RUBY.replace 'rubyee' -end - -for task_file in Dir['rake_tasks/*.rake'] - load task_file -end - +if File.directory? 'rake_tasks' + + # load rake tasks from subfolder + for task_file in Dir['rake_tasks/*.rake'].sort + load task_file + end + +else + + # fallback tasks when rake_tasks folder is not present + desc 'Run CodeRay tests (basic)' + task :test do + ruby './test/functional/suite.rb' + ruby './test/functional/for_redcloth.rb' + end + + desc 'Generate documentation for CodeRay' + Rake::RDocTask.new :doc do |rd| + rd.title = 'CodeRay Documentation' + rd.main = 'lib/README' + rd.rdoc_files.add Dir['lib'] + rd.rdoc_files.add 'lib/README' + rd.rdoc_files.add 'FOLDERS' + rd.rdoc_dir = 'doc' + end + +end \ No newline at end of file diff --git a/etc/coderay-lib.tmproj b/etc/coderay-lib.tmproj index ad29cad..fdb322b 100644 --- a/etc/coderay-lib.tmproj +++ b/etc/coderay-lib.tmproj @@ -52,10 +52,6 @@ lastUsed 2009-10-03T23:52:27Z - - filename - ../ftp.yaml - name etc @@ -81,8 +77,12 @@ filename ../LICENSE + lastUsed + 2010-03-08T22:53:09Z + expanded + name rake_helpers regexFolderFilter diff --git a/lib/README b/lib/README index 7beb924..564a9c0 100644 --- a/lib/README +++ b/lib/README @@ -18,7 +18,7 @@ And with line numbers. * is what everybody should have on their website * solves all your problems and makes the girls run after you -Version: 0.9.1 +Version: 0.9.2 Author:: murphy (Kornelius Kalnbach) Contact:: murphy rubychan de Website:: coderay.rubychan.de[http://coderay.rubychan.de] @@ -82,14 +82,18 @@ Please report errors in this documentation to . * Andreas Schwarz for finding out that CaseIgnoringWordList was not case ignoring! Such things really make you write tests. * closure for the first version of the Scheme scanner. -* Stefan Walk for the first version of the JavaScript scanner. -* Josh Goebel for another version of the JavaScript scanner and a Diff scanner. +* Stefan Walk for the first version of the JavaScript and PHP scanners. +* Josh Goebel for another version of the JavaScript scanner, a SQL and a Diff scanner. * Jonathan Younger for pointing out the licence confusion caused by wrong LICENSE file. * Jeremy Hinegardner for finding the shebang-on-empty-file bug in FileType. * Charles Oliver Nutter and Yehuda Katz for helping me benchmark CodeRay on JRuby. * Andreas Neuhaus for pointing out a markup bug in coderay/for_redcloth. * 0xf30fc7 for the FileType patch concerning Delphi file extensions. * The folks at redmine.org - thank you for using and fixing CodeRay! +* Keith Pitt for his SQL scanners +* Rob Aldred for the terminal encoder +* Trans for pointing out $DEBUG dependencies +* Flameeyes for finding that Term::ANSIColor was obsolete * matz and all Ruby gods and gurus * The inventors of: the computer, the internet, the true color display, HTML & CSS, VIM, Ruby, pizza, microwaves, guitars, scouting, programming, anime, diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index d43805d..56857dc 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -262,7 +262,7 @@ module Encoders @out << (@css_style[@opened] || '') @opened << type when :close - if $CODERAY_DEBUG and @opened.last != type + if $CODERAY_DEBUG and (@opened.size == 1 or @opened.last != type) warn 'Malformed token stream: Trying to close a token (%p) ' \ 'that is not open. Open are: %p.' % [type, @opened[1..-1]] end @@ -283,7 +283,7 @@ module Encoders end @opened << type when :end_line - if $CODERAY_DEBUG and @opened.last != type + if $CODERAY_DEBUG and (@opened.size == 1 or @opened.last != type) warn 'Malformed token stream: Trying to close a line (%p) ' \ 'that is not open. Open are: %p.' % [type, @opened[1..-1]] end diff --git a/lib/coderay/encoders/terminal.rb b/lib/coderay/encoders/terminal.rb index 782147a..7224218 100644 --- a/lib/coderay/encoders/terminal.rb +++ b/lib/coderay/encoders/terminal.rb @@ -19,6 +19,7 @@ module CodeRay register_for :terminal TOKEN_COLORS = { + :annotation => '35', :attribute_name => '33', :attribute_value => '31', :bin => '1;35', @@ -29,10 +30,13 @@ module CodeRay :class_variable => '36', :color => '32', :comment => '37', + :complex => '34', :constant => ['34', '4'], + :decoration => '35', :definition => '1;32', :directive => ['32', '4'], :doc => '46', + :doctype => '1;30', :doc_string => ['31', '4'], :entity => '33', :error => ['1;33', '41'], @@ -44,6 +48,7 @@ module CodeRay :include => '33', :integer => '1;34', :interpreted => '1;35', + :key => '35', :label => '1;15', :local_variable => '33', :oct => '1;35', @@ -52,6 +57,7 @@ module CodeRay :pre_type => '1;30', :predefined => ['4', '1;34'], :preprocessor => '36', + :pseudo_class => '34', :regexp => { :self => '31', :content => '31', @@ -60,20 +66,32 @@ module CodeRay :function => '1;29' }, :reserved => '1;31', - :shell => {:self => '42', :content => '1;29'}, - :string => '32', + :shell => { + :self => '42', + :content => '1;29', + :delimiter => '37', + }, + :string => { + :self => '32', + :modifier => '1;32', + :escape => '1;36', + :delimiter => '1;32', + }, :symbol => '1;32', :tag => '34', :tag_special => ['34', '4'], :type => '1;34', + :value => '36', :variable => '34', :insert => '42', :delete => '41', :change => '44', - :head => '41' + :head => '45' } + TOKEN_COLORS[:keyword] = TOKEN_COLORS[:reserved] TOKEN_COLORS[:method] = TOKEN_COLORS[:function] + TOKEN_COLORS[:imaginary] = TOKEN_COLORS[:complex] TOKEN_COLORS[:open] = TOKEN_COLORS[:close] = TOKEN_COLORS[:nesting_delimiter] = TOKEN_COLORS[:escape] = TOKEN_COLORS[:delimiter] protected diff --git a/lib/coderay/for_redcloth.rb b/lib/coderay/for_redcloth.rb index 43b2268..5149562 100644 --- a/lib/coderay/for_redcloth.rb +++ b/lib/coderay/for_redcloth.rb @@ -13,10 +13,20 @@ module CodeRay module ForRedCloth def self.install - gem 'RedCloth', '>= 4.0.3' rescue nil + gem 'RedCloth', '>= 4.0.3' if defined? gem require 'redcloth' unless RedCloth::VERSION.to_s >= '4.0.3' - raise 'CodeRay.for_redcloth needs RedCloth version 4.0.3 or later.' + if defined? gem + raise 'CodeRay.for_redcloth needs RedCloth version 4.0.3 or later. ' + + "You have #{RedCloth::VERSION}. Please gem install RedCloth." + else + $".delete 'redcloth.rb' # sorry, but it works + require 'rubygems' + return install # retry + end + end + unless RedCloth::VERSION.to_s >= '4.2.2' + warn 'CodeRay.for_redcloth works best with RedCloth version 4.2.2 or later.' end RedCloth::TextileDoc.send :include, ForRedCloth::TextileDoc RedCloth::Formatters::HTML.module_eval do diff --git a/lib/coderay/scanners/php.rb b/lib/coderay/scanners/php.rb index 73c4fc8..289e795 100644 --- a/lib/coderay/scanners/php.rb +++ b/lib/coderay/scanners/php.rb @@ -216,6 +216,7 @@ module Scanners \.(?!\d)=? | # dot that is not decimal point, string concatenation && | \|\| | # logic :: | -> | => | # scope, member, dictionary + \\(?!\n) | # namespace \+\+ | -- | # increment, decrement [,;?:()\[\]{}] | # simple delimiters [-+*\/%&|^]=? | # ordinary math, binary logic, assignment shortcuts diff --git a/lib/coderay/scanners/yaml.rb b/lib/coderay/scanners/yaml.rb index fa29701..62a6aba 100644 --- a/lib/coderay/scanners/yaml.rb +++ b/lib/coderay/scanners/yaml.rb @@ -125,9 +125,9 @@ module Scanners if $CODERAY_DEBUG and not kind raise_inspect 'Error token %p in line %d' % - [[match, kind], line], tokens + [[match, kind], line], tokens, state end - raise_inspect 'Empty token', tokens unless match + raise_inspect 'Empty token', tokens, state unless match tokens << [match, kind] diff --git a/lib/coderay/tokens.rb b/lib/coderay/tokens.rb index 0cefef2..2a0dc15 100644 --- a/lib/coderay/tokens.rb +++ b/lib/coderay/tokens.rb @@ -7,29 +7,30 @@ module CodeRay # # A token is not a special object, just a two-element Array # consisting of + # * the _token_ _text_ (the original source of the token in a String) or + # a _token_ _action_ (:open, :close, :begin_line, :end_line) # * the _token_ _kind_ (a Symbol representing the type of the token) - # * the _token_ _text_ (the original source of the token in a String) # # A token looks like this: # - # [:comment, '# It looks like this'] - # [:float, '3.1415926'] - # [:error, '$^'] + # ['# It looks like this', :comment] + # ['3.1415926', :float] + # ['$^', :error] # - # Some scanners also yield some kind of sub-tokens, represented by special - # token texts, namely :open and :close . + # Some scanners also yield sub-tokens, represented by special + # token actions, namely :open and :close. # # The Ruby scanner, for example, splits "a string" into: # # [ # [:open, :string], - # [:delimiter, '"'], - # [:content, 'a string'], - # [:delimiter, '"'], + # ['"', :delimiter], + # ['a string', :content], + # ['"', :delimiter], # [:close, :string] # ] # - # Tokens is also the interface between Scanners and Encoders: + # Tokens is the interface between Scanners and Encoders: # The input is split and saved into a Tokens object. The Encoder # then builds the output from this object. # @@ -43,6 +44,9 @@ module CodeRay # Tokens gives you the power to handle pre-scanned code very easily: # You can convert it to a webpage, a YAML file, or dump it into a gzip'ed string # that you put in your DB. + # + # It also allows you to generate tokens directly (without using a scanner), + # to load them from a file, and still use any Encoder that CodeRay provides. # # Tokens' subclass TokenStream allows streaming to save memory. class Tokens < Array @@ -128,7 +132,6 @@ module CodeRay # for example, consecutive //-comment lines could already be # joined in one comment token by the Scanner. def optimize - # print ' Tokens#optimize: before: %d - ' % size last_kind = last_text = nil new = self.class.new for text, kind in self @@ -147,7 +150,6 @@ module CodeRay end end new << [last_text, last_kind] if last_kind - # print 'after: %d (%d saved = %2.0f%%)' % [new.size, size - new.size, 1.0 - (new.size.to_f / size)] new end @@ -302,11 +304,11 @@ module CodeRay # # require 'coderay' # - # token_stream = CodeRay::TokenStream.new do |kind, text| + # token_stream = CodeRay::TokenStream.new do |text, kind| # puts 'kind: %s, text size: %d.' % [kind, text.size] # end # - # token_stream << [:regexp, '/\d+/'] + # token_stream << ['/\d+/', :regexp] # #-> kind: rexpexp, text size: 5. # def initialize &block diff --git a/rake_helpers/del_vim_orphans.rb b/rake_helpers/del_vim_orphans.rb deleted file mode 100644 index abf825e..0000000 --- a/rake_helpers/del_vim_orphans.rb +++ /dev/null @@ -1,43 +0,0 @@ -$saveable = 0.0 - -puts -puts 'Searching for vim backup files...' -puts - -for sw in Dir['**/.*.sw*'] - file = File.join(File.dirname(sw), File.basename(sw)[/^.(.*).sw.$/, 1]) - - status = - if not File.exist? file - 'MISSING!' - elsif File.mtime(sw) > File.mtime(file) - 'changed' - else - 'deprecated' - end - deprecated = (status == 'deprecated' or ARGV.include? '-A') - - size = File.size(sw).to_f / 1024 - $saveable += size if deprecated - - action = - if ARGV.include? '-D' - if deprecated - begin - File.delete sw - rescue => boom - boom.class.name - else - 'delete' - end - end - else - '' - end - - puts " %-13s [%3.0f KB] %-60s %-13s" % [ - status, size, file, action] -end - -puts -puts '%3.0f KB can be saved.' % $saveable diff --git a/rake_helpers/ftp.rb b/rake_helpers/ftp.rb deleted file mode 100644 index 1127c71..0000000 --- a/rake_helpers/ftp.rb +++ /dev/null @@ -1,47 +0,0 @@ -FTP_YAML = File.expand_path(File.join(File.dirname(__FILE__), '..', 'ftp.yaml')) -FTP_DOMAIN = 'cycnus.de' -FTP_CODERAY_DIR = 'public_html/raindark/coderay' - -def prepare_ftp - require 'net/ftp' - require 'yaml' - $username = File.exist?(FTP_YAML) ? YAML.load_file(FTP_YAML)[:username] : 'anonymous' - g "ftp login, password for #$username needed: " - $password = $stdin.gets.chomp -end - -def cYcnus_ftp - prepare_ftp unless $password - Net::FTP.open(FTP_DOMAIN) do |ftp| - g "login for #$username..." - ftp.login $username, $password - gn 'logged in.' - yield ftp - end -end - -def uploader_for ftp - proc do |l, *r| - r = r.first || l - raise 'File %s not found!' % l unless File.exist? l - if l == r - g 'Uploading %s...' % [l] - else - g 'Uploading %s to %s...' % [l, r] - end - ftp.putbinaryfile l, r - gd - end -end - -def g msg - $stderr.print msg -end - -def gn msg = '' - $stderr.puts msg -end - -def gd - gn 'done.' -end diff --git a/rake_tasks/documentation.rake b/rake_tasks/documentation.rake index 9a96a02..162699d 100644 --- a/rake_tasks/documentation.rake +++ b/rake_tasks/documentation.rake @@ -1,24 +1,16 @@ -require 'rake/rdoctask' -require 'pathname' - -CODERAY_TEMPLATE = Pathname.new(File.dirname(__FILE__)).join('..', 'rake_helpers', 'coderay_rdoc_template.rb').expand_path.to_s - -def set_rdoc_info rd +desc 'Generate documentation for CodeRay' +Rake::RDocTask.new :doc do |rd| rd.main = 'lib/README' - rd.title = "CodeRay Documentation" + rd.title = 'CodeRay Documentation' + rd.options << '--line-numbers' << '--inline-source' << '--tab-width' << '2' rd.options << '--fmt' << ENV.fetch('format', 'html_coderay') - # rd.options << '--all' + require 'pathname' + template = File.join ROOT, 'rake_helpers', 'coderay_rdoc_template.rb' + rd.template = Pathname.new(template).expand_path.to_s - rd.template = ENV.fetch('template', CODERAY_TEMPLATE) - rd.rdoc_files.add(*EXTRA_FILES.in(ROOT)) - rd.rdoc_files.add(*Dir[File.join(LIB_ROOT, 'coderay', '**', '*.rb')]) - rd.rdoc_files.add(*Dir[File.join(LIB_ROOT, '*.rb')]) -end - -desc 'Generate documentation for CodeRay' -Rake::RDocTask.new :doc do |rd| - set_rdoc_info rd + rd.rdoc_files.add EXTRA_RDOC_FILES + rd.rdoc_files.add Dir['lib'] rd.rdoc_dir = 'doc' end diff --git a/rake_tasks/example.rake b/rake_tasks/example.rake deleted file mode 100644 index dfd594a..0000000 --- a/rake_tasks/example.rake +++ /dev/null @@ -1,25 +0,0 @@ -namespace :example do - - desc 'Generate an example output' - task :make do - system "#{RUBY} -wIlib ../hidden/highlight.rb -1 -L -I lib lib/coderay/**/" - end - - desc 'Upload example to ' + FTP_DOMAIN - task :upload => :make do - gn 'Highlighting self...' - gd - gn 'Uploading example:' - cYcnus_ftp do |ftp| - ftp.chdir FTP_CODERAY_DIR - uploader = proc do |l, r| - g 'Uploading %s to %s...' % [l, r] - ftp.putbinaryfile l, r - gd - end - uploader.call 'highlighted/all_in_one.html', 'example.html' - end - gn 'Example uploaded.' - end - -end diff --git a/rake_tasks/gem.rake b/rake_tasks/gem.rake index 9db4442..328a32e 100644 --- a/rake_tasks/gem.rake +++ b/rake_tasks/gem.rake @@ -12,20 +12,16 @@ def gemspec s.requirements = [] s.date = Time.now.strftime '%Y-%m-%d' s.has_rdoc = true - s.rdoc_options = '-SNw2', '-mlib/README', '-a', '-t CodeRay Documentation' - s.extra_rdoc_files = EXTRA_FILES.in('./') + s.rdoc_options = '-SNw2', '-mlib/README', '-t CodeRay Documentation' + s.extra_rdoc_files = EXTRA_RDOC_FILES # Description s.summary = <<-EOF - CodeRay is a fast syntax highlighter engine for many languages. +Fast syntax highlighting for selected languages. EOF s.description = <<-EOF - CodeRay is a Ruby library for syntax highlighting. - I try to make CodeRay easy to use and intuitive, but at the same time - fully featured, complete, fast and efficient. - - Usage is simple: - CodeRay.scan(code, :ruby).div +Fast and easy syntax highlighting for selected languages, written in Ruby. +Comes with RedCloth integration and LOC counter. EOF # Files @@ -41,6 +37,11 @@ def gemspec end end +def svn_head_revision + sh 'svn up --ignore-externals' + `svn info`[/Revision: (\d+)/,1] +end + namespace :gem do gemtask = Rake::GemPackageTask.new(gemspec) do |pkg| @@ -48,7 +49,7 @@ namespace :gem do pkg.need_tar = true end - desc 'Create the gem again' + desc 'Create the Gem again' task :make => [:make_gemspec, :clean, :gem] desc 'Delete previously created Gems' @@ -66,25 +67,34 @@ namespace :gem do end puts 'Current Version: %s' % $version if $version[/.0$/] - sh 'svn up --ignore-externals' - $version << '.' << `svn info`[/Revision: (\d+)/,1] + $version << '.' << svn_head_revision $gem_name << '-beta' end + if ENV['pre'] + $version << '.' << svn_head_revision + $version << '.pre' + end end task :make_gemspec => :get_version do - candidates = Dir['./lib/**/*.rb'] + - Dir['./demo/*.rb'] + - # Dir['./bin/*'] + - # Dir['./demo/bench/*'] + - # Dir['./test/*'] + - %w( ./lib/README ./LICENSE) s = gemtask.gem_spec - s.files = candidates #.delete_if { |item| item[/(?:CVS|rdoc)|~$/] } + s.files = Dir['./lib/**/*.rb'] + + Dir['./demo/*.rb'] + + Dir['./Rakefile'] + + Dir['./test/functional/*'] + + %w(./lib/README ./LICENSE) + s.test_file = './test/functional/suite.rb' gemtask.version = s.version = $version gemtask.name = s.name = $gem_name end - + + task :set_pre do + ENV['pre'] = 'true' + end + + desc 'Make a prerelease Gem.' + task :prerelease => [:set_pre, :make] + end task :gem => 'gem:make' \ No newline at end of file diff --git a/rake_tasks/ruby-versions.rake b/rake_tasks/ruby-versions.rake new file mode 100644 index 0000000..bfb1f88 --- /dev/null +++ b/rake_tasks/ruby-versions.rake @@ -0,0 +1,48 @@ +RUBY = ENV.fetch 'ruby', 'ruby' + +def ruby command + params = + if RUBY == 'rbx' + '-I/usr/local/lib/ruby/1.8' + else + '-w' + end + cmd = "#{RUBY} #{params} #{command}" + puts cmd if verbose + system cmd +end + +task '19' do + RUBY.replace 'ruby19' +end + +task '18' do + RUBY.replace 'ruby18' +end + +task '187' do + RUBY.replace 'ruby187' +end + +task 'jruby' do + RUBY.replace 'jruby' +end +task :j => :jruby + +task 'jruby19' do + RUBY.replace 'jruby --1.9' +end +task :j19 => :jruby19 + +task 'jruby-nailgun' do + RUBY.replace 'jruby --ng' +end +task :jng => :'jruby-nailgun' + +task 'rubinius' do + RUBY.replace 'rbx' +end + +task 'ee' do + RUBY.replace 'rubyee' +end diff --git a/rake_tasks/rubyforge.rake b/rake_tasks/rubyforge.rake deleted file mode 100644 index 83fa0fc..0000000 --- a/rake_tasks/rubyforge.rake +++ /dev/null @@ -1,33 +0,0 @@ -RUBYFORGE_TRUNK_DIR = 'L:/rubyforge/trunk/coderay/trunk' -CODERAY_TRUNK_DIR = 'L:/root/trunk' - -namespace :rubyforge do - - desc 'Export trunk to Rubyforge working copy via SVN' - task :export do - system 'svn st' - puts 'Exporting changelog.' - system 'svn log > ../changelog.txt' - system "svn export #{`svn info`[/URL: (.*)/,1]}/ #{RUBYFORGE_TRUNK_DIR} --force" - cp '../changelog.txt', "#{RUBYFORGE_TRUNK_DIR}/.." - Dir.chdir RUBYFORGE_TRUNK_DIR do - system "svn st" - end - end - - desc 'Export trunk to Rubyforge working copy via SVN' - task :import do - Dir.chdir RUBYFORGE_TRUNK_DIR do - #system 'svn st' - #puts 'Exporting changelog.' - #system 'svn log > ../changelog.txt' - system "svn export #{`svn info`[/URL: (.*)/,1]}/ #{CODERAY_TRUNK_DIR} --force" - end - #cp '../changelog.txt', "#{RUBYFORGE_TRUNK_DIR}/.." - system "svn st" - end - -end - -task :import => 'rubyforge:import' -task :export => 'rubyforge:export' diff --git a/rake_tasks/test.rake b/rake_tasks/test.rake index 80c557f..67c6f62 100644 --- a/rake_tasks/test.rake +++ b/rake_tasks/test.rake @@ -6,7 +6,9 @@ namespace :test do desc 'run functional tests' task :functional do - ruby "./test/functional/suite.rb" + ENV['check_rubygems'] = 'true' + ruby './test/functional/suite.rb' + ruby './test/functional/for_redcloth.rb' end namespace :functional do @@ -25,11 +27,6 @@ namespace :test do end end - desc 'run for_redcloth tests' - task :for_redcloth do - ruby "./test/functional/for_redcloth.rb" - end - desc 'run all scanner tests' task :scanners do ruby "./test/scanners/suite.rb" @@ -71,7 +68,6 @@ namespace :test do ruby '-v' Rake::Task['test'].reenable Rake::Task['test:functional'].reenable - Rake::Task['test:for_redcloth'].reenable Rake::Task['test:scanners'].reenable Rake::Task['test'].invoke else @@ -82,5 +78,5 @@ namespace :test do end -task :test => %w( test:functional test:for_redcloth test:scanners ) +task :test => %w( test:functional test:scanners ) task :samples => 'test:samples' \ No newline at end of file diff --git a/test/functional/basic.rb b/test/functional/basic.rb index 9f68763..150089e 100755 --- a/test/functional/basic.rb +++ b/test/functional/basic.rb @@ -1,5 +1,5 @@ -require "test/unit" -require "coderay" +require 'test/unit' +require 'coderay' class BasicTest < Test::Unit::TestCase @@ -103,7 +103,7 @@ more code # and another comment, in-line. def test_rubygems_not_loaded assert_equal nil, defined? Gem - end unless RUBY_VERSION >= '1.9' + end if ENV['check_rubygems'] && RUBY_VERSION < '1.9' def test_list_of_encoders assert_kind_of(Array, CodeRay::Encoders.list) diff --git a/test/functional/for_redcloth.rb b/test/functional/for_redcloth.rb index e955e30..a1c3100 100644 --- a/test/functional/for_redcloth.rb +++ b/test/functional/for_redcloth.rb @@ -1,23 +1,18 @@ -require "test/unit" - -require 'pathname' -MYDIR = File.dirname(__FILE__) -LIBDIR = Pathname.new(MYDIR).join('..', '..', 'lib').cleanpath.to_s -$LOAD_PATH.unshift LIBDIR -require "coderay" +require 'test/unit' +$: << 'lib' +require 'coderay' begin - require 'rubygems' + require 'rubygems' unless defined? Gem gem 'RedCloth', '>= 4.0.3' rescue nil require 'redcloth' rescue LoadError - $stderr.puts 'RedCloth not found - skipping for_redcloth tests.' + warn 'RedCloth not found - skipping for_redcloth tests.' end class BasicTest < Test::Unit::TestCase def test_for_redcloth - require 'rubygems' require 'coderay/for_redcloth' assert_equal "

puts "Hello, World!"

", RedCloth.new('@[ruby]puts "Hello, World!"@').to_html @@ -30,7 +25,6 @@ class BasicTest < Test::Unit::TestCase end def test_for_redcloth_no_lang - require 'rubygems' require 'coderay/for_redcloth' assert_equal "

puts \"Hello, World!\"

", RedCloth.new('@puts "Hello, World!"@').to_html @@ -41,7 +35,6 @@ class BasicTest < Test::Unit::TestCase end def test_for_redcloth_style - require 'rubygems' require 'coderay/for_redcloth' assert_equal <<-BLOCKCODE.chomp,
puts \"Hello, World!\"
@@ -50,7 +43,6 @@ class BasicTest < Test::Unit::TestCase end def test_for_redcloth_escapes - require 'rubygems' require 'coderay/for_redcloth' assert_equal '

>

', RedCloth.new('@[ruby]>@').to_html @@ -63,7 +55,6 @@ class BasicTest < Test::Unit::TestCase end def test_for_redcloth_escapes2 - require 'rubygems' require 'coderay/for_redcloth' assert_equal "

#include <test.h>

", RedCloth.new('@[c]#include @').to_html @@ -71,7 +62,6 @@ class BasicTest < Test::Unit::TestCase # See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets. def test_for_redcloth_false_positive - require 'rubygems' require 'coderay/for_redcloth' assert_equal '

[project]_dff.skjd

', RedCloth.new('@[project]_dff.skjd@').to_html diff --git a/test/functional/load_plugin_scanner.rb b/test/functional/load_plugin_scanner.rb index d778e08..25bbc93 100755 --- a/test/functional/load_plugin_scanner.rb +++ b/test/functional/load_plugin_scanner.rb @@ -1,5 +1,5 @@ -require "test/unit" -require "coderay" +require 'test/unit' +require 'coderay' class PluginScannerTest < Test::Unit::TestCase diff --git a/test/functional/suite.rb b/test/functional/suite.rb index ae9c7f0..039ab47 100755 --- a/test/functional/suite.rb +++ b/test/functional/suite.rb @@ -1,10 +1,12 @@ require 'test/unit' -require 'pathname' MYDIR = File.dirname(__FILE__) -LIBDIR = Pathname.new(MYDIR).join('..', '..', 'lib').cleanpath.to_s -$LOAD_PATH.unshift MYDIR, LIBDIR -require 'basic' -require 'load_plugin_scanner' -require 'word_list' +$: << 'lib' +require 'coderay' +puts "Running basic CodeRay #{CodeRay::VERSION} tests..." + +suite = %w(basic load_plugin_scanner word_list) +for test_case in suite + load File.join(MYDIR, test_case + '.rb') +end diff --git a/test/functional/word_list.rb b/test/functional/word_list.rb index 04f4a02..84d6e9e 100644 --- a/test/functional/word_list.rb +++ b/test/functional/word_list.rb @@ -1,5 +1,5 @@ -require "test/unit" -require "coderay" +require 'test/unit' +require 'coderay' class WordListTest < Test::Unit::TestCase diff --git a/test/lib/README b/test/lib/README index dd18540..7d7a0a0 100644 --- a/test/lib/README +++ b/test/lib/README @@ -1,2 +1,3 @@ Contents: -- test/unit: We need the old Test::Unit for the scanner test suite to work with Ruby 1.9. \ No newline at end of file +- test/unit: We need the old Test::Unit for the scanner test suite to work with Ruby 1.9. +- term/ansicolor: Used for colorful output of the scanner tests. \ No newline at end of file diff --git a/test/scanners/coderay_suite.rb b/test/scanners/coderay_suite.rb index 60f71be..3a98c6b 100644 --- a/test/scanners/coderay_suite.rb +++ b/test/scanners/coderay_suite.rb @@ -11,6 +11,8 @@ $:.unshift File.join($mydir, '..', 'lib') require 'term/ansicolor' unless ENV['nocolor'] +require 'test/unit' + if defined? Term::ANSIColor class String include Term::ANSIColor @@ -413,6 +415,13 @@ module CodeRay return false end File.open(actual_html, 'w') { |f| f.write highlighted } + if okay + debug = $DEBUG + $DEBUG = false + FileUtils.copy(actual_html, name + '.expected.html') + $DEBUG = debug + end + true end expected_html = name + '.expected.html' diff --git a/test/scanners/debug/class.expected.raydebug b/test/scanners/debug/class.expected.raydebug index 501c99f..a53cdd6 100644 --- a/test/scanners/debug/class.expected.raydebug +++ b/test/scanners/debug/class.expected.raydebug @@ -12,3 +12,4 @@ < !! Folder )inline operator(+) ident(name)delimiter(})>content( not found --- > !! Folder )inline operator(+) ident(name)inline_delimiter(})>content( not found +) \ No newline at end of file diff --git a/test/scanners/php/namespaces.expected.raydebug b/test/scanners/php/namespaces.expected.raydebug new file mode 100644 index 0000000..47074a9 --- /dev/null +++ b/test/scanners/php/namespaces.expected.raydebug @@ -0,0 +1,9 @@ +inline_delimiter() diff --git a/test/scanners/php/namespaces.in.php b/test/scanners/php/namespaces.in.php new file mode 100644 index 0000000..ad6a1a1 --- /dev/null +++ b/test/scanners/php/namespaces.in.php @@ -0,0 +1,9 @@ + -- cgit v1.2.1