[JEDI.NET-commits] nunit/source Jedi.IO.BaseNUnit.pas,NONE,1.1 Jedi.IO.PathNunit.pas,NONE,1.1 Jedi.S
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2004-12-05 14:44:46
|
Update of /cvsroot/jedidotnet/nunit/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24318/nunit/source Added Files: Jedi.IO.BaseNUnit.pas Jedi.IO.PathNunit.pas Jedi.System.AttributesNUnit.pas Jedi.System.StringsNUnit.pas Log Message: Moved test sets; adapted to Delphi 2005 --- NEW FILE: Jedi.System.StringsNUnit.pas --- unit Jedi.System.StringsNUnit; interface uses Jedi.System, NUnit.Framework; type [TestFixture] TabSet = class strict protected TabSet1: StringUtils.TabSet; TabSet2: StringUtils.TabSet; TabSet3: StringUtils.TabSet; public [TestFixtureSetUp] procedure Init; [Test] procedure SimpleTabulation; [Test] procedure SpecifiedTabsWithAutoDefault; [Test] procedure SpecifiedTabsWithDefault; [Test] procedure CloneAndEqual; [Test] procedure RemovingTabs; [Test] procedure AddingTabs; [Test] procedure ConvertToString; end; [TestFixture] QuotedStrings = class strict protected const sSimpleTest = 'This is a simple test string.'; const sSimpleTestQuoted = '''This is a simple test string.'''; const sSimpleTestWithQuotes = 'This is a ''simple'' test string.'; const sSimpleTestWithQuotesQuoted = '''This is a ''''simple'''' test string.'''; const sSimpleTestWithOtherQuotes = 'This is a "simple" test string.'; const sSimpleTestWithOtherQuotesQuoted = '''This is a "simple" test string.'''; const sSimpleTestWithGarbageQuoted = '''This is a simple test string.'' With garbage.'; const sSimpleTestMissingEndQuote = '''This is a simple test string.'; const sComplexTest = 'Assuming single quotation ('') or double quotation (") this string '+ 'should always result in the roundtrip, regardless of actual used '+ 'quotation charachter. Scary combinations: ''''abc'''' and ""def""'; const sComplexTestQuoted = '''Assuming single quotation ('''') or double quotation (") this string '+ 'should always result in the roundtrip, regardless of actual used ' + 'quotation charachter. Scary combinations: ''''''''abc'''''''' and '+ '""def""'''; const sComplexTestAlternateQuoted = '"Assuming single quotation ('') or double quotation ("") this string '+ 'should always result in the roundtrip, regardless of actual used ' + 'quotation charachter. Scary combinations: ''''abc'''' and """"def"""""'; public [Test] procedure QuoteComplexString; [Test] procedure QuoteComplexStringWithAlternateQuoting; [Test] procedure QuoteSimpleString; [Test] procedure QuoteStringWithQuotes; [Test] procedure QuoteStringWithOtherQuotes; [Test] procedure RoundtripSimpleString; [Test] procedure RoundtripStringWithQuotes; [Test] procedure RoundtripStringWithOtherQuotes; [Test] procedure RoundtripComplexString; [Test] procedure RoundtripComplexStringWithAlternateQuoting; [ExpectedException(TypeOf(FormatException), 'String ends in garbage.')] [Test] procedure DequoteStringWithGarbage; [ExpectedException(TypeOf(FormatException), 'End quote missing.')] [Test] procedure DequoteStringWithoutEndQuote; [Test] procedure DequoteStringWithAllowedGarbage; [Test] procedure DequoteStringAllowedMissingEndQuote; [Test] procedure DequoteStringCheckGarbage; [Test] procedure DequoteStringCheckEndQuote; [Test] procedure DequoteNonQuotedString; end; [TestFixture] Substrings = class strict protected const sDelimTest = '|Abc(def){ghi}.jkl;mno=(pqr){stu}.vwx;yz|'; const sDelimTestBeforeParenthesis = '|Abc'; const sDelimTestBeforeBrace = '|Abc(def)'; const sDelimTestBeforeDot = '|Abc(def){ghi}.'; const sDelimTestBeforeSemiColon = '|Abc(def){ghi}.jkl'; const sDelimTestBeforeEquals = '|Abc(def){ghi}.jkl;mno'; const sDelimTestBeforeLastEquals = '|Abc(def){ghi}.jkl;mno'; const sDelimTestBeforeLastParenthesis = '|Abc(def){ghi}.jkl;mno='; const sDelimTestBeforeLastBrace = '|Abc(def){ghi}.jkl;mno=(pqr)'; const sDelimTestBeforeLastDot = '|Abc(def){ghi}.jkl;mno=(pqr){stu}'; const sDelimTestBeforeLastSemiColon = '|Abc(def){ghi}.jkl;mno=(pqr){stu}.vwx'; const sDelimTestBeforeLastPipe = '|Abc(def){ghi}.jkl;mno=(pqr){stu}.vwx;yz'; const sDelimTestAfterFirstPipe = 'Abc(def){ghi}.jkl;mno=(pqr){stu}.vwx;yz|'; const sDelimTestAfterFirstParenthesis = 'def){ghi}.jkl;mno=(pqr){stu}.vwx;yz|'; const sDelimTestAfterFirstBrace = 'ghi}.jkl;mno=(pqr){stu}.vwx;yz|'; const sDelimTestAfterFirstDot = 'jkl;mno=(pqr){stu}.vwx;yz|'; const sDelimTestAfterFirstSemiColon = 'mno=(pqr){stu}.vwx;yz|'; const sDelimTestAfterFirstEquals = '(pqr){stu}.vwx;yz|'; const sDelimTestAfterEquals = '(pqr){stu}.vwx;yz|'; const sDelimTestAfterParenthesis = 'pqr){stu}.vwx;yz|'; const sDelimTestAfterBrace = 'stu}.vwx;yz|'; const sDelimTestAfterDot = 'vwx;yz|'; const sDelimTestAfterSemiColon = 'yz|'; const sSliceTest = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; public [Test] procedure AfterSingleDelimiter; [Test] procedure AfterMultipleDelimiters; [Test] procedure AfterLastSingleDelimiter; [Test] procedure AfterLastMultipleDelimiters; [Test] procedure BeforeSingleDelimiter; [Test] procedure BeforeMultipleDelimiters; [Test] procedure BeforeLastSingleDelimiter; [Test] procedure BeforeLastMultipleDelimiters; [Test] procedure Left; [Test] procedure Mid; [Test] procedure Right; end; [TestFixture] Manipulations = class strict protected const sTabTest1 = 'Abc'#9'Def Ghi'#9'Jkl'#9#9'Mno'#9#9#9'Pqr'; const sTabTest2 = #9'Abc'#9'Def Ghi'#9'Jkl'#9#9'Mno'#9#9#9'Pqr'; // 1 2 3 4 5 6 7 // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 const sTabTest1Output1 = 'Abc Def Ghi Jkl Mno Pqr'; const sTabTest1Output2 = 'Abc Def Ghi Jkl Mno Pqr'; const sTabTest1Output3 = 'Abc Def Ghi Jkl Mno Pqr'; const sTabTest2Output1 = ' Abc Def Ghi Jkl Mno Pqr'; const sTabTest2Output2 = ' Abc Def Ghi Jkl Mno Pqr'; const sTabTest2Output3 = ' Abc Def Ghi Jkl Mno Pqr'; strict protected const sTest1 = '***abc***def***ghi***'; const sTest1Output = '*abc*def*ghi*'; strict protected const sRepeatInput = 'ab(cd)ef'; const sRepeatOutput0 = ''; const sRepeatOutput1 = 'ab(cd)ef'; const sRepeatOutput10 = 'ab(cd)efab(cd)efab(cd)efab(cd)efab(cd)efab(cd)efab(cd)efab(cd)efab(cd)efab(cd)ef'; public [Test] procedure ExpandTabs; [Test] procedure RemoveDuplicates; [Test] procedure &Repeat; end; implementation {$REGION 'TabSet'} procedure TabSet.ConvertToString; begin Assert.AreEqual('[]+2', TabSet1.ToString, 'TabSet1.ToString'); Assert.AreEqual('[15,20,40,44]+4 (automatic)', TabSet2.ToString, 'TabSet2.ToString'); Assert.AreEqual('[15,20,40,44]+2', TabSet3.ToString, 'TabSet3.ToString'); Assert.AreEqual('[]+2 (automatic)', StringUtils.TabSet.Create.ToString, 'StringUtils.TabSet.Create.ToString'); end; procedure TabSet.Init; begin TabSet1 := StringUtils.TabSet.Create(2); TabSet2 := StringUtils.TabSet.Create([15, 20, 40, 44]); TabSet3 := StringUtils.TabSet.Create([15, 20, 40, 44], 2); end; procedure TabSet.SimpleTabulation; begin // TabSet1 should always tabulate to even positions Assert.AreEqual(TabSet1.TabFrom(1), 2); Assert.AreEqual(TabSet1.TabFrom(2), 4); Assert.AreEqual(TabSet1.TabFrom(3), 4); Assert.AreEqual(TabSet1.TabFrom(51), 52); Assert.AreEqual(TabSet1.TabFrom(52), 54); end; procedure TabSet.SpecifiedTabsWithAutoDefault; var i: Integer; begin // TabSet2 will tabulate to 15, 20, 40 and 44. Beyond that it will tabulate to a multiple of 4 (44-40) for i := 0 to 14 do Assert.AreEqual(TabSet2.TabFrom(i), 15, 'Tabulate from {0}', [i]); for i := 15 to 19 do Assert.AreEqual(TabSet2.TabFrom(i), 20, 'Tabulate from {0}', [i]); for i := 20 to 39 do Assert.AreEqual(TabSet2.TabFrom(i), 40, 'Tabulate from {0}', [i]); for i := 40 to 43 do Assert.AreEqual(TabSet2.TabFrom(i), 44, 'Tabulate from {0}', [i]); for i := 44 to 47 do Assert.AreEqual(TabSet2.TabFrom(i), 48, 'Tabulate from {0}', [i]); for i := 48 to 51 do Assert.AreEqual(TabSet2.TabFrom(i), 52, 'Tabulate from {0}', [i]); end; procedure TabSet.SpecifiedTabsWithDefault; var i: Integer; begin // TabSet2 will tabulate to 15, 20, 40 and 44. Beyond that it will tabulate to a multiple of 2 for i := 0 to 14 do Assert.AreEqual(TabSet3.TabFrom(i), 15, 'Tabulate from {0}', [i]); for i := 15 to 19 do Assert.AreEqual(TabSet3.TabFrom(i), 20, 'Tabulate from {0}', [i]); for i := 20 to 39 do Assert.AreEqual(TabSet3.TabFrom(i), 40, 'Tabulate from {0}', [i]); for i := 40 to 43 do Assert.AreEqual(TabSet3.TabFrom(i), 44, 'Tabulate from {0}', [i]); for i := 44 to 45 do Assert.AreEqual(TabSet3.TabFrom(i), 46, 'Tabulate from {0}', [i]); for i := 46 to 47 do Assert.AreEqual(TabSet3.TabFrom(i), 48, 'Tabulate from {0}', [i]); for i := 48 to 49 do Assert.AreEqual(TabSet3.TabFrom(i), 50, 'Tabulate from {0}', [i]); for i := 50 to 51 do Assert.AreEqual(TabSet3.TabFrom(i), 52, 'Tabulate from {0}', [i]); end; procedure TabSet.CloneAndEqual; var tempSet: StringUtils.TabSet; begin tempSet := StringUtils.TabSet(TabSet1.Clone); Assert.AreNotSame(TabSet1, tempSet); Assert.AreEqual(TabSet1, tempSet, 'Cloned'); tempSet.Add(2); Assert.AreEqual(TabSet1, tempSet, 'TabPos=[2], DefaultWidth=2'); tempSet.DefaultWidth := 0; Assert.AreEqual(TabSet1, tempSet, 'TabPos=[2], DefaultWidth=0 (automatic)'); tempSet.Add(4); Assert.AreEqual(TabSet1, tempSet, 'TabPos=[2,4], DefaultWidth=0 (automatic)'); tempSet.Clear; Assert.AreEqual(TabSet1, tempSet, 'TabPos=[], DefaultWidth=0 (automatic)'); end; procedure TabSet.RemovingTabs; var tempSet: StringUtils.TabSet; i: Integer; begin tempSet := StringUtils.TabSet(TabSet2.Clone); tempSet.Remove(20); for i := 0 to 14 do Assert.AreEqual(tempSet.TabFrom(i), 15, 'Removed 20; Tabulate from {0}', [i]); for i := 15 to 39 do Assert.AreEqual(tempSet.TabFrom(i), 40, 'Removed 20; Tabulate from {0}', [i]); for i := 40 to 43 do Assert.AreEqual(tempSet.TabFrom(i), 44, 'Removed 20; Tabulate from {0}', [i]); for i := 44 to 47 do Assert.AreEqual(tempSet.TabFrom(i), 48, 'Removed 20; Tabulate from {0}', [i]); for i := 48 to 51 do Assert.AreEqual(tempSet.TabFrom(i), 52, 'Removed 20; Tabulate from {0}', [i]); for i := 52 to 55 do Assert.AreEqual(tempSet.TabFrom(i), 56, 'Removed 20; Tabulate from {0}', [i]); for i := 56 to 59 do Assert.AreEqual(tempSet.TabFrom(i), 60, 'Removed 20; Tabulate from {0}', [i]); tempSet := StringUtils.TabSet(TabSet2.Clone); tempSet.Remove(40); for i := 0 to 14 do Assert.AreEqual(tempSet.TabFrom(i), 15, 'Removed 40; Tabulate from {0}', [i]); for i := 15 to 19 do Assert.AreEqual(tempSet.TabFrom(i), 20, 'Removed 40; Tabulate from {0}', [i]); for i := 20 to 43 do Assert.AreEqual(tempSet.TabFrom(i), 44, 'Removed 40; Tabulate from {0}', [i]); for i := 44 to 67 do Assert.AreEqual(tempSet.TabFrom(i), 68, 'Removed 40; Tabulate from {0}', [i]); for i := 68 to 91 do Assert.AreEqual(tempSet.TabFrom(i), 92, 'Removed 40; Tabulate from {0}', [i]); for i := 92 to 115 do Assert.AreEqual(tempSet.TabFrom(i), 116, 'Removed 40; Tabulate from {0}', [i]); for i := 116 to 139 do Assert.AreEqual(tempSet.TabFrom(i), 140, 'Removed 40; Tabulate from {0}', [i]); tempSet := StringUtils.TabSet(TabSet2.Clone); tempSet.Remove(40, True); for i := 0 to 14 do Assert.AreEqual(tempSet.TabFrom(i), 15, 'Removed 40+; Tabulate from {0}', [i]); for i := 15 to 19 do Assert.AreEqual(tempSet.TabFrom(i), 20, 'Removed 40+; Tabulate from {0}', [i]); for i := 20 to 24 do Assert.AreEqual(tempSet.TabFrom(i), 25, 'Removed 40+; Tabulate from {0}', [i]); for i := 25 to 29 do Assert.AreEqual(tempSet.TabFrom(i), 30, 'Removed 40+; Tabulate from {0}', [i]); for i := 30 to 34 do Assert.AreEqual(tempSet.TabFrom(i), 35, 'Removed 40+; Tabulate from {0}', [i]); for i := 35 to 39 do Assert.AreEqual(tempSet.TabFrom(i), 40, 'Removed 40+; Tabulate from {0}', [i]); for i := 40 to 44 do Assert.AreEqual(tempSet.TabFrom(i), 45, 'Removed 40+; Tabulate from {0}', [i]); end; procedure TabSet.AddingTabs; var tempSet: StringUtils.TabSet; tempSet2: StringUtils.TabSet; i: Integer; begin tempSet := StringUtils.TabSet(TabSet2.Clone); tempSet.Add(42); for i := 0 to 14 do Assert.AreEqual(tempSet.TabFrom(i), 15, 'Added 42; Tabulate from {0}', [i]); for i := 15 to 19 do Assert.AreEqual(tempSet.TabFrom(i), 20, 'Added 42; Tabulate from {0}', [i]); for i := 20 to 39 do Assert.AreEqual(tempSet.TabFrom(i), 40, 'Added 42; Tabulate from {0}', [i]); for i := 40 to 41 do Assert.AreEqual(tempSet.TabFrom(i), 42, 'Added 42; Tabulate from {0}', [i]); for i := 42 to 43 do Assert.AreEqual(tempSet.TabFrom(i), 44, 'Added 42; Tabulate from {0}', [i]); for i := 44 to 45 do Assert.AreEqual(tempSet.TabFrom(i), 46, 'Added 42; Tabulate from {0}', [i]); for i := 46 to 47 do Assert.AreEqual(tempSet.TabFrom(i), 48, 'Added 42; Tabulate from {0}', [i]); for i := 48 to 49 do Assert.AreEqual(tempSet.TabFrom(i), 50, 'Added 42; Tabulate from {0}', [i]); for i := 50 to 51 do Assert.AreEqual(tempSet.TabFrom(i), 52, 'Added 42; Tabulate from {0}', [i]); tempSet2 := StringUtils.TabSet.Create([40, 20, 15], 2); Assert.AreEqual(tempSet2, tempSet); end; {$ENDREGION} {$REGION 'QuotedStrings'} procedure QuotedStrings.QuoteComplexString; var s: string; begin s := StringUtils.QuoteString(sComplexTest, ''''); Assert.AreEqual(s, sComplexTestQuoted); end; procedure QuotedStrings.QuoteComplexStringWithAlternateQuoting; var s: string; begin s := StringUtils.QuoteString(sComplexTest, '"'); Assert.AreEqual(s, sComplexTestAlternateQuoted); end; procedure QuotedStrings.QuoteSimpleString; var s: string; begin s := StringUtils.QuoteString(sSimpleTest); Assert.AreEqual(sSimpleTestQuoted, s); end; procedure QuotedStrings.QuoteStringWithQuotes; var s: string; begin s := StringUtils.QuoteString(sSimpleTestWithQuotes); Assert.AreEqual(sSimpleTestWithQuotesQuoted, s); end; procedure QuotedStrings.QuoteStringWithOtherQuotes; var s: string; begin s := StringUtils.QuoteString(sSimpleTestWithOtherQuotes); Assert.AreEqual(sSimpleTestWithOtherQuotesQuoted, s); end; procedure QuotedStrings.RoundtripSimpleString; var s: string; begin s := StringUtils.ExtractQuotedString(StringUtils.QuoteString(sSimpleTest)); Assert.AreEqual(sSimpleTest, s); end; procedure QuotedStrings.RoundtripStringWithOtherQuotes; var s: string; begin s := StringUtils.ExtractQuotedString(StringUtils.QuoteString(sSimpleTestWithOtherQuotes)); Assert.AreEqual(sSimpleTestWithOtherQuotes, s); end; procedure QuotedStrings.RoundtripStringWithQuotes; var s: string; begin s := StringUtils.ExtractQuotedString(StringUtils.QuoteString(sSimpleTestWithQuotes)); Assert.AreEqual(sSimpleTestWithQuotes, s); end; procedure QuotedStrings.RoundtripComplexString; var s: string; begin s := StringUtils.ExtractQuotedString(StringUtils.QuoteString(sComplexTest, '''')); Assert.AreEqual(s, sComplexTest); end; procedure QuotedStrings.RoundtripComplexStringWithAlternateQuoting; var s: string; begin s := StringUtils.ExtractQuotedString(StringUtils.QuoteString(sComplexTest, '"')); Assert.AreEqual(s, sComplexTest); end; procedure QuotedStrings.DequoteStringWithGarbage; var s: string; begin s := StringUtils.ExtractQuotedString(sSimpleTestWithGarbageQuoted); Assert.Fail('Should result in an exception. Resulting string={0}', [s]); end; procedure QuotedStrings.DequoteStringWithoutEndQuote; var s: string; begin s := StringUtils.ExtractQuotedString(sSimpleTestMissingEndQuote); Assert.Fail('Should result in an exception. Resulting string={0}', [s]); end; procedure QuotedStrings.DequoteStringWithAllowedGarbage; var s: string; begin s := StringUtils.ExtractQuotedString(sSimpleTestWithGarbageQuoted, ExtractQuotedStringFlags.IgnoreGarbage or ExtractQuotedStringFlags.EndQuoteMandetory); Assert.AreEqual(sSimpleTest, s, 'actual garbage'); s := StringUtils.ExtractQuotedString(sSimpleTestQuoted, ExtractQuotedStringFlags.IgnoreGarbage or ExtractQuotedStringFlags.EndQuoteMandetory); Assert.AreEqual(sSimpleTest, s, 'no actual garbage'); end; procedure QuotedStrings.DequoteStringAllowedMissingEndQuote; var s: string; begin s := StringUtils.ExtractQuotedString(sSimpleTestMissingEndQuote, ExtractQuotedStringFlags.IgnoreGarbage); Assert.AreEqual(sSimpleTest, s, 'end quote actually missing'); s := StringUtils.ExtractQuotedString(sSimpleTestQuoted, ExtractQuotedStringFlags.IgnoreGarbage); Assert.AreEqual(sSimpleTest, s, 'end quote provided'); end; procedure QuotedStrings.DequoteStringCheckGarbage; var s: string; i: Integer; begin s := StringUtils.ExtractQuotedString(sSimpleTestWithGarbageQuoted, i); Assert.AreEqual(sSimpleTest, s); Assert.AreEqual(sSimpleTestWithGarbageQuoted.LastIndexOf(''''), i); end; procedure QuotedStrings.DequoteStringCheckEndQuote; var s: string; i: Integer; begin s := StringUtils.ExtractQuotedString(sSimpleTestMissingEndQuote, i); Assert.AreEqual(sSimpleTest, s); Assert.AreEqual(not sSimpleTestMissingEndQuote.Length, i); end; procedure QuotedStrings.DequoteNonQuotedString; var s: string; begin s := StringUtils.ExtractQuotedString(sSimpleTest); Assert.AreEqual(sSimpleTest, s); s := StringUtils.ExtractQuotedString(sSimpleTestWithQuotes); Assert.AreEqual(sSimpleTestWithQuotes, s); end; {$ENDREGION} {$REGION 'Substrings'} procedure Substrings.AfterSingleDelimiter; var s: string; begin s := StringUtils.After(sDelimTest, '='); Assert.AreEqual(sDelimTestAfterFirstEquals, s); s := StringUtils.After(sDelimTest, '('); Assert.AreEqual(sDelimTestAfterFirstParenthesis, s); s := StringUtils.After(sDelimTest, '{'); Assert.AreEqual(sDelimTestAfterFirstBrace, s); s := StringUtils.After(sDelimTest, ' '); Assert.AreEqual('', s); s := StringUtils.After(sDelimTest, '|'); Assert.AreEqual(sDelimTestAfterFirstPipe, s); end; procedure Substrings.AfterMultipleDelimiters; var s: string; begin s := StringUtils.AfterAnyOf(sDelimTest, '={'.ToCharArray); Assert.AreEqual(sDelimTestAfterFirstBrace, s); s := StringUtils.AfterAnyOf(sDelimTest, ' =;'.ToCharArray); Assert.AreEqual(sDelimTestAfterFirstSemiColon, s); s := StringUtils.AfterAnyOf(sDelimTest, ';.{(='.ToCharArray); Assert.AreEqual(sDelimTestAfterFirstParenthesis, s); s := StringUtils.AfterAnyOf(sDelimTest, ' %$#&*_+-'.ToCharArray); Assert.AreEqual('', s); end; procedure Substrings.AfterLastSingleDelimiter; var s: string; begin s := StringUtils.AfterLast(sDelimTest, '='); Assert.AreEqual(sDelimTestAfterEquals, s); s := StringUtils.AfterLast(sDelimTest, '('); Assert.AreEqual(sDelimTestAfterParenthesis, s); s := StringUtils.AfterLast(sDelimTest, '{'); Assert.AreEqual(sDelimTestAfterBrace, s); s := StringUtils.AfterLast(sDelimTest, ' '); Assert.AreEqual('', s); s := StringUtils.AfterLast(sDelimTest, '|'); Assert.AreEqual('', s); end; procedure Substrings.AfterLastMultipleDelimiters; var s: string; begin s := StringUtils.AfterLastAnyOf(sDelimTest, '={'.ToCharArray); Assert.AreEqual(sDelimTestAfterBrace, s); s := StringUtils.AfterLastAnyOf(sDelimTest, ' =.'.ToCharArray); Assert.AreEqual(sDelimTestAfterDot, s); s := StringUtils.AfterLastAnyOf(sDelimTest, ';.{(='.ToCharArray); Assert.AreEqual(sDelimTestAfterSemiColon, s); s := StringUtils.AfterLastAnyOf(sDelimTest, ' %$#&*_+-'.ToCharArray); Assert.AreEqual('', s); end; procedure Substrings.BeforeSingleDelimiter; var s: string; begin s := StringUtils.Before(sDelimTest, '='); Assert.AreEqual(sDelimTestBeforeEquals, s); s := StringUtils.Before(sDelimTest, '('); Assert.AreEqual(sDelimTestBeforeParenthesis, s); s := StringUtils.Before(sDelimTest, '{'); Assert.AreEqual(sDelimTestBeforeBrace, s); s := StringUtils.Before(sDelimTest, ' '); Assert.AreEqual(sDelimTest, s); s := StringUtils.Before(sDelimTest, '|'); Assert.AreEqual('', s); end; procedure Substrings.BeforeMultipleDelimiters; var s: string; begin s := StringUtils.BeforeAnyOf(sDelimTest, '={'.ToCharArray); Assert.AreEqual(sDelimTestBeforeBrace, s); s := StringUtils.BeforeAnyOf(sDelimTest, ' =;'.ToCharArray); Assert.AreEqual(sDelimTestBeforeSemiColon, s); s := StringUtils.BeforeAnyOf(sDelimTest, ';.{(='.ToCharArray); Assert.AreEqual(sDelimTestBeforeParenthesis, s); s := StringUtils.BeforeAnyOf(sDelimTest, ' %$#&*_+-'.ToCharArray); Assert.AreEqual(sDelimTest, s); end; procedure Substrings.BeforeLastSingleDelimiter; var s: string; begin s := StringUtils.BeforeLast(sDelimTest, '='); Assert.AreEqual(sDelimTestBeforeLastEquals, s); s := StringUtils.BeforeLast(sDelimTest, '('); Assert.AreEqual(sDelimTestBeforeLastParenthesis, s); s := StringUtils.BeforeLast(sDelimTest, '{'); Assert.AreEqual(sDelimTestBeforeLastBrace, s); s := StringUtils.BeforeLast(sDelimTest, ' '); Assert.AreEqual(sDelimTest, s); s := StringUtils.BeforeLast(sDelimTest, '|'); Assert.AreEqual(sDelimTestBeforeLastPipe, s); end; procedure Substrings.BeforeLastMultipleDelimiters; var s: string; begin s := StringUtils.BeforeLastAnyOf(sDelimTest, '={'.ToCharArray); Assert.AreEqual(sDelimTestBeforeLastBrace, s); s := StringUtils.BeforeLastAnyOf(sDelimTest, ' =;'.ToCharArray); Assert.AreEqual(sDelimTestBeforeLastSemiColon, s); s := StringUtils.BeforeLastAnyOf(sDelimTest, ';.{(='.ToCharArray); Assert.AreEqual(sDelimTestBeforeLastSemiColon, s); s := StringUtils.BeforeLastAnyOf(sDelimTest, ' %$#&*_+-'.ToCharArray); Assert.AreEqual(sDelimTest, s); end; procedure Substrings.Left; var s: string; begin s := StringUtils.Left(sSliceTest, 10); Assert.AreEqual('0123456789', s); end; procedure Substrings.Mid; var s: string; begin s := StringUtils.Mid(sSliceTest, 10, 14); Assert.AreEqual('ABCDE', s); end; procedure Substrings.Right; var s: string; begin s := StringUtils.Right(sSliceTest, 10); Assert.AreEqual('qrstuvwxyz', s); end; {$ENDREGION} {$REGION 'Manipulations'} procedure Manipulations.ExpandTabs; var tabSet1: StringUtils.TabSet; tabSet2: StringUtils.TabSet; tabSet3: StringUtils.TabSet; begin tabSet1 := StringUtils.TabSet.Create(2); tabSet2 := StringUtils.TabSet.Create([15, 20, 40, 44]); tabSet3 := StringUtils.TabSet.Create([15, 20, 40, 44], 2); Assert.AreEqual(sTabTest1Output1, StringUtils.ExpandTabs(sTabTest1, tabSet1), 'sTabTest1Output1'); Assert.AreEqual(sTabTest2Output1, StringUtils.ExpandTabs(sTabTest2, tabSet1), 'sTabTest2Output1'); Assert.AreEqual(sTabTest1Output2, StringUtils.ExpandTabs(sTabTest1, tabSet2), 'sTabTest1Output2'); Assert.AreEqual(sTabTest2Output2, StringUtils.ExpandTabs(sTabTest2, tabSet2), 'sTabTest2Output2'); Assert.AreEqual(sTabTest1Output3, StringUtils.ExpandTabs(sTabTest1, tabSet3), 'sTabTest1Output3'); Assert.AreEqual(sTabTest2Output3, StringUtils.ExpandTabs(sTabTest2, tabSet3), 'sTabTest2Output3'); end; procedure Manipulations.RemoveDuplicates; begin Assert.AreEqual(sTest1Output, StringUtils.RemoveDuplicateChars(sTest1, '*'), 'sTest1'); end; procedure Manipulations.&Repeat; begin Assert.AreEqual(sRepeatOutput0, StringUtils.&Repeat(sRepeatInput, 0), 'Count=0'); Assert.AreEqual(sRepeatOutput1, StringUtils.&Repeat(sRepeatInput, 1), 'Count=1'); Assert.AreEqual(sRepeatOutput10, StringUtils.&Repeat(sRepeatInput, 10), 'Count=10'); end; {$ENDREGION} end. --- NEW FILE: Jedi.IO.BaseNUnit.pas --- unit Jedi.IO.BaseNUnit; interface type PathTestCases = class strict private class constructor Create; strict protected const sNormVolumeRoot = 'volume{0}{1}'; const sNormVolumeRoot2 = 'secondvolume{0}'; const sNormVolumeRootNoSlash = 'volume{0}'; const sNormInvalidVolumeRoot = '{1}path{1}volume{0}{1}'; const sNormInvalidRelativePathUpLevel = '..SubFolder2.2'; const sNormDeepVolumeRootedPath = 'volume{0}{1}MyRootFolder{1}SubFolder1{1}SubFolder1.1{1}SubFolder1.1.1'; const sNormVolumePath = 'primary{0}{1}PrimaryRoot{1}My Folder'; const sNormDeepRootedPath = '{1}MyRootFolder{1}SubFolder1{1}SubFolder1.1{1}SubFolder1.1.1'; const sNormRelativePath = 'SubFolder2{1}SubFolder2.1'; const sNormRelativePathUpLevel = '..{1}SubFolder2.2'; const sNormRelativePathUpTwoLevels = '..{1}..{1}SubFolder3{1}SubFolder3.1{1}SubFolder3.1.1{1}SubFolder3.1.4'; const sNormRelativePathUpTwoLevelsSep = '..{1}..{1}SubFolder4{1}SubFolder4.1{1}SubFolder4.1.1{1}SubFolder4.1.4'; const sNormStartWithThisPath = 'My Folder'; const sNormHasDottedFolderName = 'SubFolder5{1}.HiddenStuff'; const sNormWildcardedFile = '*.txt'; const sNormCombinedVolRootAndRelativePath = 'volume{0}{1}SubFolder2{1}SubFolder2.1'; const sNormCombinedDeepVolRootAndRelPathUpTwo = 'volume{0}{1}MyRootFolder{1}SubFolder1{1}SubFolder3{1}SubFolder3.1{1}SubFolder3.1.1{1}SubFolder3.1.4'; const sNormCombinedVolRoot2AndDeepRooted = 'secondvolume{0}{1}MyRootFolder{1}SubFolder1{1}SubFolder1.1{1}SubFolder1.1.1'; const sNormCombinedVolPathAndDeepRooted = 'primary{0}{1}MyRootFolder{1}SubFolder1{1}SubFolder1.1{1}SubFolder1.1.1'; const sNormCombinedRelAndRelPathUp = 'SubFolder2{1}SubFolder2.2'; public const sVolumeRoot = 'volume:\'; const sVolumeRoot2 = 'secondvolume:'; const sVolumeRootNoSlash = 'volume:'; const sInvalidVolumeRoot = '\path\volume:\'; const sInvalidRelativePathUpLevel = '..SubFolder2.2'; const sDeepVolumeRootedPath = 'volume:\MyRootFolder/SubFolder1\SubFolder1.1/SubFolder1.1.1\'; const sVolumePath = 'primary:/PrimaryRoot\My Folder'; const sDeepRootedPath = '\MyRootFolder/SubFolder1/\SubFolder1.1//SubFolder1.1.1\'; const sRelativePath = 'SubFolder2\SubFolder2.1'; const sRelativePathUpLevel = '..\SubFolder2.2'; const sRelativePathUpTwoLevels = '...\SubFolder3\SubFolder3.1\SubFolder3.1.1\SubFolder3.1.4'; const sRelativePathUpTwoLevelsSep = '..\..\SubFolder4\SubFolder4.1\SubFolder4.1.1\SubFolder4.1.4'; const sStartWithThisPath = '.\My Folder'; const sHasDottedFolderName = 'SubFolder5\.HiddenStuff'; const sWildcardedFile = '*.txt'; class var sVolumeRootNormalized: string; sVolumeRoot2Normalized: string; sVolumeRootNoSlashNormalized: string; sInvalidVolumeRootNormalized: string; sInvalidRelativePathUpLevelNormalized: string; sDeepVolumeRootedPathNormalized: string; sDeepRootedPathNormalized: string; sVolumePathNormalized: string; sRelativePathNormalized: string; sRelativePathUpLevelNormalized: string; sRelativePathUpTwoLevelsNormalized: string; sRelativePathUpTwoLevelsSepNormalized: string; sStartWithThisPathNormalized: string; sHasDottedFolderNameNormalized: string; sWildcardedFileNormalized: string; sCombinedVolRootAndRelativePath: string; sCombinedDeepVolRootAndRelPathUpTwo: string; sCombinedVolRoot2AndDeepRooted: string; sCombinedVolPathAndDeepRooted: string; sCombinedRelAndRelPathUp: string; end; implementation uses System.IO; class constructor PathTestCases.Create; begin sVolumeRootNormalized := System.String.Format(sNormVolumeRoot, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sVolumeRoot2Normalized := System.String.Format(sNormVolumeRoot2, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sVolumeRootNoSlashNormalized := System.String.Format(sNormVolumeRootNoSlash, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sInvalidVolumeRootNormalized := System.String.Format(sNormInvalidVolumeRoot, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sInvalidRelativePathUpLevelNormalized := System.String.Format(sNormInvalidRelativePathUpLevel, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sDeepVolumeRootedPathNormalized := System.String.Format(sNormDeepVolumeRootedPath, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sDeepRootedPathNormalized := System.String.Format(sNormDeepRootedPath, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sVolumePathNormalized := System.String.Format(sNormVolumePath, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sRelativePathNormalized := System.String.Format(sNormRelativePath, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sRelativePathUpLevelNormalized := System.String.Format(sNormRelativePathUpLevel, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sRelativePathUpTwoLevelsNormalized := System.String.Format(sNormRelativePathUpTwoLevels, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sRelativePathUpTwoLevelsSepNormalized := System.String.Format(sNormRelativePathUpTwoLevelsSep, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sStartWithThisPathNormalized := System.String.Format(sNormStartWithThisPath, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sHasDottedFolderNameNormalized := System.String.Format(sNormHasDottedFolderName, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sWildcardedFileNormalized := System.String.Format(sNormWildcardedFile, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sCombinedVolRootAndRelativePath := System.String.Format(sNormCombinedVolRootAndRelativePath, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sCombinedDeepVolRootAndRelPathUpTwo := System.String.Format(sNormCombinedDeepVolRootAndRelPathUpTwo, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sCombinedVolRoot2AndDeepRooted := System.String.Format(sNormCombinedVolRoot2AndDeepRooted, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sCombinedVolPathAndDeepRooted := System.String.Format(sNormCombinedVolPathAndDeepRooted, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); sCombinedRelAndRelPathUp := System.String.Format(sNormCombinedRelAndRelPathUp, Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); end; end. --- NEW FILE: Jedi.System.AttributesNUnit.pas --- unit Jedi.System.AttributesNUnit; interface uses System.ComponentModel, NUnit.Framework, Jedi.System.Attributes; type [TestFixture] AttributeUtils = class strict protected List1: array of Attribute; List2: AttributeCollection; ListAfterAdd: array of Attribute; ListAfterAddAndReplace: array of Attribute; ListAfterDelete: array of Attribute; ListAfterReplace: array of Attribute; public [TestFixtureSetup] procedure TestSetup; [Test] procedure Combine_Add; [Test] procedure Combine_AddAndReplace; [Test] procedure Combine_Delete; [Test] procedure Combine_Replace; [Test] procedure RetrieveAttributeByType; [Test] procedure RetrieveAttributeByInstance; end; implementation {$REGION 'Test attributes'} type TestAttributeBase = class (Attribute) public constructor Create(value: &Object); public Value: &Object; end; TestAttribute1 = class (TestAttributeBase); TestAttribute2 = class (TestAttributeBase); TestAttribute3 = class (TestAttributeBase); TestAttribute4 = class (TestAttributeBase); TestAttribute5 = class (TestAttributeBase); TestAttribute6 = class (TestAttributeBase); TestAttribute7 = class (TestAttributeBase); TestAttribute8 = class (TestAttributeBase); TestAttribute9 = class (TestAttributeBase); TestAttribute11 = class (TestAttribute1); TestAttribute12 = class (TestAttribute1); TestAttribute111 = class (TestAttribute11); TestAttribute112 = class (TestAttribute11); TestAttribute121 = class (TestAttribute12); TestAttribute122 = class (TestAttribute12); TestAttribute21 = class (TestAttribute2); TestAttribute22 = class (TestAttribute2); TestAttribute211 = class (TestAttribute21); TestAttribute212 = class (TestAttribute21); TestAttribute221 = class (TestAttribute22); TestAttribute222 = class (TestAttribute22); {$REGION 'TestAttributeBase'} constructor TestAttributeBase.Create(value: &Object); begin inherited Create; Self.Value := value; end; {$ENDREGION} {$ENDREGION} {$REGION 'AttributeUtils'} procedure AttributeUtils.Combine_Add; var newList: array of Attribute; begin newList := Jedi.System.Attributes.AttributeUtils.CombineAttributes(List1, List2, AttributeCombineOperation.Add); Assert.AreEqual(ListAfterAdd, newList); end; procedure AttributeUtils.Combine_AddAndReplace; var newList: array of Attribute; begin newList := Jedi.System.Attributes.AttributeUtils.CombineAttributes(List1, List2, AttributeCombineOperation.AddAndReplace); Assert.AreEqual(ListAfterAddAndReplace, newList); end; procedure AttributeUtils.Combine_Delete; var newList: array of Attribute; begin newList := Jedi.System.Attributes.AttributeUtils.CombineAttributes(List1, List2, AttributeCombineOperation.Delete); Assert.AreEqual(ListAfterDelete, newList); end; procedure AttributeUtils.Combine_Replace; var newList: array of Attribute; begin newList := Jedi.System.Attributes.AttributeUtils.CombineAttributes(List1, List2, AttributeCombineOperation.Replace); Assert.AreEqual(ListAfterReplace, newList); end; procedure AttributeUtils.RetrieveAttributeByType; var attr: Attribute; begin attr := Jedi.System.Attributes.AttributeUtils.GetAttribute(List1, TypeOf(TestAttribute1)); Assert.AreSame(List1[0], attr, 'List1[0]'); attr := Jedi.System.Attributes.AttributeUtils.GetAttribute(List2, TypeOf(TestAttribute1)); Assert.AreSame(List2[0], attr, 'List2[0]'); end; procedure AttributeUtils.RetrieveAttributeByInstance; var attr: Attribute; begin attr := TestAttribute1.Create('Attribute 1, list 1.'); attr := Jedi.System.Attributes.AttributeUtils.GetAttribute(List1, attr); Assert.AreSame(List1[0], attr, 'List1[0]'); attr := TestAttribute1.Create('Attribute 1, list 2.'); attr := Jedi.System.Attributes.AttributeUtils.GetAttribute(List2, attr); Assert.AreSame(List2[0], attr, 'List2[0]'); attr := TestAttribute1.Create('Attribute x, list 1.'); attr := Jedi.System.Attributes.AttributeUtils.GetAttribute(List1, attr); Assert.IsNull( attr, 'Found an attribute for TestAttribute1(''Attribute x, list1.'')'); attr := TestAttribute1.Create('Attribute x, list 2.'); attr := Jedi.System.Attributes.AttributeUtils.GetAttribute(List2, attr); Assert.IsNull( attr, 'Found an attribute for TestAttribute1(''Attribute x, list2.'')'); end; procedure AttributeUtils.TestSetup; begin List1 := AttributeArray.Create( TestAttribute1.Create('Attribute 1, list 1.'), TestAttribute212.Create('Attribute 2, list 1.'), TestAttribute3.Create('Attribute 3, list 1.'), TestAttribute4.Create('Attribute 4, list 1.'), TestAttribute5.Create('Attribute 5, list 1.') ); List2 := AttributeCollection.Create(AttributeArray.Create( TestAttribute1.Create('Attribute 1, list 2.'), TestAttribute11.Create('Attribute 2, list 2.'), TestAttribute2.Create('Attribute 3, list 2.'), TestAttribute6.Create('Attribute 4, list 2.'), TestAttribute7.Create('Attribute 5, list 2.') )); ListAfterAdd := AttributeArray.Create( TestAttribute1.Create('Attribute 1, list 1.'), TestAttribute212.Create('Attribute 2, list 1.'), TestAttribute3.Create('Attribute 3, list 1.'), TestAttribute4.Create('Attribute 4, list 1.'), TestAttribute5.Create('Attribute 5, list 1.'), TestAttribute11.Create('Attribute 2, list 2.'), TestAttribute2.Create('Attribute 3, list 2.'), TestAttribute6.Create('Attribute 4, list 2.'), TestAttribute7.Create('Attribute 5, list 2.') ); ListAfterAddAndReplace := AttributeArray.Create( TestAttribute1.Create('Attribute 1, list 2.'), TestAttribute212.Create('Attribute 2, list 1.'), TestAttribute3.Create('Attribute 3, list 1.'), TestAttribute4.Create('Attribute 4, list 1.'), TestAttribute5.Create('Attribute 5, list 1.'), TestAttribute11.Create('Attribute 2, list 2.'), TestAttribute2.Create('Attribute 3, list 2.'), TestAttribute6.Create('Attribute 4, list 2.'), TestAttribute7.Create('Attribute 5, list 2.') ); ListAfterDelete := AttributeArray.Create( TestAttribute212.Create('Attribute 2, list 1.'), TestAttribute3.Create('Attribute 3, list 1.'), TestAttribute4.Create('Attribute 4, list 1.'), TestAttribute5.Create('Attribute 5, list 1.') ); ListAfterReplace := AttributeArray.Create( TestAttribute1.Create('Attribute 1, list 2.'), TestAttribute212.Create('Attribute 2, list 1.'), TestAttribute3.Create('Attribute 3, list 1.'), TestAttribute4.Create('Attribute 4, list 1.'), TestAttribute5.Create('Attribute 5, list 1.') ); end; {$ENDREGION} end. --- NEW FILE: Jedi.IO.PathNunit.pas --- unit Jedi.IO.PathNunit; interface uses System.IO, NUnit.Framework, Jedi.IO.Paths, Jedi.IO.BaseNUnit; type [TestFixture] Normalize = class public [Test] procedure DeepVolumeRootedPath; [Test] procedure DeepRootedPath; [Test] procedure RelativePath; [Test] procedure RelativePathUpLevel; [Test] procedure RelativePathUpTwoLevels; [Test] procedure RelativePathUpTwoLevelsSep; [Test] procedure InvalidVolumeRoot; [Test] procedure InvalidRelativePathUpLevel; [Test] procedure VolumeRoot; [Test] procedure StartWithThisPath; [Test] procedure HasDottedFolderName; [Test] procedure WildcardedFile; end; [TestFixture] ValidityChecks = class public [Test] procedure DeepVolumeRootedPath; [Test] procedure DeepRootedPath; [Test] procedure RelativePath; [Test] procedure RelativePathUpLevel; [Test] procedure RelativePathUpTwoLevels; [Test] procedure RelativePathUpTwoLevelsSep; [Test] procedure InvalidVolumeRoot; [Test] procedure InvalidRelativePathUpLevel; [Test] procedure VolumeRoot; [Test] procedure StartWithThisPath; [Test] procedure HasDottedFolderName; [Test] procedure WildcardedFile; end; [TestFixture] Manipulations = class public [Test] procedure CombineTenPaths; [Test] procedure CombineTwo; [Test] procedure CombineTwoAbsolutePaths; end; [TestFixture] PathConfigurations = class public [Test] procedure TestConfiguration; end; implementation {$REGION 'Normalize'} procedure Normalize.DeepVolumeRootedPath; begin Assert.AreEqual(PathTestCases.sDeepVolumeRootedPathNormalized, Path.Normalize(PathTestCases.sDeepVolumeRootedPath)); end; procedure Normalize.DeepRootedPath; begin Assert.AreEqual(PathTestCases.sDeepRootedPathNormalized, Path.Normalize(PathTestCases.sDeepRootedPath)); end; procedure Normalize.RelativePath; begin Assert.AreEqual(PathTestCases.sRelativePathNormalized, Path.Normalize(PathTestCases.sRelativePath)); end; procedure Normalize.RelativePathUpLevel; begin Assert.AreEqual(PathTestCases.sRelativePathUpLevelNormalized, Path.Normalize(PathTestCases.sRelativePathUpLevel)); end; procedure Normalize.RelativePathUpTwoLevels; begin Assert.AreEqual(PathTestCases.sRelativePathUpTwoLevelsNormalized, Path.Normalize(PathTestCases.sRelativePathUpTwoLevels)); end; procedure Normalize.RelativePathUpTwoLevelsSep; begin Assert.AreEqual(PathTestCases.sRelativePathUpTwoLevelsSepNormalized, Path.Normalize(PathTestCases.sRelativePathUpTwoLevelsSep)); end; procedure Normalize.InvalidVolumeRoot; begin Assert.AreEqual(PathTestCases.sInvalidVolumeRootNormalized, Path.Normalize(PathTestCases.sInvalidVolumeRoot)); end; procedure Normalize.InvalidRelativePathUpLevel; begin Assert.AreEqual(PathTestCases.sInvalidRelativePathUpLevelNormalized, Path.Normalize(PathTestCases.sInvalidRelativePathUpLevel)); end; procedure Normalize.VolumeRoot; begin Assert.AreEqual(PathTestCases.sVolumeRootNormalized, Path.Normalize(PathTestCases.sVolumeRoot)); end; procedure Normalize.StartWithThisPath; begin Assert.AreEqual(PathTestCases.sStartWithThisPathNormalized, Path.Normalize(PathTestCases.sStartWithThisPath)); end; procedure Normalize.HasDottedFolderName; begin Assert.AreEqual(PathTestCases.sHasDottedFolderNameNormalized, Path.Normalize(PathTestCases.sHasDottedFolderName)); end; procedure Normalize.WildcardedFile; begin Assert.AreEqual(PathTestCases.sWildcardedFileNormalized, Path.Normalize(PathTestCases.sWildcardedFile)); end; {$ENDREGION} {$REGION 'ValidityChecks'} procedure ValidityChecks.DeepVolumeRootedPath; begin Assert.IsTrue(Path.IsValid(PathTestCases.sDeepVolumeRootedPath), 'IsValid({0}{{''{1}''}}) should be True', ['sDeepVolumeRootedPath', PathTestCases.sDeepVolumeRootedPath]); end; procedure ValidityChecks.DeepRootedPath; begin Assert.IsTrue(Path.IsValid(PathTestCases.sDeepRootedPath), 'IsValid({0}{{''{1}''}}) should be True', ['sDeepRootedPath', PathTestCases.sDeepRootedPath]); end; procedure ValidityChecks.RelativePath; begin Assert.IsTrue(Path.IsValid(PathTestCases.sRelativePath), 'IsValid({0}{{''{1}''}}) should be True', ['sRelativePath', PathTestCases.sRelativePath]); end; procedure ValidityChecks.RelativePathUpLevel; begin Assert.IsTrue(Path.IsValid(PathTestCases.sRelativePathUpLevel), 'IsValid({0}{{''{1}''}}) should be True', ['sRelativePathUpLevel', PathTestCases.sRelativePathUpLevel]); end; procedure ValidityChecks.RelativePathUpTwoLevels; begin Assert.IsTrue(Path.IsValid(PathTestCases.sRelativePathUpTwoLevels), 'IsValid({0}{{''{1}''}}) should be True', ['sRelativePathUpTwoLevels', PathTestCases.sRelativePathUpTwoLevels]); end; procedure ValidityChecks.RelativePathUpTwoLevelsSep; begin Assert.IsTrue(Path.IsValid(PathTestCases.sRelativePathUpTwoLevelsSep), 'IsValid({0}{{''{1}''}}) should be True', ['sRelativePathUpTwoLevelsSep', PathTestCases.sRelativePathUpTwoLevelsSep]); end; procedure ValidityChecks.InvalidVolumeRoot; begin Assert.IsFalse(Path.IsValid(PathTestCases.sInvalidVolumeRoot), 'IsValid({0}{{''{1}''}}) should be False', ['sInvalidVolumeRoot', PathTestCases.sInvalidVolumeRoot]); end; procedure ValidityChecks.InvalidRelativePathUpLevel; begin Assert.IsFalse(Path.IsValid(PathTestCases.sInvalidRelativePathUpLevel), 'IsValid({0}{{''{1}''}}) should be False', ['sInvalidRelativePathUpLevel', PathTestCases.sInvalidRelativePathUpLevel]); end; procedure ValidityChecks.VolumeRoot; begin Assert.IsTrue(Path.IsValid(PathTestCases.sVolumeRoot), 'IsValid({0}{{''{1}''}}) should be True', ['sVolumeRoot', PathTestCases.sVolumeRoot]); end; procedure ValidityChecks.StartWithThisPath; begin Assert.IsTrue(Path.IsValid(PathTestCases.sStartWithThisPath), 'IsValid({0}{{''{1}''}}) should be True', ['sStartWithThisPath', PathTestCases.sStartWithThisPath]); end; procedure ValidityChecks.HasDottedFolderName; begin Assert.IsTrue(Path.IsValid(PathTestCases.sHasDottedFolderName), 'IsValid({0}{{''{1}''}}) should be True', ['sHasDottedFolderName', PathTestCases.sHasDottedFolderName]); end; procedure ValidityChecks.WildcardedFile; begin Assert.IsFalse(Path.IsValid(PathTestCases.sWildcardedFile), 'IsValid({0}{{''{1}''}}) should be False', ['sWildcardedFile', PathTestCases.sWildcardedFile]); end; {$ENDREGION} {$REGION 'Manipulations'} procedure Manipulations.CombineTenPaths; begin Assert.AreEqual( System.String.Format('myvolume{0}{1}Root{1}Folder1{1}Folder1.1{1}Folder1.1.2{1}Folder1.1.2.1', System.IO.Path.VolumeSeparatorChar, System.IO.Path.DirectorySeparatorChar), Path.Combine(['dummy:NotAvailable\SubNotAvailable', '..\NotUsedEither', 'myvolume:\ignore', '\RootNotUsed\Ignore\Ignore2', '..\NotUsed', '\Root\Folder1\', '.\Folder1.1', 'Folder1.1.1\Folder1.1.1.1\Folder1.1.1.1.1\Folder1.1.1.1.1.1', '.....\Folder1.1.2', '.\Folder1.1.2.1'])); end; procedure Manipulations.CombineTwo; begin Assert.AreEqual( PathTestCases.sCombinedVolRootAndRelativePath, Path.Combine(PathTestCases.sVolumeRoot, PathTestCases.sRelativePath), 'Combine(sVolumeRoot, sRelativePath)'); Assert.AreEqual( PathTestCases.sCombinedDeepVolRootAndRelPathUpTwo, Path.Combine(PathTestCases.sDeepVolumeRootedPath, PathTestCases.sRelativePathUpTwoLevels), 'Combine(sDeepVolumeRootedPath, sRelativePathUpTwoLevels)'); Assert.AreEqual( PathTestCases.sCombinedRelAndRelPathUp, Path.Combine(PathTestCases.sRelativePath, PathTestCases.sRelativePathUpLevel), 'Combine(sRelativePath, sRelativePathUpLevel)'); end; procedure Manipulations.CombineTwoAbsolutePaths; begin Assert.AreEqual( PathTestCases.sCombinedVolRoot2AndDeepRooted, Path.Combine(PathTestCases.sVolumeRoot2, PathTestCases.sDeepRootedPath), 'Combine(sVolumeRoot2, sDeepRootedPath)'); Assert.AreEqual( PathTestCases.sCombinedVolPathAndDeepRooted, Path.Combine(PathTestCases.sVolumePath, PathTestCases.sDeepRootedPath), 'Combine(sVolumePath, sDeepRootedPath)'); Assert.AreEqual( PathTestCases.sDeepRootedPathNormalized, Path.Combine(PathTestCases.sRelativePath, PathTestCases.sDeepRootedPath), 'Combine(sRelativePath, sDeepRootedPath)'); end; {$ENDREGION} {$REGION 'PathConfigurations'} procedure PathConfigurations.TestConfiguration; begin Assert.AreEqual('myvolume#:folder1:folder2:folder3', Path.Normalize('myvolume#:folder1:folder2;folder3', Path.PathConfig.Create(':', ';', '#', ['$']))); end; {$ENDREGION} end. |