coderay 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ require 'test/unit'
2
+ require 'coderay'
3
+
4
+ class WordListTest < Test::Unit::TestCase
5
+
6
+ include CodeRay
7
+
8
+ # define word arrays
9
+ RESERVED_WORDS = %w[
10
+ asm break case continue default do else
11
+ ...
12
+ ]
13
+
14
+ PREDEFINED_TYPES = %w[
15
+ int long short char void
16
+ ...
17
+ ]
18
+
19
+ PREDEFINED_CONSTANTS = %w[
20
+ EOF NULL ...
21
+ ]
22
+
23
+ # make a WordList
24
+ IDENT_KIND = WordList.new(:ident).
25
+ add(RESERVED_WORDS, :reserved).
26
+ add(PREDEFINED_TYPES, :pre_type).
27
+ add(PREDEFINED_CONSTANTS, :pre_constant)
28
+
29
+ def test_word_list_example
30
+ assert_equal :pre_type, IDENT_KIND['void']
31
+ # assert_equal :pre_constant, IDENT_KIND['...'] # not specified
32
+ end
33
+
34
+ def test_word_list
35
+ list = WordList.new(:ident).add(['foobar'], :reserved)
36
+ assert_equal :reserved, list['foobar']
37
+ assert_equal :ident, list['FooBar']
38
+ end
39
+
40
+ def test_word_list_cached
41
+ list = WordList.new(:ident, true).add(['foobar'], :reserved)
42
+ assert_equal :reserved, list['foobar']
43
+ assert_equal :ident, list['FooBar']
44
+ end
45
+
46
+ def test_case_ignoring_word_list
47
+ list = CaseIgnoringWordList.new(:ident).add(['foobar'], :reserved)
48
+ assert_equal :ident, list['foo']
49
+ assert_equal :reserved, list['foobar']
50
+ assert_equal :reserved, list['FooBar']
51
+
52
+ list = CaseIgnoringWordList.new(:ident).add(['FooBar'], :reserved)
53
+ assert_equal :ident, list['foo']
54
+ assert_equal :reserved, list['foobar']
55
+ assert_equal :reserved, list['FooBar']
56
+ end
57
+
58
+ def test_case_ignoring_word_list_cached
59
+ list = CaseIgnoringWordList.new(:ident, true).add(['foobar'], :reserved)
60
+ assert_equal :ident, list['foo']
61
+ assert_equal :reserved, list['foobar']
62
+ assert_equal :reserved, list['FooBar']
63
+
64
+ list = CaseIgnoringWordList.new(:ident, true).add(['FooBar'], :reserved)
65
+ assert_equal :ident, list['foo']
66
+ assert_equal :reserved, list['foobar']
67
+ assert_equal :reserved, list['FooBar']
68
+ end
69
+
70
+ def test_dup
71
+ list = WordList.new(:ident).add(['foobar'], :reserved)
72
+ assert_equal :reserved, list['foobar']
73
+ list2 = list.dup
74
+ list2.add(%w[foobar], :keyword)
75
+ assert_equal :keyword, list2['foobar']
76
+ assert_equal :reserved, list['foobar']
77
+ end
78
+
79
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coderay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 2
9
+ version: 0.9.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - murphy
@@ -9,11 +14,14 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-01 00:00:00 +01:00
17
+ date: 2010-03-14 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
16
- description: " CodeRay is a Ruby library for syntax highlighting.\n I try to make CodeRay easy to use and intuitive, but at the same time\n fully featured, complete, fast and efficient.\n\n Usage is simple:\n CodeRay.scan(code, :ruby).div\n"
21
+ description: |
22
+ Fast and easy syntax highlighting for selected languages, written in Ruby.
23
+ Comes with RedCloth integration and LOC counter.
24
+
17
25
  email: murphy@rubychan.de
18
26
  executables:
19
27
  - coderay
@@ -21,8 +29,8 @@ executables:
21
29
  extensions: []
22
30
 
23
31
  extra_rdoc_files:
