coderay 1.1.1 → 1.1.2.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/MIT-LICENSE +22 -0
- data/lib/coderay/encoders/encoder.rb +1 -1
- data/lib/coderay/encoders/html.rb +2 -2
- data/lib/coderay/scanners/cpp.rb +19 -17
- data/lib/coderay/scanners/haml.rb +1 -1
- data/lib/coderay/scanners/java.rb +1 -1
- data/lib/coderay/token_kinds.rb +0 -0
- data/lib/coderay/version.rb +1 -1
- metadata +33 -36
- data/Rakefile +0 -37
- data/test/functional/basic.rb +0 -318
- data/test/functional/examples.rb +0 -129
- data/test/functional/for_redcloth.rb +0 -78
- data/test/functional/suite.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA512:
|
3
|
+
metadata.gz: 03cd3856123c3c19e85bdc3e2ce1ada513f67567d89ee2c5446c6b9430839b595d19aa25472660685d61e22b94e4a9236093e299b7056bf22a096d7d4b61cf79
|
4
|
+
data.tar.gz: 950a45db317ea5ccc14a807f392492b6db3df99a341b82996cf146ef815a0126a4790fc6e11a399692e3ae3d4c904cb6ae857f866dc73fabfa9960f708f96311
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: 92c24f8df92879a57c768afaf089de0ddced36e6
|
7
|
+
data.tar.gz: 0244efec449860ba0649d90610ac5aa1fb71f00f
|
data/MIT-LICENSE
ADDED
@@ -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.
|
@@ -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
|
data/lib/coderay/scanners/cpp.rb
CHANGED
@@ -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', '
|
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', '
|
27
|
-
'
|
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
|
-
'
|
38
|
-
'
|
39
|
-
'
|
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).
|
@@ -48,9 +50,9 @@ module Scanners
|
|
48
50
|
|
49
51
|
ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
|
50
52
|
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
|
51
|
-
|
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
|
|
data/lib/coderay/token_kinds.rb
CHANGED
File without changes
|
data/lib/coderay/version.rb
CHANGED
metadata
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: coderay
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.2.rc1
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Kornelius Kalnbach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
11
|
+
|
12
|
+
date: 2017-09-03 00:00:00 Z
|
12
13
|
dependencies: []
|
13
|
-
|
14
|
-
|
15
|
-
email:
|
14
|
+
|
15
|
+
description: Fast and easy syntax highlighting for selected languages, written in Ruby. Comes with RedCloth integration and LOC counter.
|
16
|
+
email:
|
16
17
|
- murphy@rubychan.de
|
17
|
-
executables:
|
18
|
+
executables:
|
18
19
|
- coderay
|
19
20
|
extensions: []
|
20
|
-
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
21
23
|
- README_INDEX.rdoc
|
22
|
-
files:
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
23
26
|
- README_INDEX.rdoc
|
24
|
-
- Rakefile
|
25
27
|
- bin/coderay
|
26
28
|
- lib/coderay.rb
|
27
29
|
- lib/coderay/duo.rb
|
@@ -95,39 +97,34 @@ files:
|
|
95
97
|
- lib/coderay/tokens.rb
|
96
98
|
- lib/coderay/tokens_proxy.rb
|
97
99
|
- 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
100
|
homepage: http://coderay.rubychan.de
|
103
|
-
licenses:
|
101
|
+
licenses:
|
104
102
|
- MIT
|
105
103
|
metadata: {}
|
104
|
+
|
106
105
|
post_install_message:
|
107
|
-
rdoc_options:
|
108
|
-
-
|
109
|
-
-
|
110
|
-
-
|
111
|
-
require_paths:
|
106
|
+
rdoc_options:
|
107
|
+
- -SNw2
|
108
|
+
- -mREADME_INDEX.rdoc
|
109
|
+
- -t CodeRay Documentation
|
110
|
+
require_paths:
|
112
111
|
- lib
|
113
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
115
114
|
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
115
|
+
- !ruby/object:Gem::Version
|
117
116
|
version: 1.8.6
|
118
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
-
requirements:
|
120
|
-
- - "
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
version:
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 1.3.1
|
123
122
|
requirements: []
|
123
|
+
|
124
124
|
rubyforge_project: coderay
|
125
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.6.13
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Fast syntax highlighting for selected languages.
|
129
|
-
test_files:
|
130
|
-
|
131
|
-
- test/functional/examples.rb
|
132
|
-
- test/functional/for_redcloth.rb
|
133
|
-
- test/functional/suite.rb
|
129
|
+
test_files: []
|
130
|
+
|
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
|
data/test/functional/basic.rb
DELETED
@@ -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">"</span>' +
|
50
|
-
'<span class="content">Hello, World!</span><span class="delimiter">"</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
|
data/test/functional/examples.rb
DELETED
@@ -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">"</span><span style="color:#D20">Hello, world!</span><span style="color:#710">"</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">"</span><span class="content">Hello, world!</span><span class="delimiter">"</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">"</span><span class="content">just</span><span class="delimiter">"</span></span>: <span class="string"><span class="delimiter">"</span><span class="content">an</span><span class="delimiter">"</span></span>, <span class="key"><span class="delimiter">"</span><span class="content">example</span><span class="delimiter">"</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">"</span><span style="color:#D20">Hello, world!</span><span style="color:#710">"</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\">"</span><span style=\"color:#D20\">Hello, World!</span><span style=\"color:#710\">"</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">"</span><span style="color:#D20">Hello, World!</span><span style="color:#710">"</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">></span></p>',
|
50
|
-
RedCloth.new('@[ruby]>@').to_html
|
51
|
-
assert_equal <<-BLOCKCODE.chomp,
|
52
|
-
<div lang="ruby" class="CodeRay">
|
53
|
-
<div class="code"><pre>&</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\"><test.h></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
|
data/test/functional/suite.rb
DELETED
@@ -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
|