コード例 #1
0
        public void MoveDablinksTests()
        {
            const string d = @"Fred is a doctor.
Fred has a dog.
[[Category:Dog owners]]
{{some template}}
";

            string e = @"{{otherpeople1|Fred the dancer|Fred Smith (dancer)}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            e = @"{{For|Fred the dancer|Fred Smith (dancer)}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            e = @"{{redirect2|Fred the dancer|Fred Smith (dancer)}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            e = @"{{redirect2|Fred the {{dancer}}|Fred Smith (dancer)}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            // check no change when already in correct position
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(e + "\r\n" + d));

            // don't move dablinks in a section
            string f = @"Article words
== heading ==
{{redirect2|Fred the dancer|Fred Smith (dancer)}}
words";
            Assert.AreEqual(f, MetaDataSorter.MoveDablinks(f));

        }
コード例 #2
0
        public void MoveMoreNoFootnotesTests()
        {
          string A = @"{{nofootnotes}}";
          string A2 = @"{{Morefootnotes}}";
          
          string B = @"
'''Article''' words.
== section ==
words.
";
          string C = @"== References ==
";
          string D = @"== Notes ==
";
          string E = @"== Footnotes ==
";

          string F = @"'''Article''' words.
== section ==
{{nofootnotes}}
words.
";  
          string G = @"words";
        
          Assert.AreEqual(B + C + A + "\r\n" + G, MetaDataSorter.MoveMoreNoFootnotes(A + B + C + G));
          Assert.AreEqual(B + D + A + "\r\n" + G, MetaDataSorter.MoveMoreNoFootnotes(A + B + D + G));
          Assert.AreEqual(B + E + A + "\r\n" + G, MetaDataSorter.MoveMoreNoFootnotes(A + B + E + G));
          Assert.AreEqual(B + E + A + "\r\n", MetaDataSorter.MoveMoreNoFootnotes(A + B + E));
          Assert.AreEqual(B + E + A2 + "\r\n", MetaDataSorter.MoveMoreNoFootnotes(A2 + B + E));
        
          // not moved if outside zeroth section
          Assert.AreEqual(F + C + G, MetaDataSorter.MoveMoreNoFootnotes(F + C + G));
          Assert.AreEqual(F + D + G, MetaDataSorter.MoveMoreNoFootnotes(F + D + G));
          Assert.AreEqual(F + E + G, MetaDataSorter.MoveMoreNoFootnotes(F + E + G));
        }
コード例 #3
0
        public void RemoveStubs()
        {
            // shouldn't break anything
            string s = "==foo==\r\nbar<ref name=\"123\"/>{{boz}}";

            Assert.AreEqual("", MetaDataSorter.RemoveStubs(ref s));
            Assert.AreEqual("==foo==\r\nbar<ref name=\"123\"/>{{boz}}", s);

            // should remove stubs, but not section stubs
            s = "{{foo}}{{stub}}{{foo-stub}}bar{{sect-stub}}{{not a|stub}}";
            Assert.AreEqual("{{stub}}\r\n{{foo-stub}}\r\n", MetaDataSorter.RemoveStubs(ref s));
            Assert.AreEqual("{{foo}}bar{{sect-stub}}{{not a|stub}}", s);

            // handle stubs with extra parameters e.g. date=
            s = "{{foo}}{{stub}}{{foo-stub|date=May 2012}}bar{{sect-stub}}{{not a|stub}}";
            Assert.AreEqual("{{stub}}\r\n{{foo-stub|date=May 2012}}\r\n", MetaDataSorter.RemoveStubs(ref s));

            //shouldn't fail
            s = "";
            Assert.AreEqual("", MetaDataSorter.RemoveStubs(ref s));
            Assert.AreEqual("", s);
            s = "{{stub}}";
            Assert.AreEqual("{{stub}}\r\n", MetaDataSorter.RemoveStubs(ref s));
            Assert.AreEqual("", s);
        }
コード例 #4
0
        public void MoveMoreNoFootnotesTests()
        {
            const string a = @"{{nofootnotes}}", a2 = @"{{Morefootnotes}}", b = @"
'''Article''' words.
== section ==
words.
";
            const string c = @"== References ==
", d = @"== Notes ==
", e = @"== Footnotes ==
", f = @"'''Article''' words.
== section ==
{{nofootnotes}}
words.
";
            const string g = @"words";

            Assert.AreEqual(b + c + a + "\r\n" + g, MetaDataSorter.MoveTemplateToReferencesSection(a + b + c + g, WikiFunctions.WikiRegexes.MoreNoFootnotes, true));
            Assert.AreEqual(b + d + a + "\r\n" + g, MetaDataSorter.MoveTemplateToReferencesSection(a + b + d + g, WikiFunctions.WikiRegexes.MoreNoFootnotes, true));
            Assert.AreEqual(b + e + a + "\r\n" + g, MetaDataSorter.MoveTemplateToReferencesSection(a + b + e + g, WikiFunctions.WikiRegexes.MoreNoFootnotes, true));
            Assert.AreEqual(b + e + a + "\r\n", MetaDataSorter.MoveTemplateToReferencesSection(a + b + e, WikiFunctions.WikiRegexes.MoreNoFootnotes, true));
            Assert.AreEqual(b + e + a2 + "\r\n", MetaDataSorter.MoveTemplateToReferencesSection(a2 + b + e, WikiFunctions.WikiRegexes.MoreNoFootnotes, true));
            Assert.AreEqual(b + e + a2 + "\r\n", MetaDataSorter.MoveTemplateToReferencesSection(a2 + b + e, WikiFunctions.WikiRegexes.MoreNoFootnotes, false));

            // not moved if outside zeroth section
            Assert.AreEqual(f + c + g, MetaDataSorter.MoveTemplateToReferencesSection(f + c + g, WikiFunctions.WikiRegexes.MoreNoFootnotes, true));
            Assert.AreEqual(f + d + g, MetaDataSorter.MoveTemplateToReferencesSection(f + d + g, WikiFunctions.WikiRegexes.MoreNoFootnotes, true));
            Assert.AreEqual(f + e + g, MetaDataSorter.MoveTemplateToReferencesSection(f + e + g, WikiFunctions.WikiRegexes.MoreNoFootnotes, true));
        }
コード例 #5
0
        public void MoveIbidTests()
        {
            const string a = @"{{Ibid|date=May 2009}}", b = @"
'''Article''' words<ref>ibid</ref>.
== section ==
words.
", c = @"== References ==
", d = @"== Notes ==
", e = @"== Footnotes ==
", f = @"'''Article''' words.
== section ==
{{Ibid|date=May 2009}}
words.
";
            const string g = @"more words";

            Assert.AreEqual(b + c + a + "\r\n" + g, MetaDataSorter.MoveTemplateToReferencesSection(a + b + c + g, WikiFunctions.WikiRegexes.Ibid, true));
            Assert.AreEqual(b + d + a + "\r\n" + g, MetaDataSorter.MoveTemplateToReferencesSection(a + b + d + g, WikiFunctions.WikiRegexes.Ibid, true));
            Assert.AreEqual(b + e + a + "\r\n" + g, MetaDataSorter.MoveTemplateToReferencesSection(a + b + e + g, WikiFunctions.WikiRegexes.Ibid, true));
            Assert.AreEqual(b + e + a + "\r\n", MetaDataSorter.MoveTemplateToReferencesSection(a + b + e, WikiFunctions.WikiRegexes.Ibid, true));

            Assert.AreEqual(b + c + a + "\r\n" + g, MetaDataSorter.MoveTemplateToReferencesSection(a + b + c + g, WikiFunctions.WikiRegexes.Ibid, false));
            Assert.AreEqual(b + d + a + "\r\n" + g, MetaDataSorter.MoveTemplateToReferencesSection(a + b + d + g, WikiFunctions.WikiRegexes.Ibid, false));
            Assert.AreEqual(b + e + a + "\r\n" + g, MetaDataSorter.MoveTemplateToReferencesSection(a + b + e + g, WikiFunctions.WikiRegexes.Ibid));
            Assert.AreEqual(b + e + a + "\r\n", MetaDataSorter.MoveTemplateToReferencesSection(a + b + e, WikiFunctions.WikiRegexes.Ibid));

            // outside zeroth section – okay
            Assert.AreEqual(@"'''Article''' words.
== section ==

words.
" + c + a + "\r\n" + g, MetaDataSorter.MoveTemplateToReferencesSection(f + c + g, WikiFunctions.WikiRegexes.Ibid, false));
        }
コード例 #6
0
        public void MoveMoreNoFootnotesTests()
        {
            const string a  = @"{{nofootnotes}}";
            const string a2 = @"{{Morefootnotes}}";

            const string b = @"
'''Article''' words.
== section ==
words.
";
            const string c = @"== References ==
";
            const string d = @"== Notes ==
";
            const string e = @"== Footnotes ==
";

            const string f = @"'''Article''' words.
== section ==
{{nofootnotes}}
words.
";
            const string g = @"words";

            Assert.AreEqual(b + c + a + "\r\n" + g, MetaDataSorter.MoveMoreNoFootnotes(a + b + c + g));
            Assert.AreEqual(b + d + a + "\r\n" + g, MetaDataSorter.MoveMoreNoFootnotes(a + b + d + g));
            Assert.AreEqual(b + e + a + "\r\n" + g, MetaDataSorter.MoveMoreNoFootnotes(a + b + e + g));
            Assert.AreEqual(b + e + a + "\r\n", MetaDataSorter.MoveMoreNoFootnotes(a + b + e));
            Assert.AreEqual(b + e + a2 + "\r\n", MetaDataSorter.MoveMoreNoFootnotes(a2 + b + e));

            // not moved if outside zeroth section
            Assert.AreEqual(f + c + g, MetaDataSorter.MoveMoreNoFootnotes(f + c + g));
            Assert.AreEqual(f + d + g, MetaDataSorter.MoveMoreNoFootnotes(f + d + g));
            Assert.AreEqual(f + e + g, MetaDataSorter.MoveMoreNoFootnotes(f + e + g));
        }
コード例 #7
0
        public void MoveExternalLinksTests()
        {
            string a = @"'''article'''
== blah ==
words<ref>abc</ref>";
            string b = @"== external links ==
* [http://www.site.com a site]";
            string c = @"== References ==
{{reflist}}";
            string d = @"=== another section ===
blah";
            string e = @"[[Category:Foos]]";

            string f = @"{{some footer thing}}";

            string g = @"== another section ==
blah";
            string h = @"{{DEFAULTSORT:Foo, bar}}";

            Assert.AreEqual(a + "\r\n" + c + "\r\n" + b + "\r\n" + e, MetaDataSorter.MoveExternalLinks(a + "\r\n" + b + "\r\n" + c + "\r\n" + e));
            Assert.AreEqual(a + "\r\n" + c + "\r\n" + b + "\r\n" + h, MetaDataSorter.MoveExternalLinks(a + "\r\n" + b + "\r\n" + c + "\r\n" + h));
            Assert.AreEqual(a + "\r\n" + c + "\r\n" + b + "\r\n" + g, MetaDataSorter.MoveExternalLinks(a + "\r\n" + b + "\r\n" + c + "\r\n" + g));

            // no change if already correct
            Assert.AreEqual(a + "\r\n" + c + "\r\n" + b, MetaDataSorter.MoveExternalLinks(a + "\r\n" + c + "\r\n" + b));
            Assert.AreEqual(a + "\r\n" + c + "\r\n" + b + "\r\n" + g, MetaDataSorter.MoveExternalLinks(a + "\r\n" + c + "\r\n" + b + "\r\n" + g));

            // no change if end of references section is unclear
            Assert.AreEqual(a + "\r\n" + b + "\r\n" + c + "\r\n" + f, MetaDataSorter.MoveExternalLinks(a + "\r\n" + b + "\r\n" + c + "\r\n" + f));

            // only matching level two headings following references
            Assert.AreEqual(a + "\r\n" + b + "\r\n" + c + "\r\n" + d, MetaDataSorter.MoveExternalLinks(a + "\r\n" + b + "\r\n" + c + "\r\n" + d));

        }
コード例 #8
0
        public void MoveDablinksTests()
        {
            const string d = @"Fred is a doctor.
Fred has a dog.
[[Category:Dog owners]]
{{some template}}
", e0 = @"{{redirect|foo|bar}}";

            string e = @"{{otherpeople1|Fred the dancer|Fred Smith (dancer)}}";

            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            e = @"{{For|Fred the dancer|Fred Smith (dancer)}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(e + " " + d));

            e = @"{{redirect2|Fred the dancer|Fred Smith (dancer)}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            e = @"{{redirect2|Fred the {{dancer}}|Fred Smith (dancer)}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            e = @"{{redirect2|Fred the {{dancer}}|Fred Smith (dancer)}}
";
            Assert.AreEqual(e + d, MetaDataSorter.MoveDablinks(d + ":" + e), "colons before dablinks removed");

            // don't move dablinks in a section
            const string f = @"Article words
== heading ==
{{redirect2|Fred the dancer|Fred Smith (dancer)}}
words";

            Assert.AreEqual(f, MetaDataSorter.MoveDablinks(f));

            // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs/Archive_11#String_cannot_be_of_zero_length._Parameter_name:_oldValue_.2F_ArgumentException_in_MetaDataSorter.MoveDablinks
            Assert.AreEqual(@"[[Category:Confederate Navy officers|Captains]]", MetaDataSorter.MoveDablinks(@"[[Category:Confederate Navy officers|Captains]]"));

            const string g = @"Some words";
            const string h = @"==heading==
more words
[[Category:Foo]]";

            e = @"{{redirect2|Fred the {{dancer}}|Fred Smith (dancer)}}";

            Assert.AreEqual(e + "\r\n" + g + "\r\n" + h, MetaDataSorter.MoveDablinks(g + "\r\n" + e + "\r\n" + h));

            Assert.AreEqual(e + "\r\n" + e0 + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e + e0));
            Assert.AreEqual(e + "\r\n" + e0 + "\r\n\r\n" + d, MetaDataSorter.MoveDablinks(e + e0 + "\r\n\r\n" + d));

            // check spacing
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(e + "\r\n" + d));
            Assert.AreEqual(e + "\r\n" + e0 + "\r\n" + d, MetaDataSorter.MoveDablinks(e + "\r\n" + e0 + d));
            Assert.AreEqual(e + "\r\n" + e0 + "\r\n" + d, MetaDataSorter.MoveDablinks(e + "\r\n" + e0 + "\r\n" + d));
            Assert.AreEqual(e + "\r\n" + e0 + "\r\n\r\n" + d, MetaDataSorter.MoveDablinks(e + "\r\n" + e0 + "\r\n\r\n" + d));
            Assert.AreEqual(e + "\r\n" + e0 + "\r\n" + e0 + "\r\n\r\n" + d, MetaDataSorter.MoveDablinks(e + "\r\n" + e0 + e0 + "\r\n\r\n" + d));
        }
コード例 #9
0
        public void MovePersonDataTests()
        {
            const string a  = @"<!-- Metadata: see [[Wikipedia:Persondata]] -->
";
            string       b1 = @"{{Persondata
|NAME= Hodgson, Jane Elizabeth
|ALTERNATIVE NAMES=
|SHORT DESCRIPTION= [[Physician]], [[obstetrician]], [[gynecologist]]
|DATE OF BIRTH= 1915-1-23
|PLACE OF BIRTH= [[Crookston, Minnesota]]
|DATE OF DEATH= 2006-10-23
|PLACE OF DEATH= [[Rochester, Minnesota]]
}}";

            const string b2 = @"{{Persondata
|NAME= Hodgson, Jane Elizabeth
|ALTERNATIVE NAMES=
|SHORT DESCRIPTION= [[Physician]], [[obstetrician]], [[gynecologist]]
|DATE OF BIRTH= {{birth date|1915|1|23}}
|PLACE OF BIRTH= [[Crookston, Minnesota]]
|DATE OF DEATH= 2006-10-23
|PLACE OF DEATH= [[Rochester, Minnesota]]
}}";

            string c1 = a + b1;
            string c2 = a + b2;

            MetaDataSorter.RemovePersonData(ref c1);
            Assert.AreEqual(c1, "");
            MetaDataSorter.RemovePersonData(ref c2);
            Assert.AreEqual(c2, "");
            MetaDataSorter.RemovePersonData(ref b1);
            Assert.AreEqual(b1, "");

            const string d1 = @"{{Persondata<!-- Metadata: see [[Wikipedia:Persondata]] -->
