Refactoring of chunks and rendering [Denis Mertz]
This commit is contained in:
parent
a87ef98aef
commit
78bad46419
19 changed files with 365 additions and 180 deletions
|
@ -75,11 +75,12 @@ end
|
|||
# It provides a easy way to test whether a chunk matches a particular string
|
||||
# and any the values of any fields that should be set after a match.
|
||||
class ContentStub < String
|
||||
attr_reader :chunks, :content
|
||||
include ChunkManager
|
||||
def initialize(str)
|
||||
super
|
||||
@chunks = []
|
||||
init_chunk_manager
|
||||
end
|
||||
def page_link(*); end
|
||||
end
|
||||
|
||||
module ChunkMatch
|
||||
|
@ -97,7 +98,7 @@ module ChunkMatch
|
|||
expected_chunk_state.each_pair do |a_method, expected_value|
|
||||
assert content.chunks.last.kind_of?(chunk_type)
|
||||
assert_respond_to(content.chunks.last, a_method)
|
||||
assert_equal(expected_value, content.chunks.last.send(a_method.to_sym),
|
||||
assert_equal(expected_value, content.chunks.last.send(a_method.to_sym),
|
||||
"Wrong #{a_method} value")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,12 +5,6 @@ require 'chunks/wiki'
|
|||
|
||||
class WikiTest < Test::Unit::TestCase
|
||||
|
||||
class ContentStub < String
|
||||
def chunks
|
||||
@chunks ||= []
|
||||
end
|
||||
end
|
||||
|
||||
include ChunkMatch
|
||||
|
||||
def test_simple
|
||||
|
@ -18,21 +12,19 @@ class WikiTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_escaped
|
||||
# escape is only implemented in WikiChunk::Word
|
||||
match(WikiChunk::Word, 'Do not link to an \EscapedWord',
|
||||
:page_name => 'EscapedWord', :escaped_text => 'EscapedWord'
|
||||
)
|
||||
end
|
||||
|
||||
def test_simple_brackets
|
||||
match(WikiChunk::Link, 'This is a [[bracketted link]]',
|
||||
:page_name => 'bracketted link', :escaped_text => nil
|
||||
)
|
||||
match(WikiChunk::Link, 'This is a [[bracketted link]]', :page_name => 'bracketted link')
|
||||
end
|
||||
|
||||
def test_complex_brackets
|
||||
match(WikiChunk::Link, 'This is a tricky link [[Sperberg-McQueen]]',
|
||||
:page_name => 'Sperberg-McQueen', :escaped_text => nil
|
||||
)
|
||||
match(WikiChunk::Link, 'This is a tricky link [[Sperberg-McQueen]]',
|
||||
:page_name => 'Sperberg-McQueen')
|
||||
end
|
||||
|
||||
def test_textile_link
|
||||
|
|
|
@ -15,6 +15,7 @@ class RevisionTest < Test::Unit::TestCase
|
|||
['MyWay', 'SmartEngine', 'ThatWay'].each do |page|
|
||||
@wiki.write_page('wiki1', page, page, Time.now, 'Me')
|
||||
end
|
||||
@wiki.write_page('wiki1','NoWikiWord', 'hey you', Time.now, 'Me')
|
||||
|
||||
@revision = Revision.new(@page, 1,
|
||||
'HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \OverThere -- ' +
|
||||
|
@ -24,6 +25,9 @@ class RevisionTest < Test::Unit::TestCase
|
|||
|
||||
def test_wiki_words
|
||||
assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ), @revision.wiki_words.sort
|
||||
|
||||
@wiki.write_page('wiki1', 'NoWikiWord', 'hey you', Time.now, 'Me')
|
||||
assert_equal [], @wiki.read_page('wiki1', 'NoWikiWord').wiki_words
|
||||
end
|
||||
|
||||
def test_existing_pages
|
||||
|
|
|
@ -209,7 +209,7 @@ class URITest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def assert_conversion_does_not_apply(chunk_type, str)
|
||||
processed_str = str.dup
|
||||
processed_str = ContentStub.new(str.dup)
|
||||
chunk_type.apply_to(processed_str)
|
||||
assert_equal(str, processed_str)
|
||||
end
|
||||
|
|
|
@ -134,4 +134,4 @@ class WebTest < Test::Unit::TestCase
|
|||
@web.add_page(Page.new(@web, 'EverBeenHated', 'I am me EverBeenHated',
|
||||
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue