2005-08-11 07:46:38 +02:00
|
|
|
#!/usr/bin/env ruby
|
2005-01-24 19:52:04 +01:00
|
|
|
|
|
|
|
require File.dirname(__FILE__) + '/../../test_helper'
|
|
|
|
require 'chunks/wiki'
|
|
|
|
|
|
|
|
class WikiTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
include ChunkMatch
|
|
|
|
|
|
|
|
def test_simple
|
|
|
|
match(WikiChunk::Word, 'This is a WikiWord okay?', :page_name => 'WikiWord')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_escaped
|
2005-03-27 20:13:43 +02:00
|
|
|
# escape is only implemented in WikiChunk::Word
|
2005-01-24 19:52:04 +01:00
|
|
|
match(WikiChunk::Word, 'Do not link to an \EscapedWord',
|
|
|
|
:page_name => 'EscapedWord', :escaped_text => 'EscapedWord'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_simple_brackets
|
2005-05-12 02:56:57 +02:00
|
|
|
match(WikiChunk::Link, 'This is a [[bracketted link]]', :page_name => 'bracketted link')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_void_brackets
|
|
|
|
# double brackets woith only spaces inside are not a WikiLink
|
|
|
|
no_match(WikiChunk::Link, "This [[ ]] are [[]] no [[ \t ]] links")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_brackets_strip_spaces
|
|
|
|
match(WikiChunk::Link,
|
|
|
|
"This is a [[Sperberg-McQueen \t ]] link with trailing spaces to strip",
|
|
|
|
:page_name => 'Sperberg-McQueen')
|
|
|
|
match(WikiChunk::Link,
|
|
|
|
"This is a [[ \t Sperberg-McQueen]] link with leading spaces to strip",
|
|
|
|
:page_name => 'Sperberg-McQueen')
|
|
|
|
match(WikiChunk::Link,
|
|
|
|
'This is a [[ Sperberg-McQueen ]] link with spaces around it to strip',
|
|
|
|
:page_name => 'Sperberg-McQueen')
|
|
|
|
match(WikiChunk::Link,
|
|
|
|
'This is a [[ Sperberg McQueen ]] link with spaces inside and around it',
|
2006-03-12 00:25:04 +01:00
|
|
|
:page_name => 'Sperberg McQueen')
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_complex_brackets
|
2005-03-27 20:13:43 +02:00
|
|
|
match(WikiChunk::Link, 'This is a tricky link [[Sperberg-McQueen]]',
|
|
|
|
:page_name => 'Sperberg-McQueen')
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
2005-05-12 02:56:57 +02:00
|
|
|
|
|
|
|
def test_include_chunk_pattern
|
|
|
|
content = 'This is a [[!include pagename]] and [[!include WikiWord]] but [[blah]]'
|
|
|
|
recognized_includes = content.scan(Include.pattern).collect { |m| m[0] }
|
|
|
|
assert_equal %w(pagename WikiWord), recognized_includes
|
|
|
|
end
|
2005-01-24 19:52:04 +01:00
|
|
|
|
|
|
|
def test_textile_link
|
|
|
|
textile_link = ContentStub.new('"Here is a special link":SpecialLink')
|
|
|
|
WikiChunk::Word.apply_to(textile_link)
|
|
|
|
assert_equal '"Here is a special link":SpecialLink', textile_link
|
|
|
|
assert textile_link.chunks.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_file_types
|
|
|
|
# only link
|
2005-02-13 19:53:49 +01:00
|
|
|
assert_link_parsed_as 'only text', 'only text', :show, '[[only text]]'
|
2005-01-24 19:52:04 +01:00
|
|
|
# link and text
|
2005-02-13 19:53:49 +01:00
|
|
|
assert_link_parsed_as 'page name', 'link text', :show, '[[page name|link text]]'
|
2005-01-24 19:52:04 +01:00
|
|
|
# link and type (file)
|
2005-02-13 19:53:49 +01:00
|
|
|
assert_link_parsed_as 'foo.tar.gz', 'foo.tar.gz', :file, '[[foo.tar.gz:file]]'
|
2005-01-24 19:52:04 +01:00
|
|
|
# link and type (pic)
|
2005-02-13 19:53:49 +01:00
|
|
|
assert_link_parsed_as 'foo.tar.gz', 'foo.tar.gz', :pic, '[[foo.tar.gz:pic]]'
|
2005-01-24 19:52:04 +01:00
|
|
|
# link, text and type
|
2005-02-13 19:53:49 +01:00
|
|
|
assert_link_parsed_as 'foo.tar.gz', 'FooTar', :file, '[[foo.tar.gz|FooTar:file]]'
|
2005-01-24 19:52:04 +01:00
|
|
|
|
|
|
|
# NEGATIVE TEST CASES
|
|
|
|
|
|
|
|
# empty page name
|
2005-02-13 19:53:49 +01:00
|
|
|
assert_link_parsed_as '|link text?', '|link text?', :file, '[[|link text?:file]]'
|
2005-01-24 19:52:04 +01:00
|
|
|
# empty link text
|
2005-02-13 19:53:49 +01:00
|
|
|
assert_link_parsed_as 'page name?|', 'page name?|', :file, '[[page name?|:file]]'
|
2005-01-24 19:52:04 +01:00
|
|
|
# empty link type
|
2005-02-13 19:53:49 +01:00
|
|
|
assert_link_parsed_as 'page name', 'link?:', :show, '[[page name|link?:]]'
|
2005-01-24 19:52:04 +01:00
|
|
|
# unknown link type
|
2005-02-13 19:53:49 +01:00
|
|
|
assert_link_parsed_as 'page name:create_system', 'page name:create_system', :show,
|
2005-01-24 19:52:04 +01:00
|
|
|
'[[page name:create_system]]'
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_link_parsed_as(expected_page_name, expected_link_text, expected_link_type, link)
|
|
|
|
link_to_file = ContentStub.new(link)
|
|
|
|
WikiChunk::Link.apply_to(link_to_file)
|
|
|
|
chunk = link_to_file.chunks.last
|
|
|
|
assert chunk
|
|
|
|
assert_equal expected_page_name, chunk.page_name
|
|
|
|
assert_equal expected_link_text, chunk.link_text
|
|
|
|
assert_equal expected_link_type, chunk.link_type
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|