moved some tests over
This commit is contained in:
parent
e4ecb406bf
commit
2eb01cd575
9 changed files with 0 additions and 0 deletions
53
test/functional
Normal file
53
test/functional
Normal file
|
@ -0,0 +1,53 @@
|
|||
#!/bin/env ruby -w
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
require 'action_controller/routing'
|
||||
|
||||
class RoutesTest < Test::Unit::TestCase
|
||||
|
||||
def test_parse_uri
|
||||
assert_routing('', :controller => 'wiki', :action => 'index')
|
||||
assert_routing('x', :controller => 'wiki', :action => 'index', :web => 'x')
|
||||
assert_routing('x/y', :controller => 'wiki', :web => 'x', :action => 'y')
|
||||
assert_routing('x/y/z', :controller => 'wiki', :web => 'x', :action => 'y', :id => 'z')
|
||||
assert_recognizes({:web => 'x', :controller => 'wiki', :action => 'y'}, 'x/y/')
|
||||
assert_recognizes({:web => 'x', :controller => 'wiki', :action => 'y', :id => 'z'}, 'x/y/z/')
|
||||
end
|
||||
|
||||
def test_parse_uri_interestng_cases
|
||||
assert_routing('_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_/an_action/HomePage',
|
||||
:web => '_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_',
|
||||
:controller => 'wiki',
|
||||
:action => 'an_action', :id => 'HomePage'
|
||||
)
|
||||
assert_recognizes({:controller => 'wiki', :action => 'index'}, '///')
|
||||
end
|
||||
|
||||
def test_parse_uri_liberal_with_pagenames
|
||||
|
||||
assert_routing('web/show/%24HOME_PAGE',
|
||||
:controller => 'wiki', :web => 'web', :action => 'show', :id => '$HOME_PAGE')
|
||||
|
||||
assert_routing('web/show/HomePage%3Farg1%3Dvalue1%26arg2%3Dvalue2',
|
||||
:controller => 'wiki', :web => 'web', :action => 'show',
|
||||
:id => 'HomePage?arg1=value1&arg2=value2')
|
||||
|
||||
assert_routing('web/file/abc.zip',
|
||||
:web => 'web', :controller => 'file', :action => 'file', :id => 'abc.zip')
|
||||
assert_routing('web/pic/abc.jpg',
|
||||
:web => 'web', :controller => 'file', :action => 'pic', :id => 'abc.jpg')
|
||||
assert_routing('web/import', :web => 'web', :controller => 'file', :action => 'import')
|
||||
# default option is wiki
|
||||
assert_recognizes({:controller => 'wiki', :web => 'unknown_path', :action => 'index', },
|
||||
'unknown_path')
|
||||
end
|
||||
|
||||
def test_cases_broken_by_routes
|
||||
# assert_routing('web/show/Page+With+Spaces',
|
||||
# :controller => 'wiki', :web => 'web', :action => 'show', :id => 'Page With Spaces')
|
||||
# assert_routing('web/show/HomePage%2Fsomething_else',
|
||||
# :controller => 'wiki', :web => 'web', :action => 'show', :id => 'HomePage/something_else')
|
||||
end
|
||||
|
||||
end
|
92
test/uni
Executable file
92
test/uni
Executable file
|
@ -0,0 +1,92 @@
|
|||
#!/bin/env ruby -w
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'diff'
|
||||
|
||||
include Diff
|
||||
|
||||
class DiffTest < Test::Unit::TestCase
|
||||
def test_init
|
||||
assert_nothing_raised {
|
||||
s = SequenceMatcher.new('private Thread currentThread;',
|
||||
'private volatile Thread currentThread;') { |x| x == ' ' }
|
||||
}
|
||||
end
|
||||
|
||||
def test_matching_blocks
|
||||
s = SequenceMatcher.new 'abxcd', 'abcd'
|
||||
assert_equal [[0, 0, 2], [3, 2, 2], [5, 4, 0]], s.get_matching_blocks
|
||||
end
|
||||
|
||||
def test_ratio
|
||||
s = SequenceMatcher.new 'abcd', 'bcde'
|
||||
assert_equal 0.75, s.ratio, 0.001
|
||||
assert_equal 0.75, s.quick_ratio, 0.001
|
||||
assert_equal 1.0, s.real_quick_ratio, 0.001
|
||||
end
|
||||
|
||||
def test_longest_match
|
||||
s = SequenceMatcher.new(' abcd', 'abcd abcd')
|
||||
assert_equal [0, 4, 5], s.find_longest_match(0, 5, 0, 9)
|
||||
end
|
||||
|
||||
def test_opcodes
|
||||
s = SequenceMatcher.new('qabxcd', 'abycdf')
|
||||
assert_equal(
|
||||
[
|
||||
[:delete, 0, 1, 0, 0],
|
||||
[:equal, 1, 3, 0, 2],
|
||||
[:replace, 3, 4, 2, 3],
|
||||
[:equal, 4, 6, 3, 5],
|
||||
[:insert, 6, 6, 5, 6]
|
||||
],
|
||||
s.get_opcodes)
|
||||
end
|
||||
|
||||
|
||||
def test_count_leading
|
||||
assert_equal 3, Diff.count_leading(' abc', ' ')
|
||||
end
|
||||
|
||||
def test_html2list
|
||||
a = "here is the original text"
|
||||
assert_equal(
|
||||
['here ', 'is ', 'the ', 'original ', 'text'],
|
||||
HTMLDiff.html2list(a))
|
||||
end
|
||||
|
||||
def test_html_diff
|
||||
a = 'this was the original string'
|
||||
b = 'this is the super string'
|
||||
assert_equal('this <del class="diffmod">was </del>' +
|
||||
'<ins class="diffmod">is </ins>the ' +
|
||||
'<del class="diffmod">original </del>' +
|
||||
'<ins class="diffmod">super </ins>string',
|
||||
HTMLDiff.diff(a, b))
|
||||
end
|
||||
|
||||
def test_html_diff_with_multiple_paragraphs
|
||||
a = "<p>this was the original string</p>"
|
||||
b = "<p>this is</p>\r\n<p>the super string</p>\r\n<p>around the world</p>"
|
||||
|
||||
assert_equal(
|
||||
"<p>this <del class=\"diffmod\">was </del>" +
|
||||
"<ins class=\"diffmod\">is</ins></p>\r\n<p>the " +
|
||||
"<del class=\"diffmod\">original </del>" +
|
||||
"<ins class=\"diffmod\">super </ins>string</p>\r\n" +
|
||||
"<p><ins class=\"diffins\">around the world</ins></p>",
|
||||
HTMLDiff.diff(a, b)
|
||||
)
|
||||
end
|
||||
|
||||
# FIXME this test fails (ticket #67, http://dev.instiki.org/ticket/67)
|
||||
def test_html_diff_preserves_endlines_in_pre
|
||||
a = "<pre>\na\nb\nc\n</pre>"
|
||||
b = ''
|
||||
|
||||
assert_equal(
|
||||
"<pre>\n<del class=\"diffdel\">a\nb\nc\n</del></pre>",
|
||||
HTMLDiff.diff(a, b))
|
||||
end
|
||||
|
||||
end
|
22
test/unit/chunks/category_test.rb
Executable file
22
test/unit/chunks/category_test.rb
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../../test_helper'
|
||||
require 'chunks/category'
|
||||
|
||||
class CategoryTest < Test::Unit::TestCase
|
||||
include ChunkMatch
|
||||
|
||||
def test_single_category
|
||||
match(Category, 'category: test', :list => ['test'], :hidden => nil)
|
||||
match(Category, 'category : chunk test ', :list => ['chunk test'], :hidden => nil)
|
||||
match(Category, ':category: test', :list => ['test'], :hidden => ':')
|
||||
end
|
||||
|
||||
def test_multiple_categories
|
||||
match(Category, 'category: test, multiple', :list => ['test', 'multiple'], :hidden => nil)
|
||||
match(Category, 'category : chunk test , multi category,regression test case ',
|
||||
:list => ['chunk test','multi category','regression test case'], :hidden => nil
|
||||
)
|
||||
end
|
||||
|
||||
end
|
15
test/unit/chunks/nowiki_test.rb
Executable file
15
test/unit/chunks/nowiki_test.rb
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../../test_helper'
|
||||
require 'chunks/nowiki'
|
||||
|
||||
class NoWikiTest < Test::Unit::TestCase
|
||||
include ChunkMatch
|
||||
|
||||
def test_simple_nowiki
|
||||
match(NoWiki, 'This sentence contains <nowiki>[[raw text]]</nowiki>. Do not touch!',
|
||||
:plain_text => '[[raw text]]'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
98
test/unit/chunks/wiki_test.rb
Executable file
98
test/unit/chunks/wiki_test.rb
Executable file
|
@ -0,0 +1,98 @@
|
|||
#!/bin/env ruby
|
||||
|
||||
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
|
||||
# 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')
|
||||
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',
|
||||
:page_name => 'Sperberg McQueen')
|
||||
end
|
||||
|
||||
def test_complex_brackets
|
||||
match(WikiChunk::Link, 'This is a tricky link [[Sperberg-McQueen]]',
|
||||
:page_name => 'Sperberg-McQueen')
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
assert_link_parsed_as 'only text', 'only text', :show, '[[only text]]'
|
||||
# link and text
|
||||
assert_link_parsed_as 'page name', 'link text', :show, '[[page name|link text]]'
|
||||
# link and type (file)
|
||||
assert_link_parsed_as 'foo.tar.gz', 'foo.tar.gz', :file, '[[foo.tar.gz:file]]'
|
||||
# link and type (pic)
|
||||
assert_link_parsed_as 'foo.tar.gz', 'foo.tar.gz', :pic, '[[foo.tar.gz:pic]]'
|
||||
# link, text and type
|
||||
assert_link_parsed_as 'foo.tar.gz', 'FooTar', :file, '[[foo.tar.gz|FooTar:file]]'
|
||||
|
||||
# NEGATIVE TEST CASES
|
||||
|
||||
# empty page name
|
||||
assert_link_parsed_as '|link text?', '|link text?', :file, '[[|link text?:file]]'
|
||||
# empty link text
|
||||
assert_link_parsed_as 'page name?|', 'page name?|', :file, '[[page name?|:file]]'
|
||||
# empty link type
|
||||
assert_link_parsed_as 'page name', 'link?:', :show, '[[page name|link?:]]'
|
||||
# unknown link type
|
||||
assert_link_parsed_as 'page name:create_system', 'page name:create_system', :show,
|
||||
'[[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
|
70
test/unit/file_yard_test.rb
Executable file
70
test/unit/file_yard_test.rb
Executable file
|
@ -0,0 +1,70 @@
|
|||
#!/bin/env ruby -w
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'fileutils'
|
||||
require 'file_yard'
|
||||
require 'stringio'
|
||||
|
||||
class FileYardTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
FileUtils.mkdir_p(file_path)
|
||||
FileUtils.rm(Dir["#{file_path}/*"])
|
||||
@yard = FileYard.new(file_path, 100)
|
||||
end
|
||||
|
||||
def test_check_upload_size
|
||||
assert_nothing_raised { @yard.check_upload_size(100.kilobytes) }
|
||||
assert_raises(Instiki::ValidationError) { @yard.check_upload_size(100.kilobytes + 1) }
|
||||
end
|
||||
|
||||
def test_files
|
||||
assert_equal [], @yard.files
|
||||
|
||||
# FileYard gets the list of files from directory in the constructor
|
||||
@yard.upload_file('aaa', StringIO.new('file contents'))
|
||||
assert_equal ["#{file_path}/aaa"], Dir["#{file_path}/*"]
|
||||
assert_equal ['aaa'], @yard.files
|
||||
assert @yard.has_file?('aaa')
|
||||
assert_equal 'file contents', File.read(@yard.file_path('aaa'))
|
||||
end
|
||||
|
||||
def test_file_path
|
||||
assert_equal "#{file_path}/abcd", @yard.file_path('abcd')
|
||||
end
|
||||
|
||||
def test_size_limit
|
||||
@yard = FileYard.new(file_path, 1)
|
||||
one_kilobyte_string = "a" * 1.kilobyte
|
||||
|
||||
# as StringIO
|
||||
assert_nothing_raised {
|
||||
@yard.upload_file('acceptable_file', StringIO.new(one_kilobyte_string))
|
||||
}
|
||||
assert_raises(Instiki::ValidationError) {
|
||||
@yard.upload_file('one_byte_too_long', StringIO.new(one_kilobyte_string + 'a'))
|
||||
}
|
||||
|
||||
# as Tempfile
|
||||
require 'tempfile'
|
||||
|
||||
Tempfile.open('acceptable_file') do |f|
|
||||
f.write(one_kilobyte_string)
|
||||
assert_nothing_raised {
|
||||
@yard.upload_file('acceptable_file', f)
|
||||
}
|
||||
end
|
||||
|
||||
Tempfile.open('one_byte_too_long') do |f|
|
||||
f.write(one_kilobyte_string + 'a')
|
||||
assert_nothing_raised {
|
||||
@yard.upload_file('one_byte_too_long_2', f)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def file_path
|
||||
"#{RAILS_ROOT}/storage/test/instiki"
|
||||
end
|
||||
|
||||
end
|
69
test/unit/redcloth_for_tex_test.rb
Executable file
69
test/unit/redcloth_for_tex_test.rb
Executable file
|
@ -0,0 +1,69 @@
|
|||
#!/bin/env ruby -w
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'redcloth_for_tex'
|
||||
|
||||
class RedClothForTexTest < Test::Unit::TestCase
|
||||
def test_basics
|
||||
assert_equal '{\bf First Page}', RedClothForTex.new("*First Page*").to_tex
|
||||
assert_equal '{\em First Page}', RedClothForTex.new("_First Page_").to_tex
|
||||
assert_equal "\\begin{itemize}\n\t\\item A\n\t\t\\item B\n\t\t\\item C\n\t\\end{itemize}", RedClothForTex.new("* A\n* B\n* C").to_tex
|
||||
end
|
||||
|
||||
def test_blocks
|
||||
assert_equal '\section*{hello}', RedClothForTex.new("h1. hello").to_tex
|
||||
assert_equal '\subsection*{hello}', RedClothForTex.new("h2. hello").to_tex
|
||||
end
|
||||
|
||||
def test_table_of_contents
|
||||
|
||||
source = <<EOL
|
||||
* [[A]]
|
||||
** [[B]]
|
||||
** [[C]]
|
||||
* D
|
||||
** [[E]]
|
||||
*** F
|
||||
EOL
|
||||
|
||||
expected_result = <<EOL
|
||||
\\pagebreak
|
||||
|
||||
\\section{A}
|
||||
Abe
|
||||
|
||||
\\subsection{B}
|
||||
Babe
|
||||
|
||||
\\subsection{C}
|
||||
\\pagebreak
|
||||
|
||||
\\section{D}
|
||||
|
||||
\\subsection{E}
|
||||
|
||||
\\subsubsection{F}
|
||||
EOL
|
||||
expected_result.chop!
|
||||
assert_equal(expected_result, table_of_contents(source, 'A' => 'Abe', 'B' => 'Babe'))
|
||||
end
|
||||
|
||||
def test_entities
|
||||
assert_equal "Beck \\& Fowler are 100\\% cool", RedClothForTex.new("Beck & Fowler are 100% cool").to_tex
|
||||
end
|
||||
|
||||
def test_bracket_links
|
||||
assert_equal "such a Horrible Day, but I won't be Made Useless", RedClothForTex.new("such a [[Horrible Day]], but I won't be [[Made Useless]]").to_tex
|
||||
end
|
||||
|
||||
def test_footnotes_on_abbreviations
|
||||
assert_equal(
|
||||
"such a Horrible Day\\footnote{1}, but I won't be Made Useless",
|
||||
RedClothForTex.new("such a [[Horrible Day]][1], but I won't be [[Made Useless]]").to_tex
|
||||
)
|
||||
end
|
||||
|
||||
def test_subsection_depth
|
||||
assert_equal "\\subsubsection*{Hello}", RedClothForTex.new("h4. Hello").to_tex
|
||||
end
|
||||
end
|
217
test/unit/uri_test.rb
Executable file
217
test/unit/uri_test.rb
Executable file
|
@ -0,0 +1,217 @@
|
|||
#!/bin/env ruby -w
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'chunks/uri'
|
||||
|
||||
class URITest < Test::Unit::TestCase
|
||||
include ChunkMatch
|
||||
|
||||
def test_non_matches
|
||||
assert_conversion_does_not_apply(URIChunk, 'There is no URI here')
|
||||
assert_conversion_does_not_apply(URIChunk,
|
||||
'One gemstone is the garnet:reddish in colour, like ruby')
|
||||
end
|
||||
|
||||
def test_simple_uri
|
||||
# Simplest case
|
||||
match(URIChunk, 'http://www.example.com',
|
||||
:scheme =>'http', :host =>'www.example.com', :path => nil,
|
||||
:link_text => 'http://www.example.com'
|
||||
)
|
||||
# With trailing slash
|
||||
match(URIChunk, 'http://www.example.com/',
|
||||
:scheme =>'http', :host =>'www.example.com', :path => '/',
|
||||
:link_text => 'http://www.example.com/'
|
||||
)
|
||||
# Without http://
|
||||
match(URIChunk, 'www.example.com',
|
||||
:scheme =>'http', :host =>'www.example.com', :link_text => 'www.example.com'
|
||||
)
|
||||
# two parts
|
||||
match(URIChunk, 'example.com',
|
||||
:scheme =>'http',:host =>'example.com', :link_text => 'example.com'
|
||||
)
|
||||
# "unusual" base domain (was a bug in an early version)
|
||||
match(URIChunk, 'http://example.com.au/',
|
||||
:scheme =>'http', :host =>'example.com.au', :link_text => 'http://example.com.au/'
|
||||
)
|
||||
# "unusual" base domain without http://
|
||||
match(URIChunk, 'example.com.au',
|
||||
:scheme =>'http', :host =>'example.com.au', :link_text => 'example.com.au'
|
||||
)
|
||||
# Another "unusual" base domain
|
||||
match(URIChunk, 'http://www.example.co.uk/',
|
||||
:scheme =>'http', :host =>'www.example.co.uk',
|
||||
:link_text => 'http://www.example.co.uk/'
|
||||
)
|
||||
match(URIChunk, 'example.co.uk',
|
||||
:scheme =>'http', :host =>'example.co.uk', :link_text => 'example.co.uk'
|
||||
)
|
||||
# With some path at the end
|
||||
match(URIChunk, 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation',
|
||||
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
|
||||
:link_text => 'http://moinmoin.wikiwikiweb.de/HelpOnNavigation'
|
||||
)
|
||||
# With some path at the end, and withot http:// prefix
|
||||
match(URIChunk, 'moinmoin.wikiwikiweb.de/HelpOnNavigation',
|
||||
:scheme => 'http', :host => 'moinmoin.wikiwikiweb.de', :path => '/HelpOnNavigation',
|
||||
:link_text => 'moinmoin.wikiwikiweb.de/HelpOnNavigation'
|
||||
)
|
||||
# With a port number
|
||||
match(URIChunk, 'http://www.example.com:80',
|
||||
:scheme =>'http', :host =>'www.example.com', :port => '80', :path => nil,
|
||||
:link_text => 'http://www.example.com:80')
|
||||
# With a port number and a path
|
||||
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation',
|
||||
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
|
||||
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation')
|
||||
# With a query
|
||||
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val',
|
||||
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
|
||||
:query => 'arg=val',
|
||||
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val')
|
||||
# Query with two arguments
|
||||
match(URIChunk, 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2',
|
||||
:scheme =>'http', :host =>'www.example.com.tw', :port => '80', :path => '/HelpOnNavigation',
|
||||
:query => 'arg=val&arg2=val2',
|
||||
:link_text => 'http://www.example.com.tw:80/HelpOnNavigation?arg=val&arg2=val2')
|
||||
# HTTPS
|
||||
match(URIChunk, 'https://www.example.com',
|
||||
:scheme =>'https', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
|
||||
:link_text => 'https://www.example.com')
|
||||
# FTP
|
||||
match(URIChunk, 'ftp://www.example.com',
|
||||
:scheme =>'ftp', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
|
||||
:link_text => 'ftp://www.example.com')
|
||||
# mailto
|
||||
match(URIChunk, 'mailto:jdoe123@example.com',
|
||||
:scheme =>'mailto', :host =>'example.com', :port => nil, :path => nil, :query => nil,
|
||||
:user => 'jdoe123', :link_text => 'mailto:jdoe123@example.com')
|
||||
# something nonexistant
|
||||
match(URIChunk, 'foobar://www.example.com',
|
||||
:scheme =>'foobar', :host =>'www.example.com', :port => nil, :path => nil, :query => nil,
|
||||
:link_text => 'foobar://www.example.com')
|
||||
|
||||
# Soap opera (the most complex case imaginable... well, not really, there should be more evil)
|
||||
match(URIChunk, 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2',
|
||||
:scheme =>'http', :host =>'www.example.com.tw', :port => '80',
|
||||
:path => '/~jdoe123/Help%20Me%20', :query => 'arg=val&arg2=val2',
|
||||
:link_text => 'http://www.example.com.tw:80/~jdoe123/Help%20Me%20?arg=val&arg2=val2')
|
||||
|
||||
# from 0.9 bug reports
|
||||
match(URIChunk, 'http://www2.pos.to/~tosh/ruby/rdtool/en/doc/rd-draft.html',
|
||||
:scheme =>'http', :host => 'www2.pos.to',
|
||||
:path => '/~tosh/ruby/rdtool/en/doc/rd-draft.html')
|
||||
|
||||
match(URIChunk, 'http://support.microsoft.com/default.aspx?scid=kb;en-us;234562',
|
||||
:scheme =>'http', :host => 'support.microsoft.com', :path => '/default.aspx',
|
||||
:query => 'scid=kb;en-us;234562')
|
||||
end
|
||||
|
||||
def test_email_uri
|
||||
match(URIChunk, 'mail@example.com',
|
||||
:user => 'mail', :host => 'example.com', :link_text => 'mail@example.com'
|
||||
)
|
||||
end
|
||||
|
||||
def test_non_email
|
||||
# The @ is part of the normal text, but 'example.com' is marked up.
|
||||
match(URIChunk, 'Not an email: @example.com', :user => nil, :uri => 'http://example.com')
|
||||
end
|
||||
|
||||
def test_textile_image
|
||||
assert_conversion_does_not_apply(URIChunk,
|
||||
'This !http://hobix.com/sample.jpg! is a Textile image link.')
|
||||
end
|
||||
|
||||
def test_textile_link
|
||||
assert_conversion_does_not_apply(URIChunk,
|
||||
'This "hobix (hobix)":http://hobix.com/sample.jpg is a Textile link.')
|
||||
# just to be sure ...
|
||||
match(URIChunk, 'This http://hobix.com/sample.jpg should match',
|
||||
:link_text => 'http://hobix.com/sample.jpg')
|
||||
end
|
||||
|
||||
def test_inline_html
|
||||
assert_conversion_does_not_apply(URIChunk, '<IMG SRC="http://hobix.com/sample.jpg">')
|
||||
assert_conversion_does_not_apply(URIChunk, "<img src='http://hobix.com/sample.jpg'/>")
|
||||
end
|
||||
|
||||
def test_non_uri
|
||||
# "so" is a valid country code; "libproxy.so" is a valid url
|
||||
match(URIChunk, 'libproxy.so', :link_text => 'libproxy.so')
|
||||
|
||||
assert_conversion_does_not_apply URIChunk, 'httpd.conf'
|
||||
assert_conversion_does_not_apply URIChunk, 'ld.so.conf'
|
||||
assert_conversion_does_not_apply URIChunk, 'index.jpeg'
|
||||
assert_conversion_does_not_apply URIChunk, 'index.jpg'
|
||||
assert_conversion_does_not_apply URIChunk, 'file.txt'
|
||||
assert_conversion_does_not_apply URIChunk, 'file.doc'
|
||||
assert_conversion_does_not_apply URIChunk, 'file.pdf'
|
||||
assert_conversion_does_not_apply URIChunk, 'file.png'
|
||||
assert_conversion_does_not_apply URIChunk, 'file.ps'
|
||||
end
|
||||
|
||||
def test_uri_in_text
|
||||
match(URIChunk, 'Go to: http://www.example.com/', :host => 'www.example.com', :path =>'/')
|
||||
match(URIChunk, 'http://www.example.com/ is a link.', :host => 'www.example.com')
|
||||
match(URIChunk,
|
||||
'Email david@loudthinking.com',
|
||||
:scheme =>'mailto', :user =>'david', :host =>'loudthinking.com')
|
||||
# check that trailing punctuation is not included in the hostname
|
||||
match(URIChunk, 'Hey dude, http://fake.link.com.', :scheme => 'http', :host => 'fake.link.com')
|
||||
# this is a textile link, no match please.
|
||||
assert_conversion_does_not_apply(URIChunk, '"link":http://fake.link.com.')
|
||||
end
|
||||
|
||||
def test_uri_in_parentheses
|
||||
match(URIChunk, 'URI (http://brackets.com.de) in brackets', :host => 'brackets.com.de')
|
||||
match(URIChunk, 'because (as shown at research.net) the results', :host => 'research.net')
|
||||
match(URIChunk,
|
||||
'A wiki (http://wiki.org/wiki.cgi?WhatIsWiki) page',
|
||||
:scheme => 'http', :host => 'wiki.org', :path => '/wiki.cgi', :query => 'WhatIsWiki'
|
||||
)
|
||||
end
|
||||
|
||||
def test_uri_list_item
|
||||
match(
|
||||
URIChunk,
|
||||
'* http://www.btinternet.com/~mail2minh/SonyEricssonP80xPlatform.sis',
|
||||
:path => '/~mail2minh/SonyEricssonP80xPlatform.sis'
|
||||
)
|
||||
end
|
||||
|
||||
def test_interesting_uri_with__comma
|
||||
# Counter-intuitively, this URL matches, but the query part includes the trailing comma.
|
||||
# It has no way to know that the query does not include the comma.
|
||||
match(
|
||||
URIChunk,
|
||||
"This text contains a URL http://someplace.org:8080/~person/stuff.cgi?arg=val, doesn't it?",
|
||||
:scheme => 'http', :host => 'someplace.org', :port => '8080', :path => '/~person/stuff.cgi',
|
||||
:query => 'arg=val,')
|
||||
end
|
||||
|
||||
def test_local_urls
|
||||
# normal
|
||||
match(LocalURIChunk, 'http://perforce:8001/toto.html',
|
||||
:scheme => 'http', :host => 'perforce',
|
||||
:port => '8001', :link_text => 'http://perforce:8001/toto.html')
|
||||
|
||||
# in parentheses
|
||||
match(LocalURIChunk, 'URI (http://localhost:2500) in brackets',
|
||||
:host => 'localhost', :port => '2500')
|
||||
match(LocalURIChunk, 'because (as shown at http://perforce:8001) the results',
|
||||
:host => 'perforce', :port => '8001')
|
||||
match(LocalURIChunk,
|
||||
'A wiki (http://localhost:2500/wiki.cgi?WhatIsWiki) page',
|
||||
:scheme => 'http', :host => 'localhost', :path => '/wiki.cgi',
|
||||
:port => '2500', :query => 'WhatIsWiki')
|
||||
end
|
||||
|
||||
def assert_conversion_does_not_apply(chunk_type, str)
|
||||
processed_str = ContentStub.new(str.dup)
|
||||
chunk_type.apply_to(processed_str)
|
||||
assert_equal(str, processed_str)
|
||||
end
|
||||
|
||||
end
|
14
test/unit/wiki_words_test.rb
Executable file
14
test/unit/wiki_words_test.rb
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/bin/env ruby -w
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'wiki_words'
|
||||
|
||||
class WikiWordsTest < Test::Unit::TestCase
|
||||
|
||||
def test_utf8_characters_in_wiki_word
|
||||
assert_equal "Æåle Øen", WikiWords.separate("ÆåleØen")
|
||||
assert_equal "ÆÅØle Øen", WikiWords.separate("ÆÅØleØen")
|
||||
assert_equal "Æe ÅØle Øen", WikiWords.separate("ÆeÅØleØen")
|
||||
assert_equal "Legetøj", WikiWords.separate("Legetøj")
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue