Ejemplo n.º 1
0
        public void TalkHeaderDefaultsortChange()
        {
            string start = @"
==Foo==
bar", df = @"{{DEFAULTSORT:Bert}}";

            string articleText = start + "\r\n" + df;

            TalkPageHeaders.ProcessTalkPage(ref articleText, DEFAULTSORT.MoveToBottom);
            Assert.AreEqual(start + "\r\n" + "\r\n" + df, articleText);

            articleText = start + df;

            TalkPageHeaders.ProcessTalkPage(ref articleText, DEFAULTSORT.MoveToTop);
            Assert.AreEqual(df + "\r\n" + start, articleText);

            articleText = start + df;

            TalkPageHeaders.ProcessTalkPage(ref articleText, DEFAULTSORT.NoChange);
            Assert.AreEqual(start + df, articleText);

            string df2 = @"{{DEFAULTSORT:}}";

            articleText = start + df2;

            TalkPageHeaders.ProcessTalkPage(ref articleText, DEFAULTSORT.MoveToBottom);
            Assert.AreEqual(start, articleText, "defaultsort with no key removed");

            articleText = start + df2;

            TalkPageHeaders.ProcessTalkPage(ref articleText, DEFAULTSORT.MoveToTop);
            Assert.AreEqual(start, articleText, "defaultsort with no key removed");
        }
Ejemplo n.º 2
0
        public void AddMissingFirstCommentHeader()
        {
            const string comment       = @"
Hello world comment.";
            string       newSummary    = "";
            string       articleTextIn = articleTextHeader + comment;

            // plain comment
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(articleTextIn, articleTextHeader + "\r\n" + @"
==Untitled==
Hello world comment.");
            Assert.IsTrue(newSummary.Contains("Added missing comments section header"));

            // idented comment2
            articleTextIn = articleTextHeader + @"
*Hello world comment2.";
            newSummary    = "";
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(articleTextIn, articleTextHeader + "\r\n" + @"
==Untitled==
*Hello world comment2.");
            Assert.IsTrue(newSummary.Contains("Added missing comments section header"));

            // idented comment3
            articleTextIn = articleTextHeader + @"
:Hello world comment3.";
            newSummary    = "";
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(articleTextIn, articleTextHeader + "\r\n" + @"
==Untitled==
:Hello world comment3.");
            Assert.IsTrue(newSummary.Contains("Added missing comments section header"));

            // quoted comment
            articleTextIn = articleTextHeader + @"
""Hello world comment4"".";
            newSummary    = "";
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(articleTextIn, articleTextHeader + "\r\n" + @"
==Untitled==
""Hello world comment4"".");
            Assert.IsTrue(newSummary.Contains("Added missing comments section header"));

            // heading level 3 changed to level 2
            articleTextIn = articleTextHeader + "\r\n" + @"===Foo bar===
*Hello world comment2.";
            newSummary    = "";
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.IsTrue(articleTextIn.Contains(@"==Foo bar=="));
            Assert.IsFalse(articleTextIn.Contains(@"==Untitled=="));
            Assert.IsTrue(newSummary.Contains("Corrected comments section header"));
        }
Ejemplo n.º 3
0
        public void RenameTalkHeader()
        {
            string talkheader = @"{{talkheader|noarchive=no}}", talkrest = @"==hello==
hello talk";
            string articleText = talkrest + "\r\n" + talkheader;

            TalkPageHeaders.ProcessTalkPage(ref articleText, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"{{Talk header|noarchive=no}}" + "\r\n" + talkrest + "\r\n", articleText, "renamed to upper case with space");
        }
Ejemplo n.º 4
0
        public void RenameTalkHeader()
        {
            string talkheader = @"{{talkheader|noarchive=no}}", talkrest = @"==hello==
hello talk";
            string articleText = talkrest + "\r\n" + talkheader, newSummary = "";

            TalkPageHeaders.ProcessTalkPage(ref articleText, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"{{talk header|noarchive=no}}" + "\r\n" + talkrest + "\r\n", articleText);
            Assert.IsTrue(newSummary.Contains("{{tl|Talk header}} given top billing"));
        }
Ejemplo n.º 5
0
        public void SkipToTalk()
        {
            string articleText = @"{{Skiptotoc}}", STT = @"{{Skip to talk}}";

            TalkPageHeaders.ProcessTalkPage(ref articleText, DEFAULTSORT.NoChange);
            Assert.AreEqual(STT + "\r\n", articleText);

            articleText = @"{{skiptotoctalk}}";

            TalkPageHeaders.ProcessTalkPage(ref articleText, DEFAULTSORT.NoChange);
            Assert.AreEqual(STT + "\r\n", articleText);
        }
Ejemplo n.º 6
0
        public void RemoveTemplateNamespace()
        {
            string T1 = @"{{Template:Foo}}", T2 = @"{{Template:Foo}}
==Section==
{{Template:Bar}}";

            Assert.IsFalse(TalkPageHeaders.ProcessTalkPage(ref T1, DEFAULTSORT.NoChange));
            Assert.AreEqual("{{Foo}}", T1, "template namespace removed");

            Assert.IsFalse(TalkPageHeaders.ProcessTalkPage(ref T2, DEFAULTSORT.NoChange));
            Assert.AreEqual(@"{{Foo}}
==Section==
{{Template:Bar}}", T2, "changes only made in zeroth section");
        }
Ejemplo n.º 7
0
        public void SkipToTalk()
        {
            string articleText = @"{{Skiptotoc}}", newSummary = "", STT = @"{{Skip to talk}}";

            TalkPageHeaders.ProcessTalkPage(ref articleText, ref newSummary, DEFAULTSORT.NoChange);
            Assert.AreEqual(STT + "\r\n", articleText);
            Assert.IsTrue(newSummary.Contains("Skip to talk"));

            articleText = @"{{skiptotoctalk}}";
            newSummary  = "";
            TalkPageHeaders.ProcessTalkPage(ref articleText, ref newSummary, DEFAULTSORT.NoChange);
            Assert.AreEqual(STT + "\r\n", articleText);
            Assert.IsTrue(newSummary.Contains("Skip to talk"));
        }
Ejemplo n.º 8
0
        public void MoveTalkHeader()
        {
            string talkheader = @"{{talk header|noarchive=no|search=no|arpol=no|wp=no|disclaimer=no|shortcut1|shortcut2}}", talkrest = @"==hello==
hello talk";
            string articleText = talkrest + "\r\n" + talkheader;

            TalkPageHeaders.ProcessTalkPage(ref articleText, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(talkheader + "\r\n" + talkrest + "\r\n", articleText);
            Assert.IsTrue(newSummary.Contains("{{tl|Talk header}} given top billing"));

            // handles {{talk header}} on same line as other template
            string WPBS = @"{{WikiProjectBannerShell|blp=yes|1=
{{OH-Project|class=B|importance=Low|nested=yes}}
{{WPBiography|living=yes|class=B|priority=Low|filmbio-work-group=yes|nested=yes|listas=Parker, Sarah Jessica}}
{{WikiProject Cincinnati|class=B|importance=mid|nested=yes}}
}}", rest = "\r\n" + @"==Song Jessie by Joshua Kadison==
In the article it says that above mentioned";

            articleText = WPBS + @"{{Talkheader}}" + rest;

            TalkPageHeaders.ProcessTalkPage(ref articleText, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"{{talk header}}" + "\r\n" + WPBS + rest, articleText);
            Assert.IsTrue(newSummary.Contains("{{tl|Talk header}} given top billing"));

            // no change if already at top
            articleText = talkheader + "\r\n" + talkrest;
            newSummary  = "";
            TalkPageHeaders.ProcessTalkPage(ref articleText, ref newSummary, DEFAULTSORT.NoChange);
            Assert.AreEqual(talkheader + "\r\n" + talkrest, articleText);
            Assert.IsFalse(newSummary.Contains("{{tl|Talk header}} given top billing"));

            // no change if no talk header
            articleText = talkrest;
            newSummary  = "";
            TalkPageHeaders.ProcessTalkPage(ref articleText, ref newSummary, DEFAULTSORT.NoChange);
            Assert.AreEqual(talkrest, articleText);
            Assert.IsFalse(newSummary.Contains("{{tl|Talk header}} given top billing"));
        }
Ejemplo n.º 9
0
        public void AddMissingFirstCommentHeaderNoChanges()
        {
            // no change – header already
            string articleTextIn = articleTextHeader + @"
==Question==
:Hello world comment3.";

            newSummary = "";
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(articleTextIn, articleTextHeader + @"
==Question==
:Hello world comment3.");
            Assert.IsFalse(newSummary.Contains("Added missing comments section header"));

            // no change – already header at top
            articleTextIn = @"
{{Some template}}
==Question==
:Hello world comment3.";

            newSummary = "";
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"
{{Some template}}
==Question==
:Hello world comment3.", articleTextIn);
            Assert.IsFalse(newSummary.Contains("Added missing comments section header"));

            // no change – already header at top 2
            articleTextIn = @"
==Question==
{{Some template}}
:Hello world comment3.";

            newSummary = "";
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"
==Question==
{{Some template}}
:Hello world comment3.", articleTextIn);
            Assert.IsFalse(newSummary.Contains("Added missing comments section header"));

            // no change – no comments
            articleTextIn = @"
==Question==
{{Some template}}";

            newSummary = "";
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"
==Question==
{{Some template}}", articleTextIn);
            Assert.IsFalse(newSummary.Contains("Added missing comments section header"));

            // no change – only text in template
            articleTextIn = @"
{{foo|
bar|
end}}";

            newSummary = "";
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"
{{foo|
bar|
end}}", articleTextIn);
            Assert.IsFalse(newSummary.Contains("Added missing comments section header"));

            // no change – only TOC
            articleTextIn = @"
__TOC__";

            newSummary = "";
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"
__TOC__", articleTextIn);
            Assert.IsFalse(newSummary.Contains("Added missing comments section header"));

            // no change -- only in template
            const string allInTemplate = @"{{archive box|
*[[/Archive: GA review|Good Article review]]}}

== Explanation of Wright's work in ''Certaine Errors'' ==";

            articleTextIn = allInTemplate;
            newSummary    = "";
            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, ref newSummary, DEFAULTSORT.NoChange);

            Assert.AreEqual(allInTemplate, articleTextIn);
            Assert.IsFalse(newSummary.Contains("Added missing comments section header"));
        }
Ejemplo n.º 10
0
        public void AddMissingFirstCommentHeaderNoChanges()
        {
            // no change – header already
            string articleTextIn = articleTextHeader + @"
==Question==
:Hello world comment3.";


            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, DEFAULTSORT.NoChange);

            Assert.AreEqual(articleTextIn, articleTextHeader + @"
==Question==
:Hello world comment3.");

            // no change – already header at top
            articleTextIn = @"
{{Some template}}
==Question==
:Hello world comment3.";


            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"
{{Some template}}
==Question==
:Hello world comment3.", articleTextIn);

            // no change – already header at top 2
            articleTextIn = @"
==Question==
{{Some template}}
:Hello world comment3.";

            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"
==Question==
{{Some template}}
:Hello world comment3.", articleTextIn);

            // no change – no comments
            articleTextIn = @"
==Question==
{{Some template}}";

            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"
==Question==
{{Some template}}", articleTextIn);

            // no change – only text in template
            articleTextIn = @"
{{foo|
bar|
end}}";

            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"
{{foo|
bar|
end}}", articleTextIn);

            // no change – only comments
            articleTextIn = @"
<!--
foo
-->";

            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"
<!--
foo
-->", articleTextIn);

            // no change – only TOC
            articleTextIn = @"
__TOC__";

            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, DEFAULTSORT.NoChange);

            Assert.AreEqual(@"
__TOC__", articleTextIn);

            // no change -- only in template
            const string allInTemplate = @"{{archive box|
*[[/Archive: GA review|Good Article review]]}}

== Explanation of Wright's work in ''Certaine Errors'' ==";

            articleTextIn = allInTemplate;

            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, DEFAULTSORT.NoChange);

            Assert.AreEqual(allInTemplate, articleTextIn);

            // no change -- only after template on same line
            // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs#Section_header_added_in_wrong_position
            const string allAfterTemplate = @"{{archive box|words}} extra foo

{{another one}}";

            articleTextIn = allAfterTemplate;

            TalkPageHeaders.ProcessTalkPage(ref articleTextIn, DEFAULTSORT.NoChange);

            Assert.AreEqual(allAfterTemplate, articleTextIn);
        }