mirror of
https://github.com/redmine/redmine.git
synced 2025-11-12 16:26:03 +01:00
Coderay upgraded to 0.9.7 (#5344).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4739 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
122
vendor/gems/coderay-0.9.7/test/functional/basic.rb
vendored
Normal file
122
vendor/gems/coderay-0.9.7/test/functional/basic.rb
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
require 'test/unit'
|
||||
require 'coderay'
|
||||
|
||||
class BasicTest < Test::Unit::TestCase
|
||||
|
||||
def test_version
|
||||
assert_nothing_raised do
|
||||
assert_match(/\A\d\.\d\.\d\z/, CodeRay::VERSION)
|
||||
end
|
||||
end
|
||||
|
||||
RUBY_TEST_CODE = 'puts "Hello, World!"'
|
||||
|
||||
RUBY_TEST_TOKENS = [
|
||||
['puts', :ident],
|
||||
[' ', :space],
|
||||
[:open, :string],
|
||||
['"', :delimiter],
|
||||
['Hello, World!', :content],
|
||||
['"', :delimiter],
|
||||
[:close, :string]
|
||||
]
|
||||
def test_simple_scan
|
||||
assert_nothing_raised do
|
||||
assert_equal RUBY_TEST_TOKENS, CodeRay.scan(RUBY_TEST_CODE, :ruby).to_ary
|
||||
end
|
||||
end
|
||||
|
||||
RUBY_TEST_HTML = 'puts <span class="s"><span class="dl">"</span>' +
|
||||
'<span class="k">Hello, World!</span><span class="dl">"</span></span>'
|
||||
def test_simple_highlight
|
||||
assert_nothing_raised do
|
||||
assert_equal RUBY_TEST_HTML, CodeRay.scan(RUBY_TEST_CODE, :ruby).html
|
||||
end
|
||||
end
|
||||
|
||||
def test_duo
|
||||
assert_equal(RUBY_TEST_CODE,
|
||||
CodeRay::Duo[:plain, :plain].highlight(RUBY_TEST_CODE))
|
||||
assert_equal(RUBY_TEST_CODE,
|
||||
CodeRay::Duo[:plain => :plain].highlight(RUBY_TEST_CODE))
|
||||
end
|
||||
|
||||
def test_duo_stream
|
||||
assert_equal(RUBY_TEST_CODE,
|
||||
CodeRay::Duo[:plain, :plain].highlight(RUBY_TEST_CODE, :stream => true))
|
||||
end
|
||||
|
||||
def test_comment_filter
|
||||
assert_equal <<-EXPECTED, CodeRay.scan(<<-INPUT, :ruby).comment_filter.text
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
code
|
||||
|
||||
more code
|
||||
EXPECTED
|
||||
#!/usr/bin/env ruby
|
||||
=begin
|
||||
A multi-line comment.
|
||||
=end
|
||||
code
|
||||
# A single-line comment.
|
||||
more code # and another comment, in-line.
|
||||
INPUT
|
||||
end
|
||||
|
||||
def test_lines_of_code
|
||||
assert_equal 2, CodeRay.scan(<<-INPUT, :ruby).lines_of_code
|
||||
#!/usr/bin/env ruby
|
||||
=begin
|
||||
A multi-line comment.
|
||||
=end
|
||||
code
|
||||
# A single-line comment.
|
||||
more code # and another comment, in-line.
|
||||
INPUT
|
||||
rHTML = <<-RHTML
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||
<title><%= controller.controller_name.titleize %>: <%= controller.action_name %></title>
|
||||
<%= stylesheet_link_tag 'scaffold' %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p style="color: green"><%= flash[:notice] %></p>
|
||||
|
||||
<div id="main">
|
||||
<%= yield %>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
RHTML
|
||||
assert_equal 0, CodeRay.scan(rHTML, :html).lines_of_code
|
||||
assert_equal 0, CodeRay.scan(rHTML, :php).lines_of_code
|
||||
assert_equal 0, CodeRay.scan(rHTML, :yaml).lines_of_code
|
||||
assert_equal 4, CodeRay.scan(rHTML, :rhtml).lines_of_code
|
||||
end
|
||||
|
||||
def test_rubygems_not_loaded
|
||||
assert_equal nil, defined? Gem
|
||||
end if ENV['check_rubygems'] && RUBY_VERSION < '1.9'
|
||||
|
||||
def test_list_of_encoders
|
||||
assert_kind_of(Array, CodeRay::Encoders.list)
|
||||
assert CodeRay::Encoders.list.include?('count')
|
||||
end
|
||||
|
||||
def test_list_of_scanners
|
||||
assert_kind_of(Array, CodeRay::Scanners.list)
|
||||
assert CodeRay::Scanners.list.include?('plaintext')
|
||||
end
|
||||
|
||||
def test_scan_a_frozen_string
|
||||
CodeRay.scan RUBY_VERSION, :ruby
|
||||
end
|
||||
|
||||
end
|
||||
2022
vendor/gems/coderay-0.9.7/test/functional/basic.rbc
vendored
Normal file
2022
vendor/gems/coderay-0.9.7/test/functional/basic.rbc
vendored
Normal file
File diff suppressed because it is too large
Load Diff
77
vendor/gems/coderay-0.9.7/test/functional/for_redcloth.rb
vendored
Normal file
77
vendor/gems/coderay-0.9.7/test/functional/for_redcloth.rb
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
require 'test/unit'
|
||||
$:.unshift 'lib'
|
||||
require 'coderay'
|
||||
|
||||
begin
|
||||
require 'rubygems' unless defined? Gem
|
||||
gem 'RedCloth', '>= 4.0.3' rescue nil
|
||||
require 'redcloth'
|
||||
rescue LoadError
|
||||
warn 'RedCloth not found - skipping for_redcloth tests.'
|
||||
end
|
||||
|
||||
class BasicTest < Test::Unit::TestCase
|
||||
|
||||
def test_for_redcloth
|
||||
require 'coderay/for_redcloth'
|
||||
assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">puts <span style=\"background-color:#fff0f0;color:#D20\"><span style=\"color:#710\">"</span><span style=\"\">Hello, World!</span><span style=\"color:#710\">"</span></span></span></p>",
|
||||
RedCloth.new('@[ruby]puts "Hello, World!"@').to_html
|
||||
assert_equal <<-BLOCKCODE.chomp,
|
||||
<div lang="ruby" class="CodeRay">
|
||||
<div class="code"><pre>puts <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">"</span><span style="">Hello, World!</span><span style="color:#710">"</span></span></pre></div>
|
||||
</div>
|
||||
BLOCKCODE
|
||||
RedCloth.new('bc[ruby]. puts "Hello, World!"').to_html
|
||||
end
|
||||
|
||||
def test_for_redcloth_no_lang
|
||||
require 'coderay/for_redcloth'
|
||||
assert_equal "<p><code>puts \"Hello, World!\"</code></p>",
|
||||
RedCloth.new('@puts "Hello, World!"@').to_html
|
||||
assert_equal <<-BLOCKCODE.chomp,
|
||||
<pre><code>puts \"Hello, World!\"</code></pre>
|
||||
BLOCKCODE
|
||||
RedCloth.new('bc. puts "Hello, World!"').to_html
|
||||
end
|
||||
|
||||
def test_for_redcloth_style
|
||||
require 'coderay/for_redcloth'
|
||||
assert_equal <<-BLOCKCODE.chomp,
|
||||
<pre style=\"color: red;\"><code style=\"color: red;\">puts \"Hello, World!\"</code></pre>
|
||||
BLOCKCODE
|
||||
RedCloth.new('bc{color: red}. puts "Hello, World!"').to_html
|
||||
end
|
||||
|
||||
def test_for_redcloth_escapes
|
||||
require 'coderay/for_redcloth'
|
||||
assert_equal '<p><span lang="ruby" class="CodeRay">></span></p>',
|
||||
RedCloth.new('@[ruby]>@').to_html
|
||||
assert_equal <<-BLOCKCODE.chomp,
|
||||
<div lang="ruby" class="CodeRay">
|
||||
<div class="code"><pre>&</pre></div>
|
||||
</div>
|
||||
BLOCKCODE
|
||||
RedCloth.new('bc[ruby]. &').to_html
|
||||
end
|
||||
|
||||
def test_for_redcloth_escapes2
|
||||
require 'coderay/for_redcloth'
|
||||
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>",
|
||||
RedCloth.new('@[c]#include <test.h>@').to_html
|
||||
end
|
||||
|
||||
# See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets.
|
||||
def test_for_redcloth_false_positive
|
||||
require 'coderay/for_redcloth'
|
||||
assert_equal '<p><code>[project]_dff.skjd</code></p>',
|
||||
RedCloth.new('@[project]_dff.skjd@').to_html
|
||||
# false positive, but expected behavior / known issue
|
||||
assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">_dff.skjd</span></p>",
|
||||
RedCloth.new('@[ruby]_dff.skjd@').to_html
|
||||
assert_equal <<-BLOCKCODE.chomp,
|
||||
<pre><code>[project]_dff.skjd</code></pre>
|
||||
BLOCKCODE
|
||||
RedCloth.new('bc. [project]_dff.skjd').to_html
|
||||
end
|
||||
|
||||
end if defined? RedCloth
|
||||
1708
vendor/gems/coderay-0.9.7/test/functional/for_redcloth.rbc
vendored
Normal file
1708
vendor/gems/coderay-0.9.7/test/functional/for_redcloth.rbc
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
vendor/gems/coderay-0.9.7/test/functional/load_plugin_scanner.rb
vendored
Normal file
11
vendor/gems/coderay-0.9.7/test/functional/load_plugin_scanner.rb
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
require 'test/unit'
|
||||
require 'coderay'
|
||||
|
||||
class PluginScannerTest < Test::Unit::TestCase
|
||||
|
||||
def test_load
|
||||
require File.join(File.dirname(__FILE__), 'vhdl')
|
||||
assert_equal 'VHDL', CodeRay.scanner(:vhdl).class.name
|
||||
end
|
||||
|
||||
end
|
||||
317
vendor/gems/coderay-0.9.7/test/functional/load_plugin_scanner.rbc
vendored
Normal file
317
vendor/gems/coderay-0.9.7/test/functional/load_plugin_scanner.rbc
vendored
Normal file
@@ -0,0 +1,317 @@
|
||||
!RBIX
|
||||
0
|
||||
x
|
||||
M
|
||||
1
|
||||
n
|
||||
n
|
||||
x
|
||||
10
|
||||
__script__
|
||||
i
|
||||
53
|
||||
5
|
||||
7
|
||||
0
|
||||
64
|
||||
47
|
||||
49
|
||||
1
|
||||
1
|
||||
15
|
||||
5
|
||||
7
|
||||
2
|
||||
64
|
||||
47
|
||||
49
|
||||
1
|
||||
1
|
||||
15
|
||||
99
|
||||
7
|
||||
3
|
||||
45
|
||||
4
|
||||
5
|
||||
43
|
||||
6
|
||||
43
|
||||
7
|
||||
65
|
||||
49
|
||||
8
|
||||
3
|
||||
13
|
||||
99
|
||||
12
|
||||
7
|
||||
9
|
||||
12
|
||||
7
|
||||
10
|
||||
12
|
||||
65
|
||||
12
|
||||
49
|
||||
11
|
||||
4
|
||||
15
|
||||
49
|
||||
9
|
||||
0
|
||||
15
|
||||
2
|
||||
11
|
||||
I
|
||||
6
|
||||
I
|
||||
0
|
||||
I
|
||||
0
|
||||
I
|
||||
0
|
||||
n
|
||||
p
|
||||
12
|
||||
s
|
||||
9
|
||||
test/unit
|
||||
x
|
||||
7
|
||||
require
|
||||
s
|
||||
7
|
||||
coderay
|
||||
x
|
||||
17
|
||||
PluginScannerTest
|
||||
x
|
||||
4
|
||||
Test
|
||||
n
|
||||
x
|
||||
4
|
||||
Unit
|
||||
x
|
||||
8
|
||||
TestCase
|
||||
x
|
||||
10
|
||||
open_class
|
||||
x
|
||||
14
|
||||
__class_init__
|
||||
M
|
||||
1
|
||||
n
|
||||
n
|
||||
x
|
||||
17
|
||||
PluginScannerTest
|
||||
i
|
||||
16
|
||||
5
|
||||
66
|
||||
99
|
||||
7
|
||||
0
|
||||
7
|
||||
1
|
||||
65
|
||||
67
|
||||
49
|
||||
2
|
||||
0
|
||||
49
|
||||
3
|
||||
4
|
||||
11
|
||||
I
|
||||
5
|
||||
I
|
||||
0
|
||||
I
|
||||
0
|
||||
I
|
||||
0
|
||||
n
|
||||
p
|
||||
4
|
||||
x
|
||||
9
|
||||
test_load
|
||||
M
|
||||
1
|
||||
n
|
||||
n
|
||||
x
|
||||
9
|
||||
test_load
|
||||
i
|
||||
48
|
||||
5
|
||||
45
|
||||
0
|
||||
1
|
||||
45
|
||||
0
|
||||
2
|
||||
65
|
||||
49
|
||||
3
|
||||
0
|
||||
49
|
||||
4
|
||||
1
|
||||
7
|
||||
5
|
||||
64
|
||||
49
|
||||
6
|
||||
2
|
||||
47
|
||||
49
|
||||
7
|
||||
1
|
||||
15
|
||||
5
|
||||
7
|
||||
8
|
||||
64
|
||||
45
|
||||
9
|
||||
10
|
||||
7
|
||||
11
|
||||
49
|
||||
12
|
||||
1
|
||||
49
|
||||
13
|
||||
0
|
||||
49
|
||||
14
|
||||
0
|
||||
47
|
||||
49
|
||||
15
|
||||
2
|
||||
11
|
||||
I
|
||||
4
|
||||
I
|
||||
0
|
||||
I
|
||||
0
|
||||
I
|
||||
0
|
||||
n
|
||||
p
|
||||
16
|
||||
x
|
||||
4
|
||||
File
|
||||
n
|
||||
n
|
||||
x
|
||||
11
|
||||
active_path
|
||||
x
|
||||
7
|
||||
dirname
|
||||
s
|
||||
4
|
||||
vhdl
|
||||
x
|
||||
4
|
||||
join
|
||||
x
|
||||
7
|
||||
require
|
||||
s
|
||||
4
|
||||
VHDL
|
||||
x
|
||||
7
|
||||
CodeRay
|
||||
n
|
||||
x
|
||||
4
|
||||
vhdl
|
||||
x
|
||||
7
|
||||
scanner
|
||||
x
|
||||
5
|
||||
class
|
||||
x
|
||||
4
|
||||
name
|
||||
x
|
||||
12
|
||||
assert_equal
|
||||
p
|
||||
7
|
||||
I
|
||||
0
|
||||
I
|
||||
6
|
||||
I
|
||||
0
|
||||
I
|
||||
7
|
||||
I
|
||||
19
|
||||
I
|
||||
8
|
||||
I
|
||||
30
|
||||
x
|
||||
69
|
||||
/Users/murphy/ruby/coderay-0.9/test/functional/load_plugin_scanner.rb
|
||||
p
|
||||
0
|
||||
x
|
||||
17
|
||||
method_visibility
|
||||
x
|
||||
15
|
||||
add_defn_method
|
||||
p
|
||||
3
|
||||
I
|
||||
2
|
||||
I
|
||||
6
|
||||
I
|
||||
10
|
||||
x
|
||||
69
|
||||
/Users/murphy/ruby/coderay-0.9/test/functional/load_plugin_scanner.rb
|
||||
p
|
||||
0
|
||||
x
|
||||
13
|
||||
attach_method
|
||||
p
|
||||
7
|
||||
I
|
||||
0
|
||||
I
|
||||
1
|
||||
I
|
||||
9
|
||||
I
|
||||
2
|
||||
I
|
||||
12
|
||||
I
|
||||
4
|
||||
I
|
||||
35
|
||||
x
|
||||
69
|
||||
/Users/murphy/ruby/coderay-0.9/test/functional/load_plugin_scanner.rb
|
||||
p
|
||||
0
|
||||
12
vendor/gems/coderay-0.9.7/test/functional/suite.rb
vendored
Normal file
12
vendor/gems/coderay-0.9.7/test/functional/suite.rb
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'test/unit'
|
||||
|
||||
MYDIR = File.dirname(__FILE__)
|
||||
|
||||
$:.unshift '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
|
||||
322
vendor/gems/coderay-0.9.7/test/functional/suite.rbc
vendored
Normal file
322
vendor/gems/coderay-0.9.7/test/functional/suite.rbc
vendored
Normal file
@@ -0,0 +1,322 @@
|
||||
!RBIX
|
||||
0
|
||||
x
|
||||
M
|
||||
1
|
||||
n
|
||||
n
|
||||
x
|
||||
10
|
||||
__script__
|
||||
i
|
||||
95
|
||||
5
|
||||
7
|
||||
0
|
||||
64
|
||||
47
|
||||
49
|
||||
1
|
||||
1
|
||||
15
|
||||
65
|
||||
7
|
||||
2
|
||||
45
|
||||
3
|
||||
4
|
||||
65
|
||||
49
|
||||
5
|
||||
0
|
||||
49
|
||||
6
|
||||
1
|
||||
49
|
||||
7
|
||||
2
|
||||
15
|
||||
99
|
||||
43
|
||||
8
|
||||
7
|
||||
9
|
||||
49
|
||||
10
|
||||
1
|
||||
7
|
||||
11
|
||||
64
|
||||
49
|
||||
12
|
||||
1
|
||||
15
|
||||
5
|
||||
7
|
||||
13
|
||||
64
|
||||
47
|
||||
49
|
||||
1
|
||||
1
|
||||
15
|
||||
5
|
||||
7
|
||||
14
|
||||
45
|
||||
15
|
||||
16
|
||||
43
|
||||
17
|
||||
47
|
||||
49
|
||||
18
|
||||
0
|
||||
7
|
||||
19
|
||||
63
|
||||
3
|
||||
47
|
||||
49
|
||||
20
|
||||
1
|
||||
15
|
||||
7
|
||||
21
|
||||
64
|
||||
7
|
||||
22
|
||||
64
|
||||
7
|
||||
23
|
||||
64
|
||||
35
|
||||
3
|
||||
19
|
||||
0
|
||||
15
|
||||
20
|
||||
0
|
||||
56
|
||||
24
|
||||
50
|
||||
25
|
||||
0
|
||||
15
|
||||
2
|
||||
11
|
||||
I
|
||||
6
|
||||
I
|
||||
2
|
||||
I
|
||||
0
|
||||
I
|
||||
0
|
||||
n
|
||||
p
|
||||
26
|
||||
s
|
||||
9
|
||||
test/unit
|
||||
x
|
||||
7
|
||||
require
|
||||
x
|
||||
5
|
||||
MYDIR
|
||||
x
|
||||
4
|
||||
File
|
||||
n
|
||||
x
|
||||
11
|
||||
active_path
|
||||
x
|
||||
7
|
||||
dirname
|
||||
x
|
||||
9
|
||||
const_set
|
||||
x
|
||||
7
|
||||
Globals
|
||||
x
|
||||
2
|
||||
$:
|
||||
x
|
||||
2
|
||||
[]
|
||||
s
|
||||
3
|
||||
lib
|
||||
x
|
||||
2
|
||||
<<
|
||||
s
|
||||
7
|
||||
coderay
|
||||
s
|
||||
22
|
||||
Running basic CodeRay
|
||||
x
|
||||
7
|
||||
CodeRay
|
||||
n
|
||||
x
|
||||
7
|
||||
VERSION
|
||||
x
|
||||
4
|
||||
to_s
|
||||
s
|
||||
9
|
||||
tests...
|
||||
x
|
||||
4
|
||||
puts
|
||||
s
|
||||
5
|
||||
basic
|
||||
s
|
||||
19
|
||||
load_plugin_scanner
|
||||
s
|
||||
9
|
||||
word_list
|
||||
M
|
||||
1
|
||||
p
|
||||
2
|
||||
x
|
||||
9
|
||||
for_block
|
||||
t
|
||||
n
|
||||
x
|
||||
9
|
||||
__block__
|
||||
i
|
||||
28
|
||||
57
|
||||
22
|
||||
1
|
||||
1
|
||||
15
|
||||
5
|
||||
45
|
||||
0
|
||||
1
|
||||
45
|
||||
2
|
||||
3
|
||||
21
|
||||
1
|
||||
1
|
||||
7
|
||||
4
|
||||
64
|
||||
81
|
||||
5
|
||||
49
|
||||
6
|
||||
2
|
||||
47
|
||||
49
|
||||
7
|
||||
1
|
||||
11
|
||||
I
|
||||
6
|
||||
I
|
||||
0
|
||||
I
|
||||
1
|
||||
I
|
||||
1
|
||||
n
|
||||
p
|
||||
8
|
||||
x
|
||||
4
|
||||
File
|
||||
n
|
||||
x
|
||||
5
|
||||
MYDIR
|
||||
n
|
||||
s
|
||||
3
|
||||
.rb
|
||||
x
|
||||
1
|
||||
+
|
||||
x
|
||||
4
|
||||
join
|
||||
x
|
||||
4
|
||||
load
|
||||
p
|
||||
5
|
||||
I
|
||||
0
|
||||
I
|
||||
a
|
||||
I
|
||||
5
|
||||
I
|
||||
b
|
||||
I
|
||||
1c
|
||||
x
|
||||
55
|
||||
/Users/murphy/ruby/coderay-0.9/test/functional/suite.rb
|
||||
p
|
||||
0
|
||||
x
|
||||
4
|
||||
each
|
||||
p
|
||||
15
|
||||
I
|
||||
0
|
||||
I
|
||||
1
|
||||
I
|
||||
9
|
||||
I
|
||||
3
|
||||
I
|
||||
1a
|
||||
I
|
||||
5
|
||||
I
|
||||
29
|
||||
I
|
||||
6
|
||||
I
|
||||
32
|
||||
I
|
||||
7
|
||||
I
|
||||
47
|
||||
I
|
||||
9
|
||||
I
|
||||
55
|
||||
I
|
||||
a
|
||||
I
|
||||
5f
|
||||
x
|
||||
55
|
||||
/Users/murphy/ruby/coderay-0.9/test/functional/suite.rb
|
||||
p
|
||||
2
|
||||
x
|
||||
5
|
||||
suite
|
||||
x
|
||||
9
|
||||
test_case
|
||||
126
vendor/gems/coderay-0.9.7/test/functional/vhdl.rb
vendored
Normal file
126
vendor/gems/coderay-0.9.7/test/functional/vhdl.rb
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
class VHDL < CodeRay::Scanners::Scanner
|
||||
|
||||
register_for :vhdl
|
||||
|
||||
RESERVED_WORDS = [
|
||||
'access','after','alias','all','assert','architecture','begin',
|
||||
'block','body','buffer','bus','case','component','configuration','constant',
|
||||
'disconnect','downto','else','elsif','end','entity','exit','file','for',
|
||||
'function','generate','generic','group','guarded','if','impure','in',
|
||||
'inertial','inout','is','label','library','linkage','literal','loop',
|
||||
'map','new','next','null','of','on','open','others','out','package',
|
||||
'port','postponed','procedure','process','pure','range','record','register',
|
||||
'reject','report','return','select','severity','signal','shared','subtype',
|
||||
'then','to','transport','type','unaffected','units','until','use','variable',
|
||||
'wait','when','while','with','note','warning','error','failure','and',
|
||||
'or','xor','not','nor',
|
||||
'array'
|
||||
]
|
||||
|
||||
PREDEFINED_TYPES = [
|
||||
'bit','bit_vector','character','boolean','integer','real','time','string',
|
||||
'severity_level','positive','natural','signed','unsigned','line','text',
|
||||
'std_logic','std_logic_vector','std_ulogic','std_ulogic_vector','qsim_state',
|
||||
'qsim_state_vector','qsim_12state','qsim_12state_vector','qsim_strength',
|
||||
'mux_bit','mux_vector','reg_bit','reg_vector','wor_bit','wor_vector'
|
||||
]
|
||||
|
||||
PREDEFINED_CONSTANTS = [
|
||||
|
||||
]
|
||||
|
||||
IDENT_KIND = CodeRay::CaseIgnoringWordList.new(:ident).
|
||||
add(RESERVED_WORDS, :reserved).
|
||||
add(PREDEFINED_TYPES, :pre_type).
|
||||
add(PREDEFINED_CONSTANTS, :pre_constant)
|
||||
|
||||
ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x
|
||||
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
|
||||
|
||||
def scan_tokens tokens, options
|
||||
|
||||
state = :initial
|
||||
|
||||
until eos?
|
||||
|
||||
kind = nil
|
||||
match = nil
|
||||
|
||||
case state
|
||||
|
||||
when :initial
|
||||
|
||||
if scan(/ \s+ | \\\n /x)
|
||||
kind = :space
|
||||
|
||||
elsif scan(/-- .*/x)
|
||||
kind = :comment
|
||||
|
||||
elsif scan(/ [-+*\/=<>?:;,!&^|()\[\]{}~%]+ | \.(?!\d) /x)
|
||||
kind = :operator
|
||||
|
||||
elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
|
||||
kind = IDENT_KIND[match.downcase]
|
||||
|
||||
elsif match = scan(/[a-z]?"/i)
|
||||
tokens << [:open, :string]
|
||||
state = :string
|
||||
kind = :delimiter
|
||||
|
||||
elsif scan(/ L?' (?: [^\'\n\\] | \\ #{ESCAPE} )? '? /ox)
|
||||
kind = :char
|
||||
|
||||
elsif scan(/(?:\d+)(?![.eEfF])/)
|
||||
kind = :integer
|
||||
|
||||
elsif scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
|
||||
kind = :float
|
||||
|
||||
else
|
||||
getch
|
||||
kind = :error
|
||||
|
||||
end
|
||||
|
||||
when :string
|
||||
if scan(/[^\\\n"]+/)
|
||||
kind = :content
|
||||
elsif scan(/"/)
|
||||
tokens << ['"', :delimiter]
|
||||
tokens << [:close, :string]
|
||||
state = :initial
|
||||
next
|
||||
elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
|
||||
kind = :char
|
||||
elsif scan(/ \\ | $ /x)
|
||||
tokens << [:close, :string]
|
||||
kind = :error
|
||||
state = :initial
|
||||
else
|
||||
raise_inspect "else case \" reached; %p not handled." % peek(1), tokens
|
||||
end
|
||||
|
||||
else
|
||||
raise_inspect 'Unknown state', tokens
|
||||
|
||||
end
|
||||
|
||||
match ||= matched
|
||||
if $DEBUG and not kind
|
||||
raise_inspect 'Error token %p in line %d' %
|
||||
[[match, kind], line], tokens
|
||||
end
|
||||
raise_inspect 'Empty token', tokens unless match
|
||||
|
||||
tokens << [match, kind]
|
||||
|
||||
end
|
||||
|
||||
if state == :string
|
||||
tokens << [:close, :string]
|
||||
end
|
||||
|
||||
tokens
|
||||
end
|
||||
|
||||
end
|
||||
2334
vendor/gems/coderay-0.9.7/test/functional/vhdl.rbc
vendored
Normal file
2334
vendor/gems/coderay-0.9.7/test/functional/vhdl.rbc
vendored
Normal file
File diff suppressed because it is too large
Load Diff
79
vendor/gems/coderay-0.9.7/test/functional/word_list.rb
vendored
Normal file
79
vendor/gems/coderay-0.9.7/test/functional/word_list.rb
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
require 'test/unit'
|
||||
require 'coderay'
|
||||
|
||||
class WordListTest < Test::Unit::TestCase
|
||||
|
||||
include CodeRay
|
||||
|
||||
# define word arrays
|
||||
RESERVED_WORDS = %w[
|
||||
asm break case continue default do else
|
||||
...
|
||||
]
|
||||
|
||||
PREDEFINED_TYPES = %w[
|
||||
int long short char void
|
||||
...
|
||||
]
|
||||
|
||||
PREDEFINED_CONSTANTS = %w[
|
||||
EOF NULL ...
|
||||
]
|
||||
|
||||
# make a WordList
|
||||
IDENT_KIND = WordList.new(:ident).
|
||||
add(RESERVED_WORDS, :reserved).
|
||||
add(PREDEFINED_TYPES, :pre_type).
|
||||
add(PREDEFINED_CONSTANTS, :pre_constant)
|
||||
|
||||
def test_word_list_example
|
||||
assert_equal :pre_type, IDENT_KIND['void']
|
||||
# assert_equal :pre_constant, IDENT_KIND['...'] # not specified
|
||||
end
|
||||
|
||||
def test_word_list
|
||||
list = WordList.new(:ident).add(['foobar'], :reserved)
|
||||
assert_equal :reserved, list['foobar']
|
||||
assert_equal :ident, list['FooBar']
|
||||
end
|
||||
|
||||
def test_word_list_cached
|
||||
list = WordList.new(:ident, true).add(['foobar'], :reserved)
|
||||
assert_equal :reserved, list['foobar']
|
||||
assert_equal :ident, list['FooBar']
|
||||
end
|
||||
|
||||
def test_case_ignoring_word_list
|
||||
list = CaseIgnoringWordList.new(:ident).add(['foobar'], :reserved)
|
||||
assert_equal :ident, list['foo']
|
||||
assert_equal :reserved, list['foobar']
|
||||
assert_equal :reserved, list['FooBar']
|
||||
|
||||
list = CaseIgnoringWordList.new(:ident).add(['FooBar'], :reserved)
|
||||
assert_equal :ident, list['foo']
|
||||
assert_equal :reserved, list['foobar']
|
||||
assert_equal :reserved, list['FooBar']
|
||||
end
|
||||
|
||||
def test_case_ignoring_word_list_cached
|
||||
list = CaseIgnoringWordList.new(:ident, true).add(['foobar'], :reserved)
|
||||
assert_equal :ident, list['foo']
|
||||
assert_equal :reserved, list['foobar']
|
||||
assert_equal :reserved, list['FooBar']
|
||||
|
||||
list = CaseIgnoringWordList.new(:ident, true).add(['FooBar'], :reserved)
|
||||
assert_equal :ident, list['foo']
|
||||
assert_equal :reserved, list['foobar']
|
||||
assert_equal :reserved, list['FooBar']
|
||||
end
|
||||
|
||||
def test_dup
|
||||
list = WordList.new(:ident).add(['foobar'], :reserved)
|
||||
assert_equal :reserved, list['foobar']
|
||||
list2 = list.dup
|
||||
list2.add(%w[foobar], :keyword)
|
||||
assert_equal :keyword, list2['foobar']
|
||||
assert_equal :reserved, list['foobar']
|
||||
end
|
||||
|
||||
end
|
||||
1763
vendor/gems/coderay-0.9.7/test/functional/word_list.rbc
vendored
Normal file
1763
vendor/gems/coderay-0.9.7/test/functional/word_list.rbc
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user