File: test_interwiki.rb

package info (click to toggle)
hiki 1.0.0-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,812 kB
  • sloc: ruby: 14,572; lisp: 926; sh: 19; makefile: 16
file content (57 lines) | stat: -rw-r--r-- 1,943 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
# $Id: test_interwiki.rb,v 1.2 2005-06-28 05:39:09 fdiary Exp $

require 'test/unit'
require 'hiki/interwiki'

class InterWiki_Unit_Tests < Test::Unit::TestCase
  def setup
    @interwiki = Hiki::InterWiki.new( <<-EOF )
*[[Hiki|http://hikiwiki.org/ja/?]] euc
*[[Siki|http://hikiwiki.org/ja/?]] sjis
*[[Uiki|http://hikiwiki.org/ja/?]] utf8
*[[sf.jp|http://sourceforge.jp/]] alias
EOF
  end

  def test_interwiki_found
    assert_equal(['http://hikiwiki.org/ja/?FrontPage', 'Hiki:FrontPage'],
                 @interwiki.interwiki('Hiki', 'FrontPage'))
  end

  def test_interwiki_found_euc
    assert_equal(['http://hikiwiki.org/ja/?%A5%D5%A5%ED%A5%F3%A5%C8%A5%DA%A1%BC%A5%B8',
                  'Hiki:フロントページ'],
                 @interwiki.interwiki('Hiki', 'フロントページ'))
  end

  def test_interwiki_found_sjis
    if Object.const_defined?(:Encoding)
      assert_equal(['http://hikiwiki.org/ja/?%83%74%83%8D%83%93%83%67%83%79%81%5B%83%57',
                    'Siki:フロントページ'],
                   @interwiki.interwiki('Siki', 'フロントページ'))
    else
      assert_equal(['http://hikiwiki.org/ja/?%83t%83%8D%83%93%83g%83y%81%5B%83W',
                    'Siki:フロントページ'],
                   @interwiki.interwiki('Siki', 'フロントページ'))
    end
  end

  def test_interwiki_found_utf8
    assert_equal(['http://hikiwiki.org/ja/?%E3%83%95%E3%83%AD%E3%83%B3%E3%83%88%E3%83%9A%E3%83%BC%E3%82%B8',
                  'Uiki:フロントページ'],
                 @interwiki.interwiki('Uiki', 'フロントページ'))
  end

  def test_interwiki_not_found
    assert_equal( nil, @interwiki.interwiki( 'foo', 'bar' ))
  end

  def test_outer_alias_found
    assert_equal( ['http://sourceforge.jp/', 'sf.jp'], @interwiki.outer_alias( 'sf.jp' ))
  end

  def test_outer_alias_not_found
    assert_equal( nil, @interwiki.outer_alias( 'sf.net' ))
  end
end