|NAME= Becker, Gary
|ALTERNATIVE NAMES=
|SHORT DESCRIPTION= [[Economics|Economist]]
|DATE OF BIRTH= [[December 2]], [[1930]]
|PLACE OF BIRTH= [[Pottsville, Pennsylvania]]
|DATE OF DEATH=
|PLACE OF DEATH=
}}";
            const string d2 = @"{{Winners of the National Medal of Science|behav-social}}
";
            const string d3 = @"
[[Category:Members of the National Academy of Sciences]]";

            string e = d2 + d1 + d3;

            string f = MetaDataSorter.RemovePersonData(ref e);

            Assert.AreEqual(d1, f);
            Assert.AreEqual(e, d2 + d3);
        }
コード例 #10
0
        public void MoveDablinksCommentsTests()
        {
            const string d = @"Fred is a doctor.
Fred has a dog.
[[Category:Dog owners]]
{{some template}}
", e = @"<!-- {{otheruses}} this allows users with [[WP:POPUPS|popups]] to disambiguate links.-->";

            // don't pull dabs out of comments
            Assert.AreEqual(d + e, MetaDataSorter.MoveDablinks(d + e));
        }
コード例 #11
0
        public void MoveMaintenanceTagsTests()
        {
            const string d = @"Fred is a doctor.
Fred has a dog.
[[Category:Dog owners]]
{{some template}}
";

            string e = @"{{Orphan|date=May 2008}}";

            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveMaintenanceTags(d + e));

            e = @"{{orphan|date=May 2008}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveMaintenanceTags(d + e));

            e = @"{{cleanup|date=May 2008}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveMaintenanceTags(d + e), "template moved when not a section one");

            e = @"{{cleanup|section|date=May 2008}}";
            Assert.AreEqual(d + e, MetaDataSorter.MoveMaintenanceTags(d + e), "section templates not moved");

            // don't move above other maintenance templates
            string f = @"{{cleanup|date=June 2009}}
" + e + d;

            Assert.AreEqual(f, MetaDataSorter.MoveMaintenanceTags(f));

            string g = @"{{BLP unsourced|date=August 2009|bot=yes}}
{{Orphan|date=February 2008}}
'''Charles M. McKim'''";

            Assert.AreEqual(g, MetaDataSorter.MoveMaintenanceTags(g));

            // do move above infoboxes
            string h1 = @"{{Infobox foo| sdajklfsdjk | dDJfsdjkl }}", h2 = @"{{Orphan|date=February 2008}}", h3 = @"'''Charles M. McKim'''";

            Assert.AreEqual(h2 + "\r\n" + h1 + "\r\n" + h3, MetaDataSorter.MoveMaintenanceTags(h2 + "\r\n" + h1 + "\r\n" + h3));

            string i1 = @"{{cleanup|date=June 2009}}";

            e = @"{{orphan|date=May 2008}}";
            // move when tags not all at top
            Assert.AreEqual(e + "\r\n" + i1 + "\r\nfoo\r\n", MetaDataSorter.MoveMaintenanceTags(e + "\r\nfoo\r\n" + i1));

            const string CommentedOut = @"<!---sufficient-?---{{Cleanup|date=January 2010}}--{{Wikify|date=January 2010}}---?--->";

            Assert.AreEqual(CommentedOut, MetaDataSorter.MoveMaintenanceTags(CommentedOut), "no change to commented out tags");

            const string NewMultipleIssues = @"{{multiple issues|{{Cleanup|date=January 2010}}}}";

            Assert.AreEqual(NewMultipleIssues, MetaDataSorter.MoveMaintenanceTags(NewMultipleIssues), "don't pull tags from new-style {{multiple issues}}");
        }
