|
| 1 | +using Flow.Launcher.Plugin.SharedCommands; |
| 2 | +using NUnit.Framework; |
| 3 | + |
| 4 | +namespace Flow.Launcher.Test |
| 5 | +{ |
| 6 | + [TestFixture] |
| 7 | + |
| 8 | + public class FilesFoldersTest |
| 9 | + { |
| 10 | + // Testcases from https://stackoverflow.com/a/31941905/20703207 |
| 11 | + // Disk |
| 12 | + [TestCase(@"c:", @"c:\foo", true)] |
| 13 | + [TestCase(@"c:\", @"c:\foo", true)] |
| 14 | + // Slash |
| 15 | + [TestCase(@"c:\foo\bar\", @"c:\foo\", false)] |
| 16 | + [TestCase(@"c:\foo\bar", @"c:\foo\", false)] |
| 17 | + [TestCase(@"c:\foo", @"c:\foo\bar", true)] |
| 18 | + [TestCase(@"c:\foo\", @"c:\foo\bar", true)] |
| 19 | + // File |
| 20 | + [TestCase(@"c:\foo", @"c:\foo\a.txt", true)] |
| 21 | + [TestCase(@"c:\foo", @"c:/foo/a.txt", true)] |
| 22 | + [TestCase(@"c:\FOO\a.txt", @"c:\foo", false)] |
| 23 | + [TestCase(@"c:\foo\a.txt", @"c:\foo\", false)] |
| 24 | + [TestCase(@"c:\foobar\a.txt", @"c:\foo", false)] |
| 25 | + [TestCase(@"c:\foobar\a.txt", @"c:\foo\", false)] |
| 26 | + [TestCase(@"c:\foo\", @"c:\foo.txt", false)] |
| 27 | + // Prefix |
| 28 | + [TestCase(@"c:\foo", @"c:\foobar", false)] |
| 29 | + [TestCase(@"C:\Program", @"C:\Program Files\", false)] |
| 30 | + [TestCase(@"c:\foobar", @"c:\foo\a.txt", false)] |
| 31 | + [TestCase(@"c:\foobar\", @"c:\foo\a.txt", false)] |
| 32 | + // Edge case |
| 33 | + [TestCase(@"c:\foo", @"c:\foo\..\bar\baz", false)] |
| 34 | + [TestCase(@"c:\bar", @"c:\foo\..\bar\baz", true)] |
| 35 | + [TestCase(@"c:\barr", @"c:\foo\..\bar\baz", false)] |
| 36 | + // Equality |
| 37 | + [TestCase(@"c:\foo", @"c:\foo", false)] |
| 38 | + [TestCase(@"c:\foo\", @"c:\foo", false)] |
| 39 | + [TestCase(@"c:\foo", @"c:\foo\", false)] |
| 40 | + public void TestPathContains(string parentPath, string path, bool expectedResult) |
| 41 | + { |
| 42 | + Assert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path)); |
| 43 | + } |
| 44 | + |
| 45 | + [TestCase(@"c:\foo", @"c:\foo", true)] |
| 46 | + [TestCase(@"c:\foo\", @"c:\foo", true)] |
| 47 | + [TestCase(@"c:\foo\", @"c:\foo", true)] |
| 48 | + public void TestPathContainsWhenEqual(string parentPath, string path, bool expectedResult) |
| 49 | + { |
| 50 | + Assert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path, true)); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments