coderay 1.1.1.rc1 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: db55e93b3bbf78f5735b2f773d6045bed6440396
4
- data.tar.gz: e3a4924713b0ddeb0e020a7458bead68a3e8392b
2
+ SHA256:
3
+ metadata.gz: 0c0890d58def476dafbfe55ddf09fffa98621eefedc78a2d412e15bc0977b86c
4
+ data.tar.gz: da2b370828afa384e4c29797030ec1b29961921816641532170ee5fc70c7cd72
5
5
  SHA512:
6
- metadata.gz: 4dac94e6b64bb0b3539338dcb8d124516c0b00b4197a914fef9d6f005fb31f305672a01aba9a4b850e7ecd7d335e353edeb71a6b23697f65ea6fa5682630cdff
7
- data.tar.gz: 7e22b33be218c07b18dbefd507dc5ef468c91c1d38e5bc5043114a11fa575b77e77f5d4e09f99c9e933c415b5505a22e242acd84c2eecad306a44e3a35366e8a
6
+ metadata.gz: 68d2a7c3fc24064c891ca96469c15f5e83725905cfaee2450c959837a8fb6721d91169a562b54ac8d8e24b1f5ac1bb2def6425114ba1eb6361cfbc791905f5b5
7
+ data.tar.gz: 66264030b91ae0f7b32e6e1bbda73889f01984f6556e805b0bfc55fa6a5c3c0da0def08ee3f0c879aba74efa6b2f74911e45f6c0af42bd98a068df54621a622a
@@ -0,0 +1,22 @@
1
+ Copyright (C) 2005-2012 Kornelius Kalnbach <murphy@rubychan.de> (@murphy_karasu)
2
+
3
+ http://coderay.rubychan.de/
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -146,7 +146,7 @@ module CodeRay
146
146
  end
147
147
 
148
148
  def get_output options
149
- options[:out] || ''
149
+ options[:out] || ''.dup
150
150
  end
151
151
 
152
152
  # Append data.to_s to the output. Returns the argument.
@@ -176,7 +176,7 @@ module Encoders
176
176
 
177
177
  if options[:wrap] || options[:line_numbers]
178
178
  @real_out = @out
179
- @out = ''
179
+ @out = ''.dup
180
180
  end
181
181
 
182
182
  @break_lines = (options[:break_lines] == true)
@@ -314,7 +314,7 @@ module Encoders
314
314
  end
315
315
 
316
316
  def break_lines text, style
317
- reopen = ''
317
+ reopen = ''.dup
318
318
  @opened.each_with_index do |kind, index|
319
319
  reopen << (@span_for_kinds[index > 0 ? [kind, *@opened[0...index]] : kind] || '<span>')
320
320
  end
@@ -76,8 +76,6 @@ module Encoders
76
76
  apply_title! title
77
77
  end
78
78
  self
79
- when nil
80
- return self
81
79
  else
82
80
  raise "Unknown value %p for :wrap" % element
83
81
  end
@@ -37,7 +37,7 @@ module Scanners
37
37
  add(PREDEFINED_CONSTANTS, :predefined_constant) # :nodoc:
38
38
 
39
39
  ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
40
- UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
40
+ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
41
41
 
42
42
  protected
43
43
 
@@ -2,14 +2,14 @@ module CodeRay
2
2
  module Scanners
3
3
 
4
4
  # Scanner for C++.
5
- #
5
+ #
6
6
  # Aliases: +cplusplus+, c++
7
7
  class CPlusPlus < Scanner
8
8
 
9
9
  register_for :cpp
10
10
  file_extension 'cpp'
11
11
  title 'C++'
12
-
12
+
13
13
  #-- http://www.cppreference.com/wiki/keywords/start
14
14
  KEYWORDS = [
15
15
  'and', 'and_eq', 'asm', 'bitand', 'bitor', 'break',
@@ -17,28 +17,30 @@ module Scanners
17
17
  'continue', 'default', 'delete', 'do', 'dynamic_cast', 'else',
18
18
  'enum', 'export', 'for', 'goto', 'if', 'namespace', 'new',
19
19
  'not', 'not_eq', 'or', 'or_eq', 'reinterpret_cast', 'return',
20
- 'sizeof', 'static_cast', 'struct', 'switch', 'template',
21
- 'throw', 'try', 'typedef', 'typeid', 'typename', 'union',
20
+ 'sizeof', 'static_assert', 'static_cast', 'struct', 'switch',
21
+ 'template', 'throw', 'try', 'typedef', 'typeid', 'typename', 'union',
22
22
  'while', 'xor', 'xor_eq',
23
23
  ] # :nodoc:
24
-
24
+
25
25
  PREDEFINED_TYPES = [
26
- 'bool', 'char', 'double', 'float', 'int', 'long',
27
- 'short', 'signed', 'unsigned', 'wchar_t', 'string',
26
+ 'bool', 'char', 'char16_t', 'char32_t', 'double', 'float',
27
+ 'int', 'long', 'short', 'signed', 'unsigned',
28
+ 'wchar_t', 'string',
28
29
  ] # :nodoc:
29
30
  PREDEFINED_CONSTANTS = [
30
31
  'false', 'true',
31
- 'EOF', 'NULL',
32
+ 'EOF', 'NULL', 'nullptr'
32
33
  ] # :nodoc:
33
34
  PREDEFINED_VARIABLES = [
34
35
  'this',
35
36
  ] # :nodoc:
36
37
  DIRECTIVES = [
37
- 'auto', 'const', 'explicit', 'extern', 'friend', 'inline', 'mutable', 'operator',
38
- 'private', 'protected', 'public', 'register', 'static', 'using', 'virtual', 'void',
39
- 'volatile',
38
+ 'alignas', 'alignof', 'auto', 'const', 'constexpr', 'decltype', 'explicit',
39
+ 'extern', 'final', 'friend', 'inline', 'mutable', 'noexcept', 'operator',
40
+ 'override', 'private', 'protected', 'public', 'register', 'static',
41
+ 'thread_local', 'using', 'virtual', 'void', 'volatile',
40
42
  ] # :nodoc:
41
-
43
+
42
44
  IDENT_KIND = WordList.new(:ident).
43
45
  add(KEYWORDS, :keyword).
44
46
  add(PREDEFINED_TYPES, :predefined_type).
@@ -47,10 +49,10 @@ module Scanners
47
49
  add(PREDEFINED_CONSTANTS, :predefined_constant) # :nodoc:
48
50
 
49
51
  ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
50
- UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
51
-
52
+ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
53
+
52
54
  protected
53
-
55
+
54
56
  def scan_tokens encoder, options
55
57
 
56
58
  state = :initial
@@ -107,7 +109,7 @@ module Scanners
107
109
 
108
110
  elsif match = scan(/\$/)
109
111
  encoder.text_token match, :ident
110
-
112
+
111
113
  elsif match = scan(/L?"/)
112
114
  encoder.begin_group :string
113
115
  if match[0] == ?L
@@ -180,7 +182,7 @@ module Scanners
180
182
  state = :initial
181
183
 
182
184
  end
183
-
185
+
184
186
  when :class_name_expected
185
187
  if match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
186
188
  encoder.text_token match, :class
@@ -194,7 +196,7 @@ module Scanners
194
196
  state = :initial
195
197
 
196
198
  end
197
-
199
+
198
200
  else
199
201
  raise_inspect 'Unknown state', encoder
200
202
 
@@ -109,7 +109,7 @@ module Scanners
109
109
  for deleted_line, inserted_line in deleted_lines.zip(inserted_lines)
110
110
  pre, deleted_part, inserted_part, post = diff deleted_line, inserted_line
111
111
  content_scanner_entry_state = content_scanner.state
112
- deleted_lines_tokenized << content_scanner.tokenize([pre, deleted_part, post], :tokens => Tokens.new)
112
+ deleted_lines_tokenized << content_scanner.tokenize([pre, deleted_part, post], :tokens => Tokens.new)
113
113
  content_scanner.state = content_scanner_entry_state || :initial
114
114
  inserted_lines_tokenized << content_scanner.tokenize([pre, inserted_part, post], :tokens => Tokens.new)
115
115
  end
@@ -212,7 +212,7 @@ module Scanners
212
212
  # does not precede the leftmost one from the left.
213
213
  j = -1
214
214
  j -= 1 while j >= j_min && a[j] == b[j]
215
- return a[0...i], a[i..j], b[i..j], (j < -1) ? a[j+1..-1] : ''
215
+ return a[0...i], a[i..j], b[i..j], (j < -1) ? a[j + 1..-1] : ''
216
216
  end
217
217
 
218
218
  end
@@ -22,8 +22,8 @@ module Scanners
22
22
  add(GROOVY_MAGIC_VARIABLES, :local_variable) # :nodoc:
23
23
 
24
24
  ESCAPE = / [bfnrtv$\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
25
- UNICODE_ESCAPE = / u[a-fA-F0-9]{4} /x # :nodoc: no 4-byte unicode chars? U[a-fA-F0-9]{8}
26
- REGEXP_ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} | \d | [bBdDsSwW\/] /x # :nodoc:
25
+ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} /x # :nodoc: no 4-byte unicode chars? U[a-fA-F0-9]{8}
26
+ REGEXP_ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} | \d | [bBdDsSwW\/] /x # :nodoc:
27
27
 
28
28
  # TODO: interpretation inside ', ", /
