@@ -1524,11 +1524,13 @@ public void CreateStringPreviews_DiffPointsToCorrectPlaceInNonShortenedString()
15241524 int length = 1 ;
15251525 int diffIndex = 0 ;
15261526 string stringPreview = FormatStringPreview ( StringPreviewHelper . CreateStringPreviews ( DigitString ( length , diffIndex ) , DigitString ( length , diffIndex ) , diffIndex , preview ) ) ;
1527- stringPreview . Should ( ) . Be ( """
1527+ StringPreviewsAreEqual (
1528+ """
15281529 "X"
15291530 "X"
15301531 _^
1531- """ ) ;
1532+ """ ,
1533+ stringPreview ) ;
15321534 }
15331535
15341536 public void CreateStringPreviews_DiffPointsToCorrectPlaceInShortenedStringWithEndCut ( )
@@ -1537,11 +1539,12 @@ public void CreateStringPreviews_DiffPointsToCorrectPlaceInShortenedStringWithEn
15371539 int length = preview + 10 ;
15381540 int diffIndex = 0 ;
15391541 string stringPreview = FormatStringPreview ( StringPreviewHelper . CreateStringPreviews ( DigitString ( length , diffIndex ) , DigitString ( length , diffIndex ) , diffIndex , preview ) ) ;
1540- stringPreview . Should ( ) . Be ( """
1542+ StringPreviewsAreEqual (
1543+ """
15411544 "X12345..."
15421545 "X12345..."
15431546 _^
1544- """ ) ;
1547+ """ , stringPreview ) ;
15451548 }
15461549
15471550 public void CreateStringPreviews_DiffPointsToCorrectPlaceInShortenedStringWithStartCut ( )
@@ -1550,11 +1553,13 @@ public void CreateStringPreviews_DiffPointsToCorrectPlaceInShortenedStringWithSt
15501553 int length = 10 ;
15511554 int diffIndex = 9 ;
15521555 string stringPreview = FormatStringPreview ( StringPreviewHelper . CreateStringPreviews ( DigitString ( length , diffIndex ) , DigitString ( length , diffIndex ) , diffIndex : diffIndex , preview ) ) ;
1553- stringPreview . Should ( ) . Be ( """
1556+ StringPreviewsAreEqual (
1557+ """
15541558 "...45678X"
15551559 "...45678X"
15561560 _________^
1557- """ ) ;
1561+ """ ,
1562+ stringPreview ) ;
15581563 }
15591564
15601565 public void CreateStringPreviews_ShowWholeStringWhenDifferenceIsAtTheEndAndJustOneStringDoesNotFit ( )
@@ -1563,11 +1568,13 @@ public void CreateStringPreviews_ShowWholeStringWhenDifferenceIsAtTheEndAndJustO
15631568 int length = 50 ;
15641569 int diffIndex = 16 ;
15651570 string stringPreview = FormatStringPreview ( StringPreviewHelper . CreateStringPreviews ( DigitString ( preview , diffIndex ) , DigitString ( length , diffIndex ) , diffIndex : diffIndex , preview ) ) ;
1566- stringPreview . Should ( ) . Be ( """
1571+ StringPreviewsAreEqual (
1572+ """
15671573 "0123456789012345X7890"
15681574 "0123456789012345X7..."
15691575 _________________^
1570- """ ) ;
1576+ """ ,
1577+ stringPreview ) ;
15711578 }
15721579
15731580 public void CreateStringPreviews_MakeSureWeDontPointToEndEllipsis ( )
@@ -1578,11 +1585,44 @@ public void CreateStringPreviews_MakeSureWeDontPointToEndEllipsis()
15781585 int diffIndex = 24 ;
15791586
15801587 string stringPreview = FormatStringPreview ( StringPreviewHelper . CreateStringPreviews ( DigitString ( preview , diffIndex ) , DigitString ( length , diffIndex ) , diffIndex : diffIndex , preview ) ) ;
1581- stringPreview . Should ( ) . Be ( """
1588+ StringPreviewsAreEqual (
1589+ """
15821590 "...8901234567890123X"
15831591 "...8901234567890123X56..."
15841592 ____________________^
1585- """ ) ;
1593+ """ ,
1594+ stringPreview ) ;
1595+ }
1596+
1597+ public void CreateStringPreviews_MakeSureWeDontPointToEndEllipsis_WhenLongerStringOneCharLargerThanPreviewWindow ( )
1598+ {
1599+ // We will mask last 3 chars of the string, so we need to make sure that the diff index is not pointing to the end ellipsis.
1600+ int preview = 15 ;
1601+ int diffIndex = preview - 1 ;
1602+
1603+ string stringPreview = FormatStringPreview ( StringPreviewHelper . CreateStringPreviews ( DigitString ( preview , diffIndex ) , DigitString ( preview + 1 , diffIndex ) , diffIndex : diffIndex , preview ) ) ;
1604+ StringPreviewsAreEqual (
1605+ """
1606+ "...890123X"
1607+ "...890123X5"
1608+ __________^
1609+ """ ,
1610+ stringPreview ) ;
1611+ }
1612+
1613+ public void CreateStringPreviews_MakeSureWeDontPointToEndEllipsis_WhenLongerStringIsBarelyLonger ( )
1614+ {
1615+ // We will mask last 3 chars of the string, so we need to make sure that the diff index is not pointing to the end ellipsis.
1616+ int preview = 25 ;
1617+
1618+ string stringPreview = FormatStringPreview ( StringPreviewHelper . CreateStringPreviews ( "01234567890123456789012345678901234567890123X" , "01234567890123456789012345678901234567890123X56" , diffIndex : 44 , preview ) ) ;
1619+ StringPreviewsAreEqual (
1620+ """
1621+ "...8901234567890123X"
1622+ "...8901234567890123X56"
1623+ ____________________^
1624+ """ ,
1625+ stringPreview ) ;
15861626 }
15871627
15881628 public void CreateStringPreviews_DiffPointsAfterLastCharacterWhenStringsAreAllTheSameCharactersUntilTheEndOfTheShorterOne ( )
@@ -1597,6 +1637,45 @@ public void CreateStringPreviews_DiffPointsAfterLastCharacterWhenStringsAreAllTh
15971637 """ ) ;
15981638 }
15991639
1640+ public void CreateStringPreviews_DiffNeverPointsAtEllipsis_Generated ( )
1641+ {
1642+ // Generate all combinations of string lengths and diff to see if in any of them we point to ellipsis.
1643+ StringBuilder s = new ( ) ;
1644+ foreach ( int a in Enumerable . Range ( 1 , 20 ) )
1645+ {
1646+ foreach ( int e in Enumerable . Range ( 1 , 20 ) )
1647+ {
1648+ foreach ( int d in Enumerable . Range ( 1 , Math . Min ( a , e ) ) )
1649+ {
1650+ string p = FormatStringPreview ( StringPreviewHelper . CreateStringPreviews ( DigitString ( e , d ) , DigitString ( a , d ) , diffIndex : d , 11 ) ) ;
1651+
1652+ string [ ] lines = p . Split ( "\n " ) ;
1653+ int diffIndicator = lines [ 2 ] . IndexOf ( '^' ) ;
1654+ bool line0PointsOnEllipsis = lines [ 0 ] . Length > diffIndicator && lines [ 0 ] [ diffIndicator ] == '.' ;
1655+ bool line1PointsOnEllipsis = lines [ 1 ] . Length > diffIndicator && lines [ 1 ] [ diffIndicator ] == '.' ;
1656+
1657+ if ( line0PointsOnEllipsis || line1PointsOnEllipsis )
1658+ {
1659+ string text = $ """
1660+ Failed for:
1661+ Expected={ e } , Actual={ a } , DiffIndex={ d }
1662+ string result = FormatStringPreview(StringPreviewHelper.CreateStringPreviews(DigitString({ e } , { d } ), DigitString({ a } , { d } ), diffIndex: { d } , 11));
1663+ { p }
1664+ """ ;
1665+
1666+ s . AppendLine ( text ) ;
1667+ s . AppendLine ( ) ;
1668+ }
1669+ }
1670+ }
1671+ }
1672+
1673+ if ( s . Length > 0 )
1674+ {
1675+ throw new InvalidOperationException ( $ "Some combinations pointed to ellipsis:\n { s } ") ;
1676+ }
1677+ }
1678+
16001679 private string FormatStringPreview ( Tuple < string , string , int > tuple )
16011680 => $ """
16021681 "{ tuple . Item1 } "
@@ -1628,4 +1707,19 @@ private static string DigitString(int length, int diffIndex)
16281707
16291708 return result . ToString ( ) ;
16301709 }
1710+
1711+ private void StringPreviewsAreEqual ( string expected , string actual )
1712+ {
1713+ if ( expected != actual )
1714+ {
1715+ throw new InvalidOperationException (
1716+ $ """
1717+ Actual:
1718+ { actual }
1719+
1720+ Expected:
1721+ { expected }
1722+ """ ) ;
1723+ }
1724+ }
16311725}
0 commit comments