@@ -1736,6 +1736,53 @@ let expected = """
1736
1736
XCTAssertEqual ( " /=(_:_:) " , pageIdentifiersAndNames [ " /documentation/Operators/MyNumber/_=(_:_:)-3m4ko " ] )
1737
1737
}
1738
1738
1739
+ func testFileNamesWithDifferentPunctuation( ) throws {
1740
+ let tempURL = try createTempFolder ( content: [
1741
+ Folder ( name: " unit-test.docc " , content: [
1742
+ TextFile ( name: " Hello-world.md " , utf8Content: """
1743
+ # Dash
1744
+
1745
+ No whitespace in the file name
1746
+ """ ) ,
1747
+
1748
+ TextFile ( name: " Hello world.md " , utf8Content: """
1749
+ # Only space
1750
+
1751
+ This has the same reference as " Hello-world.md " and will raise a warning.
1752
+ """ ) ,
1753
+
1754
+ TextFile ( name: " Hello world.md " , utf8Content: """
1755
+ # Multiple spaces
1756
+
1757
+ Each space is replaced with a dash in the reference, so this has a unique reference.
1758
+ """ ) ,
1759
+
1760
+ TextFile ( name: " Hello, world!.md " , utf8Content: """
1761
+ # Space and punctuation
1762
+
1763
+ The punctuation is not removed from the reference, so this has a unique reference.
1764
+ """ ) ,
1765
+
1766
+ TextFile ( name: " Hello. world?.md " , utf8Content: """
1767
+ # Space and different punctuation
1768
+
1769
+ The punctuation is not removed from the reference, so this has a unique reference.
1770
+ """ ) ,
1771
+ ] )
1772
+ ] )
1773
+ let ( _, _, context) = try loadBundle ( from: tempURL)
1774
+
1775
+ XCTAssertEqual ( context. problems. map ( \. diagnostic. summary) , [ " Redeclaration of 'Hello world.md'; this file will be skipped " ] )
1776
+
1777
+ XCTAssertEqual ( context. knownPages. map ( \. absoluteString) . sorted ( ) , [
1778
+ " doc://unit-test/documentation/unit-test " ,
1779
+ " doc://unit-test/documentation/unit-test/Hello,-world! " ,
1780
+ " doc://unit-test/documentation/unit-test/Hello--world " ,
1781
+ " doc://unit-test/documentation/unit-test/Hello-world " ,
1782
+ " doc://unit-test/documentation/unit-test/Hello.-world- " ,
1783
+ ] )
1784
+ }
1785
+
1739
1786
func testSpecialCharactersInLinks( ) throws {
1740
1787
let originalSymbolGraph = Bundle . module. url ( forResource: " TestBundle " , withExtension: " docc " , subdirectory: " Test Bundles " ) !. appendingPathComponent ( " mykit-iOS.symbols.json " )
1741
1788
@@ -1751,7 +1798,15 @@ let expected = """
1751
1798
""" ) ,
1752
1799
1753
1800
TextFile ( name: " article-with-😃-in-filename.md " , utf8Content: """
1754
- # Article with 😃 emoji in file name
1801
+ # Article with 😃 emoji in its filename
1802
+
1803
+ Abstract
1804
+
1805
+ ### Hello world
1806
+ """ ) ,
1807
+
1808
+ TextFile ( name: " Article: with - various! whitespace & punctuation. in, filename.md " , utf8Content: """
1809
+ # Article with various whitespace and punctuation in its filename
1755
1810
1756
1811
Abstract
1757
1812
@@ -1767,6 +1822,8 @@ let expected = """
1767
1822
- <doc:article-with-emoji-in-heading#Hello-🌍>
1768
1823
- <doc:article-with-😃-in-filename>
1769
1824
- <doc:article-with-😃-in-filename#Hello-world>
1825
+ - <doc:Article:-with-various!-whitespace-&-punctuation.-in,-filename>
1826
+ - <doc:Article:-with-various!-whitespace-&-punctuation.-in,-filename#Hello-world>
1770
1827
1771
1828
Now test the same links in topic curation.
1772
1829
@@ -1776,6 +1833,7 @@ let expected = """
1776
1833
1777
1834
- ``MyClass/myFunc🙂()``
1778
1835
- <doc:article-with-😃-in-filename>
1836
+ - <doc:Article:-with-various!-whitespace-&-punctuation.-in,-filename>
1779
1837
""" ) ,
1780
1838
] )
1781
1839
let bundleURL = try testBundle. write ( inside: createTemporaryDirectory ( ) )
@@ -1789,11 +1847,12 @@ let expected = """
1789
1847
1790
1848
let moduleSymbol = try XCTUnwrap ( entity. semantic as? Symbol )
1791
1849
let topicSection = try XCTUnwrap ( moduleSymbol. topics? . taskGroups. first)
1792
-
1850
+
1793
1851
// Verify that all the links in the topic section resolved
1794
1852
XCTAssertEqual ( topicSection. links. map ( \. destination) , [
1795
1853
" doc://special-characters/documentation/MyKit/MyClass/myFunc_() " ,
1796
1854
" doc://special-characters/documentation/special-characters/article-with---in-filename " ,
1855
+ " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename " ,
1797
1856
] )
1798
1857
1799
1858
// Verify that all resolved link exist in the context.
@@ -1808,10 +1867,11 @@ let expected = """
1808
1867
let renderNode = translator. visit ( moduleSymbol) as! RenderNode
1809
1868
1810
1869
// Verify that the resolved links rendered as links
1811
- XCTAssertEqual ( renderNode. topicSections. first? . identifiers. count, 2 )
1870
+ XCTAssertEqual ( renderNode. topicSections. first? . identifiers. count, 3 )
1812
1871
XCTAssertEqual ( renderNode. topicSections. first? . identifiers, [
1813
1872
" doc://special-characters/documentation/MyKit/MyClass/myFunc_() " ,
1814
1873
" doc://special-characters/documentation/special-characters/article-with---in-filename " ,
1874
+ " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename " ,
1815
1875
] )
1816
1876
1817
1877
@@ -1826,7 +1886,7 @@ let expected = """
1826
1886
1827
1887
XCTAssertEqual ( lists. count, 1 )
1828
1888
let list = try XCTUnwrap ( lists. first)
1829
- XCTAssertEqual ( list. items. count, 4 , " Unexpected list items: \( list. items. map ( \. content) ) " )
1889
+ XCTAssertEqual ( list. items. count, 6 , " Unexpected list items: \( list. items. map ( \. content) ) " )
1830
1890
1831
1891
func withContentAsReference( _ listItem: RenderBlockContent . ListItem ? , verify: ( RenderReferenceIdentifier , Bool , String ? , [ RenderInlineContent ] ? ) -> Void ) {
1832
1892
guard let listItem = listItem else {
@@ -1866,7 +1926,19 @@ let expected = """
1866
1926
XCTAssertEqual ( overridingTitle, nil )
1867
1927
XCTAssertEqual ( overridingTitleInlineContent, nil )
1868
1928
}
1869
-
1929
+ withContentAsReference ( list. items. dropFirst ( 4 ) . first) { identifier, isActive, overridingTitle, overridingTitleInlineContent in
1930
+ XCTAssertEqual ( identifier. identifier, " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename " )
1931
+ XCTAssertEqual ( isActive, true )
1932
+ XCTAssertEqual ( overridingTitle, nil )
1933
+ XCTAssertEqual ( overridingTitleInlineContent, nil )
1934
+ }
1935
+ withContentAsReference ( list. items. dropFirst ( 5 ) . first) { identifier, isActive, overridingTitle, overridingTitleInlineContent in
1936
+ XCTAssertEqual ( identifier. identifier, " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename#Hello-world " )
1937
+ XCTAssertEqual ( isActive, true )
1938
+ XCTAssertEqual ( overridingTitle, nil )
1939
+ XCTAssertEqual ( overridingTitleInlineContent, nil )
1940
+ }
1941
+
1870
1942
// Verify that the topic render references have titles with special characters when the original content contained special characters
1871
1943
XCTAssertEqual (
1872
1944
( renderNode. references [ " doc://special-characters/documentation/MyKit/MyClass/myFunc_() " ] as? TopicRenderReference ) ? . title,
@@ -1878,12 +1950,20 @@ let expected = """
1878
1950
)
1879
1951
XCTAssertEqual (
1880
1952
( renderNode. references [ " doc://special-characters/documentation/special-characters/article-with---in-filename " ] as? TopicRenderReference ) ? . title,
1881
- " Article with 😃 emoji in file name "
1953
+ " Article with 😃 emoji in its filename "
1882
1954
)
1883
1955
XCTAssertEqual (
1884
1956
( renderNode. references [ " doc://special-characters/documentation/special-characters/article-with---in-filename#Hello-world " ] as? TopicRenderReference ) ? . title,
1885
1957
" Hello world "
1886
1958
)
1959
+ XCTAssertEqual (
1960
+ ( renderNode. references [ " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename " ] as? TopicRenderReference ) ? . title,
1961
+ " Article with various whitespace and punctuation in its filename "
1962
+ )
1963
+ XCTAssertEqual (
1964
+ ( renderNode. references [ " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename#Hello-world " ] as? TopicRenderReference ) ? . title,
1965
+ " Hello world "
1966
+ )
1887
1967
}
1888
1968
1889
1969
func testNonOverloadCollisionFromExtension( ) throws {
0 commit comments