24
- - ./lib/README
25
- - ./FOLDERS
32
+ - lib/README
33
+ - FOLDERS
26
34
  files:
27
35
  - ./lib/coderay/duo.rb
28
36
  - ./lib/coderay/encoder.rb
@@ -84,10 +92,17 @@ files:
84
92
  - ./lib/coderay/token_classes.rb
85
93
  - ./lib/coderay/tokens.rb
86
94
  - ./lib/coderay.rb
87
- - ./lib/term/ansicolor.rb
95
+ - ./Rakefile
96
+ - ./test/functional/basic.rb
97
+ - ./test/functional/for_redcloth.rb
98
+ - ./test/functional/load_plugin_scanner.rb
99
+ - ./test/functional/suite.rb
100
+ - ./test/functional/vhdl.rb
101
+ - ./test/functional/word_list.rb
88
102
  - ./lib/README
89
103
  - ./LICENSE
90
- - ./FOLDERS
104
+ - lib/README
105
+ - FOLDERS
91
106
  has_rdoc: true
92
107
  homepage: http://coderay.rubychan.de
93
108
  licenses: []
@@ -96,7 +111,6 @@ post_install_message:
96
111
  rdoc_options:
97
112
  - -SNw2
98
113
  - -mlib/README
99
- - -a
100
114
  - -t CodeRay Documentation
101
115
  require_paths:
102
116
  - lib
@@ -104,20 +118,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
118
  requirements:
105
119
  - - ">="
106
120
  - !ruby/object:Gem::Version
121
+ segments:
122
+ - 1
123
+ - 8
124
+ - 2
107
125
  version: 1.8.2
108
- version:
109
126
  required_rubygems_version: !ruby/object:Gem::Requirement
110
127
  requirements:
111
128
  - - ">="
112
129
  - !ruby/object:Gem::Version
130
+ segments:
131
+ - 0
113
132
  version: "0"
114
- version:
115
133
  requirements: []
116
134
 
117
135
  rubyforge_project: coderay
118
- rubygems_version: 1.3.5
136
+ rubygems_version: 1.3.6
119
137
  signing_key:
120
138
  specification_version: 3
