OSDN Git Service

#27621 言語間リンク取得時に<includeonly>, <noinclude>を考慮するよう修正,
[wptscs/wpts.git] / WptscsTest / Parsers / MediaWikiRedirectParserTest.cs
1 // ================================================================================================
2 // <summary>
3 //      MediaWikiRedirectParserのテストクラスソース。</summary>
4 //
5 // <copyright file="MediaWikiRedirectParserTest.cs" company="honeplusのメモ帳">
6 //      Copyright (C) 2012 Honeplus. All rights reserved.</copyright>
7 // <author>
8 //      Honeplus</author>
9 // ================================================================================================
10
11 namespace Honememo.Wptscs.Parsers
12 {
13     using System;
14     using Honememo.Parsers;
15     using Honememo.Wptscs.Models;
16     using Honememo.Wptscs.Websites;
17     using NUnit.Framework;
18
19     /// <summary>
20     /// <see cref="MediaWikiRedirectParser"/>のテストクラスです。
21     /// </summary>
22     [TestFixture]
23     class MediaWikiRedirectParserTest
24     {
25         #region インスタンス実装メソッドテストケース
26
27         /// <summary>
28         /// <see cref="MediaWikiRedirectParser.TryParse"/>メソッドテストケース。
29         /// </summary>
30         [Test]
31         public void TestTryParse()
32         {
33             IElement element;
34             MediaWikiLink link;
35             using (MediaWikiRedirectParser parser = new MediaWikiRedirectParser(new MockFactory().GetMediaWiki("en")))
36             {
37                 // 通常のリダイレクト
38                 Assert.IsTrue(parser.TryParse("#redirect [[Test]]", out element));
39                 Assert.IsInstanceOf(typeof(MediaWikiLink), element);
40                 link = (MediaWikiLink)element;
41                 Assert.AreEqual("Test", link.Title);
42                 Assert.IsNull(link.Section);
43
44                 // セクション指定付きのリダイレクト
45                 Assert.IsTrue(parser.TryParse("#redirect [[Test#Section]]", out element));
46                 Assert.IsInstanceOf(typeof(MediaWikiLink), element);
47                 link = (MediaWikiLink)element;
48                 Assert.AreEqual("Test", link.Title);
49                 Assert.AreEqual("Section", link.Section);
50
51                 // 普通の記事
52                 Assert.IsFalse(parser.TryParse("'''Example''' may refer to:", out element));
53                 Assert.IsNull(element);
54
55                 // enで日本語の転送書式
56                 Assert.IsFalse(parser.TryParse("#転送 [[Test]]", out element));
57                 Assert.IsNull(element);
58
59                 // 空文字列・null
60                 Assert.IsFalse(parser.TryParse(String.Empty, out element));
61                 Assert.IsNull(element);
62                 Assert.IsFalse(parser.TryParse(null, out element));
63                 Assert.IsNull(element);
64             }
65
66             using (MediaWikiRedirectParser parser = new MediaWikiRedirectParser(new MockFactory().GetMediaWiki("ja")))
67             {
68                 // jaで日本語の転送書式
69                 Assert.IsTrue(parser.TryParse("#転送 [[Test]]", out element));
70                 Assert.IsInstanceOf(typeof(MediaWikiLink), element);
71                 link = (MediaWikiLink)element;
72                 Assert.AreEqual("Test", link.Title);
73             }
74         }
75
76         #endregion
77     }
78 }