Resharper Spell Checker / ReSpeller.BasicTests / SpellEngine / TextSplitterTest.cs

using System.Collections.Generic;
using NUnit.Framework;
using ReSpeller.SpellEngine;

namespace ReSpeller.BasicTests.SpellEngine
{
  [TestFixture]
  internal class TextSplitterTest
  {
    private static readonly object[] Cases =
      {
        new object[] {"ident", new List<TextPart> {new TextPart("ident", TextPartType.Word, 0, 4)}},
        new object[]
          {
            "newIdent", new List<TextPart>
                          {
                            new TextPart("new", TextPartType.Word, 0, 2),
                            new TextPart("Ident", TextPartType.Word, 3, 7)
                          }
          },
        new object[]
          {
            "new123Ident", new List<TextPart>
                             {
                               new TextPart("new", TextPartType.Word, 0, 2),
                               new TextPart("123", TextPartType.NotAWord, 3, 5),
                               new TextPart("Ident", TextPartType.Word, 6, 10)
                             }
          },
        new object[]
          {
            "MyIdent", new List<TextPart>
                         {
                           new TextPart("My", TextPartType.Word, 0, 1),
                           new TextPart("Ident", TextPartType.Word, 2, 6)
                         }
          },
        new object[]
          {
            "My123", new List<TextPart>
                       {
                         new TextPart("My", TextPartType.Word, 0, 1),
                         new TextPart("123", TextPartType.NotAWord, 2, 4)
                       }
          },
        new object[] {"Ident", new List<TextPart> {new TextPart("Ident", TextPartType.Word, 0, 4)}},
        new object[]
          {
            "my_ident", new List<TextPart>
                          {
                            new TextPart("my", TextPartType.Word, 0, 1),
                            new TextPart("_", TextPartType.NotAWord, 2, 2),
                            new TextPart("ident", TextPartType.Word, 3, 7)
                          }
          },
        new object[]
          {
            "my_Ident", new List<TextPart>
                          {
                            new TextPart("my", TextPartType.Word, 0, 1),
                            new TextPart("_", TextPartType.NotAWord, 2, 2),
                            new TextPart("Ident", TextPartType.Word, 3, 7)
                          }
          },
        new object[]
          {
            "CAPITAL_ONLY", new List<TextPart>
                              {
                                new TextPart("CAPITAL", TextPartType.Word, 0, 6),
                                new TextPart("_", TextPartType.NotAWord, 7, 7),
                                new TextPart("ONLY", TextPartType.Word, 8, 11)
                              }
          },
        new object[]
          {
            "CAPITAL_andNotONLY", new List<TextPart>
                                    {
                                      new TextPart("CAPITAL", TextPartType.Word, 0, 6),
                                      new TextPart("_", TextPartType.NotAWord, 7, 7),
                                      new TextPart("and", TextPartType.Word, 8, 10),
                                      new TextPart("Not", TextPartType.Word, 11, 13),
                                      new TextPart("ONLY", TextPartType.Word, 14, 17)
                                    }
          },
        new object[]
          {
            "FUCKText", new List<TextPart>
                          {
                            new TextPart("FUCK", TextPartType.Word, 0, 3),
                            new TextPart("Text", TextPartType.Word, 4, 7)
                          }
          },
        new object[]
          {
            "andFUCKText", new List<TextPart>
                             {
                               new TextPart("and", TextPartType.Word, 0, 2),
                               new TextPart("FUCK", TextPartType.Word, 3, 6),
                               new TextPart("Text", TextPartType.Word, 7, 10)
                             }
          },
        new object[]
          {
            "some Text", new List<TextPart>
                           {
                             new TextPart("some", TextPartType.Word, 0, 3),
                             new TextPart(" ", TextPartType.NotAWord, 4, 4),
                             new TextPart("Text", TextPartType.Word, 5, 8)
                           }
          },
        new object[]
          {
            "he won't do", new List<TextPart>
                             {
                               new TextPart("he", TextPartType.Word, 0, 1),
                               new TextPart(" ", TextPartType.NotAWord, 2, 2),
                               new TextPart("won't", TextPartType.Word, 3, 7),
                               new TextPart(" ", TextPartType.NotAWord, 8, 8),
                               new TextPart("do", TextPartType.Word, 9, 10)
                             }
          },
        new object[]
          {
            "he won'", new List<TextPart>
                         {
                           new TextPart("he", TextPartType.Word, 0, 1),
                           new TextPart(" ", TextPartType.NotAWord, 2, 2),
                           new TextPart("won", TextPartType.Word, 3, 5),
                           new TextPart("'", TextPartType.NotAWord, 6, 6)
                         }
          },
        new object[]
          {
            "he 'won", new List<TextPart>
                         {
                           new TextPart("he", TextPartType.Word, 0, 1),
                           new TextPart(" '", TextPartType.NotAWord, 2, 3),
                           new TextPart("won", TextPartType.Word, 4, 6)
                         }
          }
      };

    [Test, TestCaseSource("Cases")]
    public void TestTextSplitter(string text, List<TextPart> result)
    {
      List<TextPart> actual = TextSplitter.Split(text);
      Assert.AreEqual(result, actual);
    }
  }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.