121
- summary: CodeRay is a fast syntax highlighter engine for many languages.
122
- test_files: []
123
-
139
+ summary: Fast syntax highlighting for selected languages.
140
+ test_files:
141
+ - ./test/functional/suite.rb
@@ -1,220 +0,0 @@
1
- # = Term::ANSIColor - ANSI escape sequences in Ruby
2
- #
3
- # == Description
4
- #
5
- # This library can be used to color/uncolor strings using ANSI escape sequences.
6
- #
7
- # == Author
8
- #
9
- # Florian Frank mailto:flori@ping.de
10
- #
11
- # == License
12
- #
13
- # This is free software; you can redistribute it and/or modify it under the
14
- # terms of the GNU General Public License Version 2 as published by the Free
15
- # Software Foundation: www.gnu.org/copyleft/gpl.html
16
- #
17
- # == Download
18
- #
19
- # The latest version of this library can be downloaded at
20
- #
21
- # * http://rubyforge.org/frs?group_id=391
22
- #
23
- # The homepage of this library is located at
24
- #
25
- # * http://term-ansicolor.rubyforge.org
26
- #
27
- # == Examples
28
- #
29
- # The file examples/example.rb in the source/gem-distribution shows how
30
- # this library can be used:
31
- # require 'term/ansicolor'
32
- #
33
- # # Use this trick to work around namespace cluttering that
34
- # # happens if you just include Term::ANSIColor:
35
- #
36
- # class Color
37
- # class << self
38
- # include Term::ANSIColor
39
- # end
40
- # end
41
- #
42
- # print Color.red, Color.bold, "No Namespace cluttering:", Color.clear, "\n"
43
- # print Color.green + "green" + Color.clear, "\n"
44
- # print Color.on_red(Color.green("green")), "\n"
45
- # print Color.yellow { Color.on_black { "yellow on_black" } }, "\n\n"
46
- #
47
- # # Or shortcut Term::ANSIColor by assignment:
48
- # c = Term::ANSIColor
49
- #
50
- # print c.red, c.bold, "No Namespace cluttering (alternative):", c.clear, "\n"
51
- # print c.green + "green" + c.clear, "\n"
52
- # print c.on_red(c.green("green")), "\n"
53
- # print c.yellow { c.on_black { "yellow on_black" } }, "\n\n"
54
- #
55
- # # Anyway, I don't define any of Term::ANSIColor's methods in this example
56
- # # and I want to keep it short:
57
- # include Term::ANSIColor
58
- #
59
- # print red, bold, "Usage as constants:", reset, "\n"
60
- # print clear, "clear", reset, reset, "reset", reset,
61
- # bold, "bold", reset, dark, "dark", reset,
62
- # underscore, "underscore", reset, blink, "blink", reset,
63
- # negative, "negative", reset, concealed, "concealed", reset, "|\n",
64
- # black, "black", reset, red, "red", reset, green, "green", reset,
65
- # yellow, "yellow", reset, blue, "blue", reset, magenta, "magenta", reset,
66
- # cyan, "cyan", reset, white, "white", reset, "|\n",
67
- # on_black, "on_black", reset, on_red, "on_red", reset,
68
- # on_green, "on_green", reset, on_yellow, "on_yellow", reset,
69
- # on_blue, "on_blue", reset, on_magenta, "on_magenta", reset,
70
- # on_cyan, "on_cyan", reset, on_white, "on_white", reset, "|\n\n"
71
- #
72
- # print red, bold, "Usage as unary argument methods:", reset, "\n"
73
- # print clear("clear"), reset("reset"), bold("bold"), dark("dark"),
74
- # underscore("underscore"), blink("blink"), negative("negative"),
75
- # concealed("concealed"), "|\n",
76
- # black("black"), red("red"), green("green"), yellow("yellow"),
77
- # blue("blue"), magenta("magenta"), cyan("cyan"), white("white"), "|\n",
78
- # on_black("on_black"), on_red("on_red"), on_green("on_green"),#
79
- # on_yellow("on_yellow"), on_blue("on_blue"), on_magenta("on_magenta"),
80
- # on_cyan("on_cyan"), on_white("on_white"), "|\n\n"
81
- #
82
- # print red { bold { "Usage as block forms:" } }, "\n"
83
- # print clear { "clear" }, reset { "reset" }, bold { "bold" },
84
- # dark { "dark" }, underscore { "underscore" }, blink { "blink" },
85
- # negative { "negative" }, concealed { "concealed" }, "|\n",
86
- # black { "black" }, red { "red" }, green { "green" },
87
- # yellow { "yellow" }, blue { "blue" }, magenta { "magenta" },
88
- # cyan { "cyan" }, white { "white" }, "|\n",
89
- # on_black { "on_black" }, on_red { "on_red" }, on_green { "on_green" },
90
- # on_yellow { "on_yellow" }, on_blue { "on_blue" },
91
- # on_magenta { "on_magenta" }, on_cyan { "on_cyan" },
92
- # on_white { "on_white" }, "|\n\n"
93
- #
94
- # # Usage as Mixin into String or its Subclasses
95
- # class String
96
- # include Term::ANSIColor
97
- # end
98
- #
99
- # print "Usage as String Mixins:".red.bold, "\n"
100
- # print "clear".clear, "reset".reset, "bold".bold, "dark".dark,
101
- # "underscore".underscore, "blink".blink, "negative".negative,
102
- # "concealed".concealed, "|\n",
103
- # "black".black, "red".red, "green".green, "yellow".yellow,
104
- # "blue".blue, "magenta".magenta, "cyan".cyan, "white".white, "|\n",
105
- # "on_black".on_black, "on_red".on_red, "on_green".on_green,
106
- # "on_yellow".on_yellow, "on_blue".on_blue, "on_magenta".on_magenta,
107
- # "on_cyan".on_cyan, "on_white".on_white, "|\n\n"
108
- #
109
- # symbols = Term::ANSIColor::attributes
110
- # print red { bold { "All supported attributes = " } },
111
- # blue { symbols.inspect }, "\n\n"
112
- #
113
- # print "Send symbols to strings:".send(:red).send(:bold), "\n"
114
- # print symbols[12, 8].map { |c| c.to_s.send(c) }, "\n\n"
115
- #
116
- # print red { bold { "Make strings monochromatic again:" } }, "\n"
117
- # print [ "red".red, "not red anymore".red.uncolored,
118
- # uncolored { "not red anymore".red }, uncolored("not red anymore".red)
119
- # ].map { |x| x + "\n" }
120
- module Term
121
- # The ANSIColor module can be used for namespacing and mixed into your own
122
- # classes.
123
- module ANSIColor
124
- # :stopdoc:
125
- ATTRIBUTES = [
126
- [ :clear , 0 ],
127
- [ :reset , 0 ], # synonym for :clear
128
- [ :bold , 1 ],
129
- [ :dark , 2 ],
130
- [ :italic , 3 ], # not widely implemented
131
- [ :underline , 4 ],
132
- [ :underscore , 4 ], # synonym for :underline
133
- [ :blink , 5 ],
134
- [ :rapid_blink , 6 ], # not widely implemented
135
- [ :negative , 7 ], # no reverse because of String#reverse
136
- [ :concealed , 8 ],
137
- [ :strikethrough, 9 ], # not widely implemented
138
- [ :black , 30 ],
139
- [ :red , 31 ],
140
- [ :green , 32 ],
141
- [ :yellow , 33 ],
142
- [ :blue , 34 ],
143
- [ :magenta , 35 ],
144
- [ :cyan , 36 ],
145
- [ :white , 37 ],
146
- [ :on_black , 40 ],
147
- [ :on_red , 41 ],
148
- [ :on_green , 42 ],
149
- [ :on_yellow , 43 ],
150
- [ :on_blue , 44 ],
151
- [ :on_magenta , 45 ],
152
- [ :on_cyan , 46 ],
153
- [ :on_white , 47 ],
154
- ]
155
-
156
- ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
157
- # :startdoc:
158
-
159
- # Returns true, if the coloring function of this module
160
- # is switched on, false otherwise.
161
- def self.coloring?
162
- @coloring
163
- end
164
-
165
- # Turns the coloring on or off globally, so you can easily do
166
- # this for example:
167
- # Term::ANSIColor::coloring = STDOUT.isatty
168
- def self.coloring=(val)
169
- @coloring = val
170
- end
171
- self.coloring = true
172
-
173
- ATTRIBUTES.each do |c, v|
174
- eval %Q{
175
- def #{c}(string = nil)
176
- result = ''
177
- result << "\e[#{v}m" if Term::ANSIColor.coloring?
178
- if block_given?
179
- result << yield
180
- elsif string
181
- result << string
182
- elsif respond_to?(:to_str)
183
- result << self
184
- else
185
- return result #only switch on
186
- end
187
- result << "\e[0m" if Term::ANSIColor.coloring?
188
- result
189
- end
190
- }
191
- end
192
-
193
- # Regular expression that is used to scan for ANSI-sequences while
194
- # uncoloring strings.
195
- COLORED_REGEXP = /\e\[([34][0-7]|[0-9])m/
196
-
197
- # Returns an uncolored version of the string, that is all
198
- # ANSI-sequences are stripped from the string.
199
- def uncolored(string = nil) # :yields:
200
- if block_given?
201
- yield.gsub(COLORED_REGEXP, '')
202
- elsif string
203
- string.gsub(COLORED_REGEXP, '')
204
- elsif respond_to?(:to_str)
205
- gsub(COLORED_REGEXP, '')
206
- else
207
- ''
208
- end
209
- end
210
-
211
- module_function
212
-
213
- # Returns an array of all Term::ANSIColor attributes as symbols.
214
- def attributes
215
- ATTRIBUTE_NAMES
216
- end
217
- extend self
218
- end
219
- end
220
- # vim: set et sw=2 ts=2: