@@ -10,6 +10,22 @@ import Testing
1010
1111@testable import Ignite
1212
13+ /// A site configured with a specific line number visibility for CodeBlock tests.
14+ private struct LineNumbersSite : Site {
15+ var name = " Test "
16+ var url = URL ( static: " https://www.example.com " )
17+ var homePage = TestPage ( )
18+ var layout = EmptyLayout ( )
19+ var syntaxHighlighterConfiguration : SyntaxHighlighterConfiguration
20+
21+ init ( lineNumberVisibility: SyntaxHighlighterConfiguration . LineNumberVisibility = . visible) {
22+ self . syntaxHighlighterConfiguration = SyntaxHighlighterConfiguration (
23+ languages: [ ] ,
24+ lineNumberVisibility: lineNumberVisibility
25+ )
26+ }
27+ }
28+
1329/// Tests for the `CodeBlock` element.
1430@Suite ( " CodeBlock Tests " )
1531@MainActor
@@ -65,4 +81,69 @@ class CodeBlockTests: IgniteTestSuite {
6581 let output = element. markupString ( )
6682 #expect( output. contains ( " data-line= \" 1-3 \" " ) )
6783 }
84+
85+ @Test ( " Code block with mixed highlighted lines and ranges combines data-line values " )
86+ func mixedHighlightedLinesAndRanges( ) {
87+ let element = CodeBlock ( . swift) { " a \n b \n c \n d \n e " }
88+ . highlightedLines ( 1 , 5 , ranges: 2 ... 4 )
89+ let output = element. markupString ( )
90+ #expect( output. contains ( " data-line= \" 1,5,2-4 \" " ) )
91+ }
92+
93+ // MARK: - Line number visibility matrix
94+
95+ @Test ( " Site visible + element hidden adds no-line-numbers class " )
96+ func siteVisibleElementHidden( ) throws {
97+ try PublishingContext . initialize ( for: LineNumbersSite ( ) , from: #filePath)
98+ let element = CodeBlock ( . swift) { " let x = 1 " }
99+ . lineNumberVisibility ( . hidden)
100+ let output = element. markupString ( )
101+ #expect( output. contains ( " no-line-numbers " ) )
102+ }
103+
104+ @Test ( " Site hidden + element visible adds line-numbers class " )
105+ func siteHiddenElementVisible( ) throws {
106+ try PublishingContext . initialize ( for: LineNumbersSite ( lineNumberVisibility: . hidden) , from: #filePath)
107+ let element = CodeBlock ( . swift) { " let x = 1 " }
108+ . lineNumberVisibility ( . visible)
109+ let output = element. markupString ( )
110+ #expect( output. contains ( " line-numbers " ) )
111+ #expect( !output. contains ( " data-start " ) )
112+ }
113+
114+ @Test ( " Site hidden + element visible with custom start adds data-start " )
115+ func siteHiddenElementVisibleCustomStart( ) throws {
116+ try PublishingContext . initialize ( for: LineNumbersSite ( lineNumberVisibility: . hidden) , from: #filePath)
117+ let element = CodeBlock ( . swift) { " let x = 1 " }
118+ . lineNumberVisibility ( . visible( firstLine: 10 , linesWrap: false ) )
119+ let output = element. markupString ( )
120+ #expect( output. contains ( " data-start= \" 10 \" " ) )
121+ }
122+
123+ @Test ( " Site hidden + element visible with wrapping adds pre-wrap style " )
124+ func siteHiddenElementVisibleWrapping( ) throws {
125+ try PublishingContext . initialize ( for: LineNumbersSite ( lineNumberVisibility: . hidden) , from: #filePath)
126+ let element = CodeBlock ( . swift) { " let x = 1 " }
127+ . lineNumberVisibility ( . visible( firstLine: 1 , linesWrap: true ) )
128+ let output = element. markupString ( )
129+ #expect( output. contains ( " white-space: pre-wrap " ) )
130+ }
131+
132+ @Test ( " Both visible with different start lines adds data-start for element value " )
133+ func bothVisibleDifferentStart( ) throws {
134+ try PublishingContext . initialize ( for: LineNumbersSite ( ) , from: #filePath)
135+ let element = CodeBlock ( . swift) { " let x = 1 " }
136+ . lineNumberVisibility ( . visible( firstLine: 5 , linesWrap: false ) )
137+ let output = element. markupString ( )
138+ #expect( output. contains ( " data-start= \" 5 \" " ) )
139+ }
140+
141+ @Test ( " Both visible with different wrapping adds white-space style " )
142+ func bothVisibleDifferentWrapping( ) throws {
143+ try PublishingContext . initialize ( for: LineNumbersSite ( ) , from: #filePath)
144+ let element = CodeBlock ( . swift) { " let x = 1 " }
145+ . lineNumberVisibility ( . visible( firstLine: 1 , linesWrap: true ) )
146+ let output = element. markupString ( )
147+ #expect( output. contains ( " white-space: pre-wrap " ) )
148+ }
68149}
0 commit comments