29
29
  STRING_CONTENT_PATTERN = {
@@ -75,7 +75,7 @@ module Scanners
75
75
 
76
76
  tag = false
77
77
 
78
- if match = scan(/%[\w:]+\/?/)
78
+ if match = scan(/%[-\w:]+\/?/)
79
79
  encoder.text_token match, :tag
80
80
  # if match = scan(/( +)(.+)/)
81
81
  # encoder.text_token self[1], :space
@@ -20,7 +20,7 @@ module Scanners
20
20
  MAGIC_VARIABLES = %w[ this super ] # :nodoc:
21
21
  TYPES = %w[
22
22
  boolean byte char class double enum float int interface long
23
- short void
23
+ short void var
24
24
  ] << '[]' # :nodoc: because int[] should be highlighted as a type
25
25
  DIRECTIVES = %w[
26
26
  abstract extends final implements native private protected public
@@ -38,13 +38,13 @@ module Scanners
38
38
  add(DIRECTIVES, :directive) # :nodoc:
39
39
 
40
40
  ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
41
- UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
41
+ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
42
42
  STRING_CONTENT_PATTERN = {
43
43
  "'" => /[^\\']+/,
44
44
  '"' => /[^\\"]+/,
45
45
  '/' => /[^\\\/]+/,
46
46
  } # :nodoc:
47
- IDENT = /[a-zA-Z_][A-Za-z_0-9]*/ # :nodoc:
47
+ IDENT = RUBY_VERSION < '1.9' ? /[a-zA-Z_][A-Za-z_0-9]*/ : Regexp.new('[[[:alpha:]]_][[[:alnum:]]_]*') # :nodoc:
48
48
 
49
49
  protected
50
50
 
@@ -40,8 +40,8 @@ module Scanners
40
40
  add(KEYWORDS, :keyword) # :nodoc:
41
41
 
42
42
  ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
43
- UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
44
- REGEXP_ESCAPE = / [bBdDsSwW] /x # :nodoc:
43
+ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
44
+ REGEXP_ESCAPE = / [bBdDsSwW] /x # :nodoc:
45
45
  STRING_CONTENT_PATTERN = {
46
46
  "'" => /[^\\']+/,
47
47
  '"' => /[^\\"]+/,
@@ -100,7 +100,6 @@ module Scanners
100
100
  # TODO: scan over nested tags
101
101
  xml_scanner.tokenize match, :tokens => encoder
102
102
  value_expected = false
103
- next
104
103
 
105
104
  elsif match = scan(/ [-+*=<>?:;,!&^|(\[{~%]+ | \.(?!\d) /x)
106
105
  value_expected = true
@@ -76,7 +76,7 @@ module Scanners
76
76
  encoder.text_token(match, :comment)
77
77
 
78
78
  elsif match = scan(/\[=*\[/) # [[ long (possibly multiline) string ]]
79
- num_equals = match.count("=") # Number must match for comment end
79
+ num_equals = match.count("=") # Number must match for string end
80
80
  encoder.begin_group(:string)
81
81
  encoder.text_token(match, :delimiter)
82
82
  state = :long_string
@@ -63,7 +63,7 @@ module Scanners
63
63
 
64
64
  NAME = / [[:alpha:]_] \w* /x # :nodoc:
65
65
  ESCAPE = / [abfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
66
- UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} | N\{[-\w ]+\} /x # :nodoc:
66
+ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} | N\{[-\w ]+\} /x # :nodoc:
67
67
 
68
68
  OPERATOR = /
69
69
  \.\.\. | # ellipsis
@@ -60,7 +60,7 @@ module Scanners
60
60
 
61
61
  QUOTE_TO_TYPE = {
62
62
  '`' => :shell,
63
- '/'=> :regexp,
63
+ '/' => :regexp,
64
64
  }
65
65
  QUOTE_TO_TYPE.default = :string
66
66
 
@@ -29,7 +29,7 @@ module Scanners
29
29
  char varchar varchar2 enum binary text tinytext mediumtext
30
30
  longtext blob tinyblob mediumblob longblob timestamp
31
31
  date time datetime year double decimal float int
32
- integer tinyint mediumint bigint smallint unsigned bit
32
+ integer tinyint mediumint bigint smallint unsigned bit numeric
33
33
  bool boolean hex bin oct
34
34
  )
35
35
 
File without changes
@@ -39,6 +39,9 @@ module CodeRay
39
39
  # You can serialize it to a JSON string and store it in a database, pass it
40
40
  # around to encode it more than once, send it to other algorithms...
41
41
  class Tokens < Array
42
+ # Remove Array#filter that is a new alias for Array#select on Ruby 2.6,
43
+ # for method_missing called with filter method.
44
+ undef_method :filter if instance_methods.include?(:filter)
42
45
 
43
46
  # The Scanner instance that created the tokens.
44
47
  attr_accessor :scanner
@@ -1,3 +1,3 @@
1
1
  module CodeRay
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coderay
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1.rc1
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kornelius Kalnbach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-13 00:00:00.000000000 Z
11
+ date: 2020-05-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fast and easy syntax highlighting for selected languages, written in
14
14
  Ruby. Comes with RedCloth integration and LOC counter.
@@ -20,8 +20,8 @@ extensions: []
20
20
  extra_rdoc_files:
21
21
  - README_INDEX.rdoc
22
22
  files:
23
+ - MIT-LICENSE
23
24
  - README_INDEX.rdoc
24
- - Rakefile
25
25
  - bin/coderay
26
26
  - lib/coderay.rb
27
27
  - lib/coderay/duo.rb
@@ -95,10 +95,6 @@ files:
95
95
  - lib/coderay/tokens.rb
96
96
  - lib/coderay/tokens_proxy.rb
97
97
  - lib/coderay/version.rb
98
- - test/functional/basic.rb
99
- - test/functional/examples.rb
100
- - test/functional/for_redcloth.rb
101
- - test/functional/suite.rb
102
98
  homepage: http://coderay.rubychan.de
103
99
  licenses:
104
100
  - MIT
@@ -117,17 +113,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
113
  version: 1.8.6
118
114
  required_rubygems_version: !ruby/object:Gem::Requirement
119
115
  requirements:
120
- - - ">"
116
+ - - ">="
121
117
  - !ruby/object:Gem::Version
122
- version: 1.3.1
118
+ version: '0'
123
119
  requirements: []
124
- rubyforge_project: coderay
125
- rubygems_version: 2.5.1
120
+ rubygems_version: 3.0.6
126
121
  signing_key:
127
122
  specification_version: 4
128
123
  summary: Fast syntax highlighting for selected languages.
129
- test_files:
130
- - test/functional/basic.rb
131
- - test/functional/examples.rb
132
- - test/functional/for_redcloth.rb
133
- - test/functional/suite.rb
124
+ test_files: []
data/Rakefile DELETED
@@ -1,37 +0,0 @@
1
- require 'bundler/gem_tasks'
2
-
3
- $:.unshift File.dirname(__FILE__) unless $:.include? '.'
4
-
5
- ROOT = '.'
6
- LIB_ROOT = File.join ROOT, 'lib'
7
-
8
- task :default => :test
9
-
10
- if File.directory? 'rake_tasks'
11
-
12
- # load rake tasks from subfolder
13
- for task_file in Dir['rake_tasks/*.rake'].sort
14
- load task_file
15
- end
16
-
17
- else
18
-
19
- # fallback tasks when rake_tasks folder is not present (eg. in the distribution package)
20
- desc 'Run CodeRay tests (basic)'
21
- task :test do
22
- ruby './test/functional/suite.rb'
23
- ruby './test/functional/for_redcloth.rb'
24
- end
25
-
26
- gem 'rdoc' if defined? gem
27
- require 'rdoc/task'
28
- desc 'Generate documentation for CodeRay'
29
- Rake::RDocTask.new :doc do |rd|
30
- rd.title = 'CodeRay Documentation'
31
- rd.main = 'README_INDEX.rdoc'
32
- rd.rdoc_files.add Dir['lib']
33
- rd.rdoc_files.add rd.main
34
- rd.rdoc_dir = 'doc'
35
- end
36
-
37
- end
@@ -1,318 +0,0 @@
1
- # encoding: utf-8
2
- require 'test/unit'
3
- require File.expand_path('../../lib/assert_warning', __FILE__)
4
-
5
- $:.unshift File.expand_path('../../../lib', __FILE__)
6
- require 'coderay'
7
-
8
- class BasicTest < Test::Unit::TestCase
9
-
10
- def test_version
11
- assert_nothing_raised do
12
- assert_match(/\A\d\.\d\.\d?\z/, CodeRay::VERSION)
13
- end
14
- end
15
-
16
- def with_empty_load_path
17
- old_load_path = $:.dup
18
- $:.clear
19
- yield
20
- ensure
21
- $:.replace old_load_path
22
- end
23
-
24
- def test_autoload
25
- with_empty_load_path do
26
- assert_nothing_raised do
27
- CodeRay::Scanners::Java::BuiltinTypes
28
- end
29
- end
30
- end
31
-
32
- RUBY_TEST_CODE = 'puts "Hello, World!"'
33
-
34
- RUBY_TEST_TOKENS = [
35
- ['puts', :ident],
36
- [' ', :space],
37
- [:begin_group, :string],
38
- ['"', :delimiter],
39
- ['Hello, World!', :content],
40
- ['"', :delimiter],
41
- [:end_group, :string]
42
- ].flatten
43
- def test_simple_scan
44
- assert_nothing_raised do
45
- assert_equal RUBY_TEST_TOKENS, CodeRay.scan(RUBY_TEST_CODE, :ruby).tokens
46
- end
47
- end
48
-
49
- RUBY_TEST_HTML = 'puts <span class="string"><span class="delimiter">&quot;</span>' +
50
- '<span class="content">Hello, World!</span><span class="delimiter">&quot;</span></span>'
51
- def test_simple_highlight
52
- assert_nothing_raised do
53
- assert_equal RUBY_TEST_HTML, CodeRay.scan(RUBY_TEST_CODE, :ruby).html
54
- end
55
- end
56
-
57
- def test_scan_file
58
- CodeRay.scan_file __FILE__
59
- end
60
-
61
- def test_encode
62
- assert_equal 1, CodeRay.encode('test', :python, :count)
63
- end
64
-
65
- def test_encode_tokens
66
- assert_equal 1, CodeRay.encode_tokens(CodeRay::Tokens['test', :string], :count)
67
- end
68
-
69
- def test_encode_file
70
- assert_equal File.read(__FILE__), CodeRay.encode_file(__FILE__, :text)
71
- end
72
-
73
- def test_highlight
74
- assert_match '<pre>test</pre>', CodeRay.highlight('test', :python)
75
- end
76
-
77
- def test_highlight_file
78
- assert_match "require <span class=\"string\"><span class=\"delimiter\">'</span><span class=\"content\">test/unit</span><span class=\"delimiter\">'</span></span>\n", CodeRay.highlight_file(__FILE__)
79
- end
80
-
81
- def test_duo
82
- assert_equal(RUBY_TEST_CODE,
83
- CodeRay::Duo[:plain, :text].highlight(RUBY_TEST_CODE))
84
- assert_equal(RUBY_TEST_CODE,
85
- CodeRay::Duo[:plain => :text].highlight(RUBY_TEST_CODE))
86
- end
87
-
88
- def test_duo_stream
89
- assert_equal(RUBY_TEST_CODE,
90
- CodeRay::Duo[:plain, :text].highlight(RUBY_TEST_CODE, :stream => true))
91
- end
92
-
93
- def test_comment_filter
94
- assert_equal <<-EXPECTED, CodeRay.scan(<<-INPUT, :ruby).comment_filter.text
95
- #!/usr/bin/env ruby
96
-
97
- code
98
-
99
- more code
100
- EXPECTED
101
- #!/usr/bin/env ruby
102
- =begin
103
- A multi-line comment.
104
- =end
105
- code
106
- # A single-line comment.
107
- more code # and another comment, in-line.
108
- INPUT
109
- end
110
-
111
- def test_lines_of_code
112
- assert_equal 2, CodeRay.scan(<<-INPUT, :ruby).lines_of_code
113
- #!/usr/bin/env ruby
114
- =begin
115
- A multi-line comment.
116
- =end
117
- code
118
- # A single-line comment.
119
- more code # and another comment, in-line.
120
- INPUT
121
- rHTML = <<-RHTML
122
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
123
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
124
-
125
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
126
- <head>
127
- <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
128
- <title><%= controller.controller_name.titleize %>: <%= controller.action_name %></title>
129
- <%= stylesheet_link_tag 'scaffold' %>
130
- </head>
131
- <body>
132
-
133
- <p style="color: green"><%= flash[:notice] %></p>
134
-
135
- <div id="main">
136
- <%= yield %>
137
- </div>
138
-
139
- </body>
140
- </html>
141
- RHTML
142
- assert_equal 0, CodeRay.scan(rHTML, :html).lines_of_code
143
- assert_equal 0, CodeRay.scan(rHTML, :php).lines_of_code
144
- assert_equal 0, CodeRay.scan(rHTML, :yaml).lines_of_code
145
- assert_equal 4, CodeRay.scan(rHTML, :erb).lines_of_code
146
- end
147
-
148
- def test_list_of_encoders
149
- assert_kind_of(Array, CodeRay::Encoders.list)
150
- assert CodeRay::Encoders.list.include?(:count)
151
- end
152
-
153
- def test_list_of_scanners
154
- assert_kind_of(Array, CodeRay::Scanners.list)
155
- assert CodeRay::Scanners.list.include?(:text)
156
- end
157
-
158
- def test_token_kinds
159
- assert_kind_of Hash, CodeRay::TokenKinds
160
- for kind, css_class in CodeRay::TokenKinds
161
- assert_kind_of Symbol, kind
162
- if css_class != false
163
- assert_kind_of String, css_class, "TokenKinds[%p] == %p" % [kind, css_class]
164
- end
165
- end
166
- assert_equal 'reserved', CodeRay::TokenKinds[:reserved]
167
- assert_equal false, CodeRay::TokenKinds[:shibboleet]
168
- end
169
-
170
- class Milk < CodeRay::Encoders::Encoder
171
- FILE_EXTENSION = 'cocoa'
172
- end
173
-
174
- class HoneyBee < CodeRay::Encoders::Encoder
175
- end
176
-
177
- def test_encoder_file_extension
178
- assert_nothing_raised do
179
- assert_equal 'html', CodeRay::Encoders::Page::FILE_EXTENSION
180
- assert_equal 'cocoa', Milk::FILE_EXTENSION
181
- assert_equal 'cocoa', Milk.new.file_extension
182
- assert_equal 'honeybee', HoneyBee::FILE_EXTENSION
183
- assert_equal 'honeybee', HoneyBee.new.file_extension
184
- end
185
- assert_raise NameError do
186
- HoneyBee::MISSING_CONSTANT
187
- end
188
- end
189
-
190
- def test_encoder_tokens
191
- encoder = CodeRay::Encoders::Encoder.new
192
- encoder.send :setup, {}
193
- assert_raise(ArgumentError) { encoder.token :strange, '' }
194
- encoder.token 'test', :debug
195
- end
196
-
197
- def test_encoder_deprecated_interface
198
- encoder = CodeRay::Encoders::Encoder.new
199
- encoder.send :setup, {}
200
- assert_warning 'Using old Tokens#<< interface.' do
201
- encoder << ['test', :content]
202
- end
203
- assert_raise ArgumentError do
204
- encoder << [:strange, :input]
205
- end
206
- assert_raise ArgumentError do
207
- encoder.encode_tokens [['test', :token]]
208
- end
209
- end
210
-
211
- def encoder_token_interface_deprecation_warning_given
212
- CodeRay::Encoders::Encoder.send :class_variable_get, :@@CODERAY_TOKEN_INTERFACE_DEPRECATION_WARNING_GIVEN
213
- end
214
-
215
- def test_scanner_file_extension
216
- assert_equal 'rb', CodeRay::Scanners::Ruby.file_extension
217
- assert_equal 'rb', CodeRay::Scanners::Ruby.new.file_extension
218
- assert_equal 'java', CodeRay::Scanners::Java.file_extension
219
- assert_equal 'java', CodeRay::Scanners::Java.new.file_extension
220
- end
221
-
222
- def test_scanner_lang
223
- assert_equal :ruby, CodeRay::Scanners::Ruby.lang
224
- assert_equal :ruby, CodeRay::Scanners::Ruby.new.lang
225
- assert_equal :java, CodeRay::Scanners::Java.lang
226
- assert_equal :java, CodeRay::Scanners::Java.new.lang
227
- end
228
-
229
- def test_scanner_tokenize
230
- assert_equal ['foo', :plain], CodeRay::Scanners::Plain.new.tokenize('foo')
231
- assert_equal [['foo', :plain], ['bar', :plain]], CodeRay::Scanners::Plain.new.tokenize(['foo', 'bar'])
232
- CodeRay::Scanners::Plain.new.tokenize 42
233
- end
234
-
235
- def test_scanner_tokens
236
- scanner = CodeRay::Scanners::Plain.new
237
- scanner.tokenize('foo')
238
- assert_equal ['foo', :plain], scanner.tokens
239
- scanner.string = ''
240
- assert_equal ['', :plain], scanner.tokens
241
- end
242
-
243
- def test_scanner_line_and_column
244
- scanner = CodeRay::Scanners::Plain.new "foo\nbär+quux"
245
- assert_equal 0, scanner.pos
246
- assert_equal 1, scanner.line
247
- assert_equal 1, scanner.column
248
- scanner.scan(/foo/)
249
- assert_equal 3, scanner.pos
250
- assert_equal 1, scanner.line
251
- assert_equal 4, scanner.column
252
- scanner.scan(/\n/)
253
- assert_equal 4, scanner.pos
254
- assert_equal 2, scanner.line
255
- assert_equal 1, scanner.column
256
- scanner.scan(/b/)
257
- assert_equal 5, scanner.pos
258
- assert_equal 2, scanner.line
259
- assert_equal 2, scanner.column
260
- scanner.scan(/a/)
261
- assert_equal 5, scanner.pos
262
- assert_equal 2, scanner.line
263
- assert_equal 2, scanner.column
264
- scanner.scan(/ä/)
265
- assert_equal 7, scanner.pos
266
- assert_equal 2, scanner.line
267
- assert_equal 4, scanner.column
268
- scanner.scan(/r/)
269
- assert_equal 8, scanner.pos
270
- assert_equal 2, scanner.line
271
- assert_equal 5, scanner.column
272
- end
273
-
274
- def test_scanner_use_subclasses
275
- assert_raise NotImplementedError do
276
- CodeRay::Scanners::Scanner.new
277
- end
278
- end
279
-
280
- class InvalidScanner < CodeRay::Scanners::Scanner
281
- end
282
-
283
- def test_scanner_scan_tokens
284
- assert_raise NotImplementedError do
285
- InvalidScanner.new.tokenize ''
286
- end
287
- end
288
-
289
- class RaisingScanner < CodeRay::Scanners::Scanner
290
- def scan_tokens encoder, options
291
- raise_inspect 'message', [], :initial
292
- end
293
- end
294
-
295
- def test_scanner_raise_inspect
296
- assert_raise CodeRay::Scanners::Scanner::ScanError do
297
- RaisingScanner.new.tokenize ''
298
- end
299
- end
300
-
301
- def test_scan_a_frozen_string
302
- assert_nothing_raised do
303
- CodeRay.scan RUBY_VERSION, :ruby
304
- CodeRay.scan RUBY_VERSION, :plain
305
- end
306
- end
307
-
308
- def test_scan_a_non_string
309
- assert_nothing_raised do
310
- CodeRay.scan 42, :ruby
311
- CodeRay.scan nil, :ruby
312
- CodeRay.scan self, :ruby
313
- CodeRay.encode ENV.to_hash, :ruby, :page
314
- CodeRay.highlight CodeRay, :plain
315
- end
316
- end
317
-
318
- end
@@ -1,129 +0,0 @@
1
- require 'test/unit'
2
-
3
- $:.unshift File.expand_path('../../../lib', __FILE__)
4
- require 'coderay'
5
-
6
- class ExamplesTest < Test::Unit::TestCase
7
-
8
- def test_examples
9
- # output as HTML div (using inline CSS styles)
10
- div = CodeRay.scan('puts "Hello, world!"', :ruby).div
11
- assert_equal <<-DIV, div
12
- <div class="CodeRay">
13
- <div class="code"><pre>puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Hello, world!</span><span style="color:#710">&quot;</span></span></pre></div>
14
- </div>
15
- DIV
16
-
17
- # ...with line numbers
18
- div = CodeRay.scan(<<-CODE.chomp, :ruby).div(:line_numbers => :table)
19
- 5.times do
20
- puts 'Hello, world!'
21
- end
22
- CODE
23
- assert_equal <<-DIV, div
24
- <table class="CodeRay"><tr>
25
- <td class="line-numbers"><pre><a href="#n1" name="n1">1</a>
26
- <a href="#n2" name="n2">2</a>
27
- <a href="#n3" name="n3">3</a>
28
- </pre></td>
29
- <td class="code"><pre><span style="color:#00D">5</span>.times <span style="color:#080;font-weight:bold">do</span>
30
- puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Hello, world!</span><span style="color:#710">'</span></span>
31
- <span style="color:#080;font-weight:bold">end</span></pre></td>
32
- </tr></table>
33
- DIV
34
-
35
- # output as standalone HTML page (using CSS classes)
36
- page = CodeRay.scan('puts "Hello, world!"', :ruby).page
37
- assert_match <<-PAGE, page
38
- <body>
39
-
40
- <table class="CodeRay"><tr>
41
- <td class="line-numbers"><pre><a href="#n1" name="n1">1</a>
42
- </pre></td>
43
- <td class="code"><pre>puts <span class="string"><span class="delimiter">&quot;</span><span class="content">Hello, world!</span><span class="delimiter">&quot;</span></span></pre></td>
44
- </tr></table>
45
-
46
- </body>
47
- PAGE
48
-
49
- # keep scanned tokens for later use
50
- tokens = CodeRay.scan('{ "just": "an", "example": 42 }', :json)
51
- assert_kind_of CodeRay::TokensProxy, tokens
52
-
53
- assert_equal ["{", :operator, " ", :space, :begin_group, :key,
54
- "\"", :delimiter, "just", :content, "\"", :delimiter,
55
- :end_group, :key, ":", :operator, " ", :space,
56
- :begin_group, :string, "\"", :delimiter, "an", :content,
57
- "\"", :delimiter, :end_group, :string, ",", :operator,
58
- " ", :space, :begin_group, :key, "\"", :delimiter,
59
- "example", :content, "\"", :delimiter, :end_group, :key,
60
- ":", :operator, " ", :space, "42", :integer,
61
- " ", :space, "}", :operator], tokens.tokens
62
-
63
- # produce a token statistic
64
- assert_equal <<-STATISTIC, tokens.statistic
65
-
66
- Code Statistics
67
-
68
- Tokens 26
69
- Non-Whitespace 15
70
- Bytes Total 31
71
-
72
- Token Types (7):
73
- type count ratio size (average)
74
- -------------------------------------------------------------
75
- TOTAL 26 100.00 % 1.2
76
- delimiter 6 23.08 % 1.0
77
- operator 5 19.23 % 1.0
78
- space 5 19.23 % 1.0
79
- key 4 15.38 % 0.0
80
- :begin_group 3 11.54 % 0.0
81
- :end_group 3 11.54 % 0.0
82
- content 3 11.54 % 4.3
83
- string 2 7.69 % 0.0
84
- integer 1 3.85 % 2.0
85
-
86
- STATISTIC
87
-
88
- # count the tokens
89
- assert_equal 26, tokens.count
90
-
91
- # produce a HTML div, but with CSS classes
92
- div = tokens.div(:css => :class)
93
- assert_equal <<-DIV, div
94
- <div class="CodeRay">
95
- <div class="code"><pre>{ <span class="key"><span class="delimiter">&quot;</span><span class="content">just</span><span class="delimiter">&quot;</span></span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">an</span><span class="delimiter">&quot;</span></span>, <span class="key"><span class="delimiter">&quot;</span><span class="content">example</span><span class="delimiter">&quot;</span></span>: <span class="integer">42</span> }</pre></div>
96
- </div>
97
- DIV
98
-
99
- # highlight a file (HTML div); guess the file type base on the extension
100
- assert_equal :ruby, CodeRay::FileType[__FILE__]
101
-
102
- # get a new scanner for Python
103
- python_scanner = CodeRay.scanner :python
104
- assert_kind_of CodeRay::Scanners::Python, python_scanner
105
-
106
- # get a new encoder for terminal
107
- terminal_encoder = CodeRay.encoder :term
108
- assert_kind_of CodeRay::Encoders::Terminal, terminal_encoder
109
-
110
- # scanning into tokens
111
- tokens = python_scanner.tokenize 'import this; # The Zen of Python'
112
- assert_equal ["import", :keyword, " ", :space, "this", :include,
113
- ";", :operator, " ", :space, "# The Zen of Python", :comment], tokens
114
-
115
- # format the tokens
116
- term = terminal_encoder.encode_tokens(tokens)
117
- assert_equal "\e[32mimport\e[0m \e[31mthis\e[0m; \e[1;30m# The Zen of Python\e[0m", term
118
-
119
- # re-using scanner and encoder
120
- ruby_highlighter = CodeRay::Duo[:ruby, :div]
121
- div = ruby_highlighter.encode('puts "Hello, world!"')
122
- assert_equal <<-DIV, div
123
- <div class="CodeRay">
124
- <div class="code"><pre>puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Hello, world!</span><span style="color:#710">&quot;</span></span></pre></div>
125
- </div>
126
- DIV
127
- end
128
-
129
- end
@@ -1,78 +0,0 @@
1
- require 'test/unit'
2
-
3
- $:.unshift File.expand_path('../../../lib', __FILE__)
4
- require 'coderay'
5
-
6
- begin
7
- require 'rubygems' unless defined? Gem
8
- gem 'RedCloth', '>= 4.0.3' rescue nil
9
- require 'redcloth'
10
- rescue LoadError
11
- warn 'RedCloth not found - skipping for_redcloth tests.'
12
- undef RedCloth if defined? RedCloth
13
- end
14
-
15
- class BasicTest < Test::Unit::TestCase
16
-
17
- def test_for_redcloth
18
- require 'coderay/for_redcloth'
19
- assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">puts <span style=\"background-color:hsla(0,100%,50%,0.05)\"><span style=\"color:#710\">&quot;</span><span style=\"color:#D20\">Hello, World!</span><span style=\"color:#710\">&quot;</span></span></span></p>",
20
- RedCloth.new('@[ruby]puts "Hello, World!"@').to_html
21
- assert_equal <<-BLOCKCODE.chomp,
22
- <div lang="ruby" class="CodeRay">
23
- <div class="code"><pre>puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Hello, World!</span><span style="color:#710">&quot;</span></span></pre></div>
24
- </div>
25
- BLOCKCODE
26
- RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html
27
- end
28
-
29
- def test_for_redcloth_no_lang
30
- require 'coderay/for_redcloth'
31
- assert_equal "<p><code>puts \"Hello, World!\"</code></p>",
32
- RedCloth.new('@puts "Hello, World!"@').to_html
33
- assert_equal <<-BLOCKCODE.chomp,
34
- <pre><code>puts \"Hello, World!\"</code></pre>
35
- BLOCKCODE
36
- RedCloth.new('bc. puts "Hello, World!"').to_html
37
- end
38
-
39
- def test_for_redcloth_style
40
- require 'coderay/for_redcloth'
41
- assert_equal <<-BLOCKCODE.chomp,
42
- <pre style=\"color: red;\"><code style=\"color: red;\">puts \"Hello, World!\"</code></pre>
43
- BLOCKCODE
44
- RedCloth.new('bc{color: red}. puts "Hello, World!"').to_html
45
- end
46
-
47
- def test_for_redcloth_escapes
48
- require 'coderay/for_redcloth'
49
- assert_equal '<p><span lang="ruby" class="CodeRay">&gt;</span></p>',
50
- RedCloth.new('@[ruby]>@').to_html
51
- assert_equal <<-BLOCKCODE.chomp,
52
- <div lang="ruby" class="CodeRay">
53
- <div class="code"><pre>&amp;</pre></div>
54
- </div>
55
- BLOCKCODE
56
- RedCloth.new('bc[ruby]. &').to_html
57
- end
58
-
59
- def test_for_redcloth_escapes2
60
- require 'coderay/for_redcloth'
61
- assert_equal "<p><span lang=\"c\" class=\"CodeRay\"><span style=\"color:#579\">#include</span> <span style=\"color:#B44;font-weight:bold\">&lt;test.h&gt;</span></span></p>",
62
- RedCloth.new('@[c]#include <test.h>@').to_html
63
- end
64
-
65
- # See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets.
66
- def test_for_redcloth_false_positive
67
- require 'coderay/for_redcloth'
68
- assert_equal '<p><code>[project]_dff.skjd</code></p>',
69
- RedCloth.new('@[project]_dff.skjd@').to_html
70
- # false positive, but expected behavior / known issue
71
- assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">_dff.skjd</span></p>",
72
- RedCloth.new('@[ruby]_dff.skjd@').to_html
73
- assert_equal <<-BLOCKCODE.chomp, RedCloth.new('bc. [project]_dff.skjd').to_html
74
- <pre><code>[project]_dff.skjd</code></pre>
75
- BLOCKCODE
76
- end
77
-
78
- end if defined? RedCloth
@@ -1,15 +0,0 @@
1
- require 'test/unit'
2
-
3
- $VERBOSE = $CODERAY_DEBUG = true
4
- $:.unshift File.expand_path('../../../lib', __FILE__)
5
- require 'coderay'
6
-
7
- mydir = File.dirname(__FILE__)
8
- suite = Dir[File.join(mydir, '*.rb')].
9
- map { |tc| File.basename(tc).sub(/\.rb$/, '') } - %w'suite for_redcloth'
10
-
11
- puts "Running basic CodeRay #{CodeRay::VERSION} tests: #{suite.join(', ')}"
12
-
13
- for test_case in suite
14
- load File.join(mydir, test_case + '.rb')
15
- end