@@ -1736,6 +1736,63 @@ 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: " Root.md " , utf8Content: """
1743
+ # Root
1744
+
1745
+ @Metadata {
1746
+ @TechnologyRoot
1747
+ }
1748
+
1749
+ This test needs an explicit root on 'release/5.10' but not on 'main'.
1750
+ """ ) ,
1751
+
1752
+ TextFile ( name: " Hello-world.md " , utf8Content: """
1753
+ # Dash
1754
+
1755
+ No whitespace in the file name
1756
+ """ ) ,
1757
+
1758
+ TextFile ( name: " Hello world.md " , utf8Content: """
1759
+ # Only space
1760
+
1761
+ This has the same reference as " Hello-world.md " and will raise a warning.
1762
+ """ ) ,
1763
+
1764
+ TextFile ( name: " Hello world.md " , utf8Content: """
1765
+ # Multiple spaces
1766
+
1767
+ Each space is replaced with a dash in the reference, so this has a unique reference.
1768
+ """ ) ,
1769
+
1770
+ TextFile ( name: " Hello, world!.md " , utf8Content: """
1771
+ # Space and punctuation
1772
+
1773
+ The punctuation is not removed from the reference, so this has a unique reference.
1774
+ """ ) ,
1775
+
1776
+ TextFile ( name: " Hello. world?.md " , utf8Content: """
1777
+ # Space and different punctuation
1778
+
1779
+ The punctuation is not removed from the reference, so this has a unique reference.
1780
+ """ ) ,
1781
+ ] )
1782
+ ] )
1783
+ let ( _, _, context) = try loadBundle ( from: tempURL)
1784
+
1785
+ XCTAssertEqual ( context. problems. map ( \. diagnostic. summary) , [ " Redeclaration of 'Hello world.md'; this file will be skipped " ] )
1786
+
1787
+ XCTAssertEqual ( context. knownPages. map ( \. absoluteString) . sorted ( ) , [
1788
+ " doc://unit-test/documentation/Root " , // since this catalog has an explicit technology root on the 'release/5.10' branch
1789
+ " doc://unit-test/documentation/unit-test/Hello,-world! " ,
1790
+ " doc://unit-test/documentation/unit-test/Hello--world " ,
1791
+ " doc://unit-test/documentation/unit-test/Hello-world " ,
1792
+ " doc://unit-test/documentation/unit-test/Hello.-world- " ,
1793
+ ] )
1794
+ }
1795
+
1739
1796
func testSpecialCharactersInLinks( ) throws {
1740
1797
let originalSymbolGraph = Bundle . module. url ( forResource: " TestBundle " , withExtension: " docc " , subdirectory: " Test Bundles " ) !. appendingPathComponent ( " mykit-iOS.symbols.json " )
1741
1798
@@ -1751,7 +1808,15 @@ let expected = """
1751
1808
""" ) ,
1752
1809
1753
1810
TextFile ( name: " article-with-😃-in-filename.md " , utf8Content: """
1754
- # Article with 😃 emoji in file name
1811
+ # Article with 😃 emoji in its filename
1812
+
1813
+ Abstract
1814
+
1815
+ ### Hello world
1816
+ """ ) ,
1817
+
1818
+ TextFile ( name: " Article: with - various! whitespace & punctuation. in, filename.md " , utf8Content: """
1819
+ # Article with various whitespace and punctuation in its filename
1755
1820
1756
1821
Abstract
1757
1822
@@ -1767,6 +1832,8 @@ let expected = """
1767
1832
- <doc:article-with-emoji-in-heading#Hello-🌍>
1768
1833
- <doc:article-with-😃-in-filename>
1769
1834
- <doc:article-with-😃-in-filename#Hello-world>
1835
+ - <doc:Article:-with-various!-whitespace-&-punctuation.-in,-filename>
1836
+ - <doc:Article:-with-various!-whitespace-&-punctuation.-in,-filename#Hello-world>
1770
1837
1771
1838
Now test the same links in topic curation.
1772
1839
@@ -1776,6 +1843,7 @@ let expected = """
1776
1843
1777
1844
- ``MyClass/myFunc🙂()``
1778
1845
- <doc:article-with-😃-in-filename>
1846
+ - <doc:Article:-with-various!-whitespace-&-punctuation.-in,-filename>
1779
1847
""" ) ,
1780
1848
] )
1781
1849
let bundleURL = try testBundle. write ( inside: createTemporaryDirectory ( ) )
@@ -1789,11 +1857,12 @@ let expected = """
1789
1857
1790
1858
let moduleSymbol = try XCTUnwrap ( entity. semantic as? Symbol )
1791
1859
let topicSection = try XCTUnwrap ( moduleSymbol. topics? . taskGroups. first)
1792
-
1860
+
1793
1861
// Verify that all the links in the topic section resolved
1794
1862
XCTAssertEqual ( topicSection. links. map ( \. destination) , [
1795
1863
" doc://special-characters/documentation/MyKit/MyClass/myFunc_() " ,
1796
1864
" doc://special-characters/documentation/special-characters/article-with---in-filename " ,
1865
+ " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename " ,
1797
1866
] )
1798
1867
1799
1868
// Verify that all resolved link exist in the context.
@@ -1808,10 +1877,11 @@ let expected = """
1808
1877
let renderNode = translator. visit ( moduleSymbol) as! RenderNode
1809
1878
1810
1879
// Verify that the resolved links rendered as links
1811
- XCTAssertEqual ( renderNode. topicSections. first? . identifiers. count, 2 )
1880
+ XCTAssertEqual ( renderNode. topicSections. first? . identifiers. count, 3 )
1812
1881
XCTAssertEqual ( renderNode. topicSections. first? . identifiers, [
1813
1882
" doc://special-characters/documentation/MyKit/MyClass/myFunc_() " ,
1814
1883
" doc://special-characters/documentation/special-characters/article-with---in-filename " ,
1884
+ " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename " ,
1815
1885
] )
1816
1886
1817
1887
@@ -1826,7 +1896,7 @@ let expected = """
1826
1896
1827
1897
XCTAssertEqual ( lists. count, 1 )
1828
1898
let list = try XCTUnwrap ( lists. first)
1829
- XCTAssertEqual ( list. items. count, 4 , " Unexpected list items: \( list. items. map ( \. content) ) " )
1899
+ XCTAssertEqual ( list. items. count, 6 , " Unexpected list items: \( list. items. map ( \. content) ) " )
1830
1900
1831
1901
func withContentAsReference( _ listItem: RenderBlockContent . ListItem ? , verify: ( RenderReferenceIdentifier , Bool , String ? , [ RenderInlineContent ] ? ) -> Void ) {
1832
1902
guard let listItem = listItem else {
@@ -1866,7 +1936,19 @@ let expected = """
1866
1936
XCTAssertEqual ( overridingTitle, nil )
1867
1937
XCTAssertEqual ( overridingTitleInlineContent, nil )
1868
1938
}
1869
-
1939
+ withContentAsReference ( list. items. dropFirst ( 4 ) . first) { identifier, isActive, overridingTitle, overridingTitleInlineContent in
1940
+ XCTAssertEqual ( identifier. identifier, " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename " )
1941
+ XCTAssertEqual ( isActive, true )
1942
+ XCTAssertEqual ( overridingTitle, nil )
1943
+ XCTAssertEqual ( overridingTitleInlineContent, nil )
1944
+ }
1945
+ withContentAsReference ( list. items. dropFirst ( 5 ) . first) { identifier, isActive, overridingTitle, overridingTitleInlineContent in
1946
+ XCTAssertEqual ( identifier. identifier, " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename#Hello-world " )
1947
+ XCTAssertEqual ( isActive, true )
1948
+ XCTAssertEqual ( overridingTitle, nil )
1949
+ XCTAssertEqual ( overridingTitleInlineContent, nil )
1950
+ }
1951
+
1870
1952
// Verify that the topic render references have titles with special characters when the original content contained special characters
1871
1953
XCTAssertEqual (
1872
1954
( renderNode. references [ " doc://special-characters/documentation/MyKit/MyClass/myFunc_() " ] as? TopicRenderReference ) ? . title,
@@ -1878,12 +1960,20 @@ let expected = """
1878
1960
)
1879
1961
XCTAssertEqual (
1880
1962
( renderNode. references [ " doc://special-characters/documentation/special-characters/article-with---in-filename " ] as? TopicRenderReference ) ? . title,
1881
- " Article with 😃 emoji in file name "
1963
+ " Article with 😃 emoji in its filename "
1882
1964
)
1883
1965
XCTAssertEqual (
1884
1966
( renderNode. references [ " doc://special-characters/documentation/special-characters/article-with---in-filename#Hello-world " ] as? TopicRenderReference ) ? . title,
1885
1967
" Hello world "
1886
1968
)
1969
+ XCTAssertEqual (
1970
+ ( renderNode. references [ " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename " ] as? TopicRenderReference ) ? . title,
1971
+ " Article with various whitespace and punctuation in its filename "
1972
+ )
1973
+ XCTAssertEqual (
1974
+ ( renderNode. references [ " doc://special-characters/documentation/special-characters/Article:-with---various!-whitespace-&-punctuation.-in,-filename#Hello-world " ] as? TopicRenderReference ) ? . title,
1975
+ " Hello world "
1976
+ )
1887
1977
}
1888
1978
1889
1979
func testNonOverloadCollisionFromExtension( ) throws {
0 commit comments