#!/usr/bin/env ruby

## Test a specific number of list items, or a range of numbers of list items.
## With the default list item length (26), it breaks at 78 list items:
# 
# irb(main):001:0> test_ol_range(0..100)
# Testing with 0 ol lines...
# Testing with 50 ol lines...
# Error while testing with 78 ol lines:
# RegexpError: Stack overflow in regexp matcher: /
# 		^						# Start of line
# 		<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script)	# Start tag: \2
# 		\b						# word break
# 		(.*\n)*?				# Any number of lines, minimal match
# 		<\/\1>					# Matching end tag
# 		[ ]*					# trailing spaces
# 		(?=\n+|\Z)				# End of line or document
# 	  /ix
# 	from ./bluecloth.rb:342:in `gsub!'
# 	from ./bluecloth.rb:342:in `hide_html_blocks'
# 	from ./bluecloth.rb:248:in `apply_block_transforms'
# 	from ./bluecloth.rb:202:in `to_html'
# [snip]
# 
require "bluecloth"

ALPHAPERLINE = 1
OLLINE = "1. %s\n"%[('a'..'z').to_a.to_s * ALPHAPERLINE]
ULLINE = "* %s\n"%[('a'..'z').to_a.to_s * ALPHAPERLINE]

def test_lines(n,line)
	begin
		puts "Testing with %d ol lines..."%n if n%50 == 0
		BlueCloth.new(line * n).to_html
	rescue
		puts "Error while testing with %d ol lines:"%n
		raise
	end
end

def test_ol_range(range)
	range.each do |num| test_lines(num, OLLINE) end
end

def test_ul_range(range)
	range.each do |num| test_lines(num, ULLINE) end
end