コード例 #12
0
        public void MoveOrphanTagsTests()
        {
            const string d = @"Fred is a doctor.
Fred has a dog.
[[Category:Dog owners]]
{{some template}}
";

            string e = @"{{Orphan|date=May 2008}}";

            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveOrphanTags(d + e));

            e = @"{{orphan|date=May 2008}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveOrphanTags(d + e));
        }
コード例 #13
0
        public void MoveMaintenanceTagsTests()
        {
            const string d = @"Fred is a doctor.
Fred has a dog.
[[Category:Dog owners]]
{{some template}}
";

            string e = @"{{Orphan|date=May 2008}}";

            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveMaintenanceTags(d + e));

            e = @"{{orphan|date=May 2008}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveMaintenanceTags(d + e));

            e = @"{{cleanup|date=May 2008}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveMaintenanceTags(d + e), "template moved when not a section one");

            e = @"{{cleanup|section|date=May 2008}}";
            Assert.AreEqual(d + e, MetaDataSorter.MoveMaintenanceTags(d + e), "section templates not moved");

            // don't move above other maintenance templates
            string f = @"{{cleanup|date=June 2009}}
" + e + d;

            Assert.AreEqual(f, MetaDataSorter.MoveMaintenanceTags(f));

            string g = @"{{BLP unsourced|date=August 2009|bot=yes}}
{{Orphan|date=February 2008}}
'''Charles M. McKim'''";

            Assert.AreEqual(g, MetaDataSorter.MoveMaintenanceTags(g));

            // do move above infoboxes
            string h1 = @"{{Infobox foo| sdajklfsdjk | dDJfsdjkl }}", h2 = @"{{Orphan|date=February 2008}}", h3 = @"'''Charles M. McKim'''";

            Assert.AreEqual(h2 + "\r\n" + h1 + "\r\n" + h3, MetaDataSorter.MoveMaintenanceTags(h2 + "\r\n" + h1 + "\r\n" + h3));

            string i1 = @"{{cleanup|date=June 2009}}";

            e = @"{{orphan|date=May 2008}}";
            // move when tags not all at top
            Assert.AreEqual(e + "\r\n" + i1 + "\r\nfoo\r\n", MetaDataSorter.MoveMaintenanceTags(e + "\r\nfoo\r\n" + i1));
        }
コード例 #14
0
        public void RemoveDisambig()
        {
            const string dab = @"{{dab}}", foo = @"foo";

            string a = dab + "\r\n" + foo;

            Assert.AreEqual(dab, MetaDataSorter.RemoveDisambig(ref a));
            Assert.AreEqual(a, "\r\n" + foo);

            // no dabs to take out – no change
            a = foo;
            Assert.AreEqual("", MetaDataSorter.RemoveDisambig(ref a));
            Assert.AreEqual(a, foo);

            // don't pull out of comments
            a = @"<!--" + dab + @"-->" + "\r\n" + foo;
            Assert.AreEqual("", MetaDataSorter.RemoveDisambig(ref a));
            Assert.AreEqual(a, @"<!--" + dab + @"-->" + "\r\n" + foo);
        }
コード例 #15
0
        public void MoveSeeAlso()
        {
            const string a = @"'''article'''
== blah ==
words<ref>abc</ref>";

            const string b = @"== see also ==
* [http://www.site.com a site]";

            const string c = @"== References ==
{{reflist}}";
            const string d = @"== another section ==
blah";

            Assert.AreEqual(a + "\r\n" + b + "\r\n" + c + "\r\n" + d, MetaDataSorter.MoveSeeAlso(a + "\r\n" + c + "\r\n" + b + "\r\n" + d));

            // no change when already correct
            Assert.AreEqual(a + "\r\n" + b + "\r\n" + c + "\r\n" + d, MetaDataSorter.MoveSeeAlso(a + "\r\n" + b + "\r\n" + c + "\r\n" + d));
        }
コード例 #16
0
        string RemoveSection(string ArticleText)
        {
            //string text = WikiRegexes.Comments.Replace(ArticleText, "");

            string[] sections = Tools.SplitToSections(ArticleText);

            bool lastSection = false;

            for (int i = 0; i < sections.Length; i++)
            {
                if (ExternalLinksSectionRegex.IsMatch(sections[i]))
                {
                    lastSection = i == sections.Length - 1;
                    if (WikiRegexes.ExternalLinks.IsMatch(sections[i]))
                    {
                        return(ArticleText);
                    }

                    string el = ExternalLinksSectionRegex.Replace(sections[i], "").Trim();

                    if (lastSection)
                    {
                        parser.Sorter.removeCats(ref el, "");
                        parser.Sorter.interwikis(ref el);
                        MetaDataSorter.removeDisambig(ref ArticleText);
                        MetaDataSorter.removePersonData(ref ArticleText);
                        MetaDataSorter.removeStubs(ref ArticleText);
                    }
                    el = Parsers.RemoveAllWhiteSpace(ArticleText).Trim();

                    if (el.Length == 0)
                    {
                        return(ExternalLinksSectionRegex.Replace(ArticleText, ""));
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(ArticleText);
        }
コード例 #17
0
        public void MovePortalTemplatesTestsDuplicates()
        {
            // remove duplicate portals
            Assert.AreEqual(@"text here
text here2
== see also ==
{{Portal|Football}}
some words", MetaDataSorter.MovePortalTemplates(@"text here
{{Portal|Football}}
{{Portal|Football}}
text here2
== see also ==
some words"));

            Assert.AreEqual(@"text here
text here2
== see also ==
{{Portal|Football}}
some words
==other==
", MetaDataSorter.MovePortalTemplates(@"text here
{{Portal|Football}}
text here2
== see also ==
some words
==other==
{{Portal|Football}}"));

            Assert.AreEqual(@"text here
text here2
== see also ==
{{Portal|Football}}
some words
==other==
", MetaDataSorter.MovePortalTemplates(@"text here
text here2
== see also ==
{{Portal|Football}}
some words
==other==
{{Portal|Football}}"));
        }
コード例 #18
0
        public void MoveDablinksTests()
        {
            const string d = @"Fred is a doctor.
Fred has a dog.
[[Category:Dog owners]]
{{some template}}
";

            string e = @"{{otherpeople1|Fred the dancer|Fred Smith (dancer)}}";

            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            e = @"{{For|Fred the dancer|Fred Smith (dancer)}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            e = @"{{redirect2|Fred the dancer|Fred Smith (dancer)}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            e = @"{{redirect2|Fred the {{dancer}}|Fred Smith (dancer)}}";
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(d + e));

            // check no change when already in correct position
            Assert.AreEqual(e + "\r\n" + d, MetaDataSorter.MoveDablinks(e + "\r\n" + d));

            // don't move dablinks in a section
            string f = @"Article words
== heading ==
{{redirect2|Fred the dancer|Fred Smith (dancer)}}
words";

            Assert.AreEqual(f, MetaDataSorter.MoveDablinks(f));

            // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs#String_cannot_be_of_zero_length._Parameter_name:_oldValue
            Assert.AreEqual(@"[[Category:Confederate Navy officers|Captains]]", MetaDataSorter.MoveDablinks(@"[[Category:Confederate Navy officers|Captains]]"));

            string g = @"Some words";
            string h = @"==heading==
more words
[[Category:Foo]]";

            Assert.AreEqual(e + "\r\n" + g + "\r\n\r\n" + h, MetaDataSorter.MoveDablinks(g + "\r\n" + e + "\r\n" + h));
        }
コード例 #19
0
        public void RemoveStubs()
        {
            // shouldn't break anything
            string s = "==foo==\r\nbar<ref name=\"123\"/>{{boz}}";
            Assert.AreEqual("", MetaDataSorter.RemoveStubs(ref s));
            Assert.AreEqual("==foo==\r\nbar<ref name=\"123\"/>{{boz}}", s);

            // should remove stubs, but not section stubs
            s = "{{foo}}{{stub}}{{foo-stub}}bar{{sect-stub}}{{not-a-stub|123}}{{not a|stub}}";
            Assert.AreEqual("{{stub}}\r\n{{foo-stub}}\r\n", MetaDataSorter.RemoveStubs(ref s));
            Assert.AreEqual("{{foo}}bar{{sect-stub}}{{not-a-stub|123}}{{not a|stub}}", s);

            //shouldn't fail
            s = "";
            Assert.AreEqual("", MetaDataSorter.RemoveStubs(ref s));
            Assert.AreEqual("", s);
            s = "{{stub}}";
            Assert.AreEqual("{{stub}}\r\n", MetaDataSorter.RemoveStubs(ref s));
            Assert.AreEqual("", s);
        }
コード例 #20
0
        public void MoveDablinksCommentsTests()
        {
            const string d = @"Fred is a doctor.
Fred has a dog.
[[Category:Dog owners]]
{{some template}}
", e = @"<!-- {{otheruses}} this allows users with [[WP:POPUPS|popups]] to disambiguate links.-->";

            // don't pull dabs out of comments
            Assert.AreEqual(d + e, MetaDataSorter.MoveDablinks(d + e));

            const string f = @"{{for|the book by René Descartes|The World (Descartes)}}
<!--
Might eventually be relevant on a disambig page?  But these are a redirect and a not direct reference, so they're pretty irrelevant for now.
{{For|the song by the [[Thievery Corporation]]|Le Monde (song)}}
{{For|the drum & bass dj [[Lemon D]]| Lemon D}}
-->";

            Assert.AreEqual(f, MetaDataSorter.MoveDablinks(f));
        }
コード例 #21
0
        public void MoveSisterLinksTest()
        {
            const string WiktInExtLinks = @"text here
text here2
== External links ==
{{wiktionary}}
* Fred";

            Assert.AreEqual(@"text here
text here2
== External links ==
{{wiktionary}}
* Fred
== other ==
x", MetaDataSorter.MoveSisterlinks(@"text here
{{wiktionary}}
text here2
== External links ==
* Fred
== other ==
x"), "another section at end");

            Assert.AreEqual(WiktInExtLinks, MetaDataSorter.MoveSisterlinks(@"text here
{{wiktionary}}
text here2
== External links ==
* Fred"), "ext links is last section");

            Assert.AreEqual(WiktInExtLinks, MetaDataSorter.MoveSisterlinks(WiktInExtLinks), "wikt already in ext links");
            const string CommentedOut = @"text here
<!--{{wiktionary}}-->
text here2
== External links ==
* Fred
== other ==
x";

            Assert.AreEqual(CommentedOut, MetaDataSorter.MoveSisterlinks(CommentedOut), "no change if commented out");
        }
コード例 #22
0
        public void MovePortalTemplatesTests()
        {
         Assert.AreEqual(@"text here
text here2
== see also ==
{{Portal|Football}}
some words", MetaDataSorter.MovePortalTemplates(@"text here
{{Portal|Football}}
text here2
== see also ==
some words"));

         Assert.AreEqual(@"text here
text here2
== see also ==
{{Portal|Sport}}
{{Portal|Football}}
some words", MetaDataSorter.MovePortalTemplates(@"text here
{{Portal|Football}}
{{Portal|Sport}}
text here2
== see also ==
some words"));

          Assert.AreEqual(@"text here
text here2
== see also ==
{{Portal|Football}}
some words", MetaDataSorter.MovePortalTemplates(@"{{Portal|Football}}
text here
text here2
== see also ==
some words"));

            Assert.AreEqual(@"text here
text here2
== see also==
{{Portal|abc}}
* Fred", MetaDataSorter.MovePortalTemplates(@"text here
{{Portal|abc}}
text here2
== see also==
* Fred"));

            Assert.AreEqual(@"text here
text here2
== see also ==
{{Portal|Football}}
* Fred
== hello ==
some words", MetaDataSorter.MovePortalTemplates(@"text here
{{Portal|Football}}
text here2
== see also ==
* Fred
== hello ==
some words"));

            Assert.AreEqual(@"text here
text here2
== see also ==
{{Portal|Football}}
* Fred
=== hello ===
some words", MetaDataSorter.MovePortalTemplates(@"text here
{{Portal|Football}}
text here2
== see also ==
* Fred
=== hello ===
some words"));

            // if portal is already in 'see also', don't move it
            Assert.AreEqual(@"text here
text here2
== see also ==
{{Portal|Football}}
some words", MetaDataSorter.MovePortalTemplates(@"text here
text here2
== see also ==
{{Portal|Football}}
some words"));

            Assert.AreEqual(@"text here
text here2
== see also ==
* Fred
{{Portal|Football}}
some words", MetaDataSorter.MovePortalTemplates(@"text here
text here2
== see also ==
* Fred
{{Portal|Football}}
some words"));

            Assert.AreEqual(@"text here
text here2
== see also ==
* Fred
=== portals ===
{{Portal|Football}}
some words", MetaDataSorter.MovePortalTemplates(@"text here
text here2
== see also ==
* Fred
=== portals ===
{{Portal|Football}}
some words"));
        }