@@ -200,6 +200,80 @@ class RenderContentMetadataTests: XCTestCase {
200200
201201 try assertRoundTripCoding ( renderedTable)
202202 }
203+
204+ /// Verifies that a table with `nil` alignments and a table with all-unset alignments still compare as equal.
205+ func testRenderedTableEquality( ) throws {
206+ let ( bundle, context) = try testBundleAndContext ( named: " TestBundle " )
207+ var renderContentCompiler = RenderContentCompiler ( context: context, bundle: bundle, identifier: ResolvedTopicReference ( bundleIdentifier: bundle. identifier, path: " /path " , fragment: nil , sourceLanguage: . swift) )
208+
209+ let source = """
210+ | Column 1 | Column 2 |
211+ | ------------- | ------------- |
212+ | Cell 1 | Cell 2 |
213+ | Cell 3 | Cell 4 |
214+ """
215+ let document = Document ( parsing: source)
216+
217+ let result = try XCTUnwrap ( renderContentCompiler. visit ( document. child ( at: 0 ) !) )
218+ let renderedTable = try XCTUnwrap ( result. first as? RenderBlockContent )
219+ guard case let . table( decodedTable) = renderedTable else {
220+ XCTFail ( " Unexpected RenderBlockContent element " )
221+ return
222+ }
223+ XCTAssertNil ( decodedTable. alignments)
224+ var modifiedTable = decodedTable
225+ modifiedTable. alignments = [ . unset, . unset]
226+
227+ XCTAssertEqual ( decodedTable, modifiedTable)
228+ }
229+
230+ /// Verifies that two tables with otherwise-identical contents but different column alignments compare as unequal.
231+ func testRenderedTableInequality( ) throws {
232+ let ( bundle, context) = try testBundleAndContext ( named: " TestBundle " )
233+ var renderContentCompiler = RenderContentCompiler ( context: context, bundle: bundle, identifier: ResolvedTopicReference ( bundleIdentifier: bundle. identifier, path: " /path " , fragment: nil , sourceLanguage: . swift) )
234+
235+ let decodedTableWithUnsetColumns : RenderBlockContent . Table
236+ do {
237+ let source = """
238+ | Column 1 | Column 2 |
239+ | ------------- | ------------- |
240+ | Cell 1 | Cell 2 |
241+ | Cell 3 | Cell 4 |
242+ """
243+ let document = Document ( parsing: source)
244+
245+ let result = try XCTUnwrap ( renderContentCompiler. visit ( document. child ( at: 0 ) !) )
246+ let renderedTable = try XCTUnwrap ( result. first as? RenderBlockContent )
247+ guard case let . table( decodedTable) = renderedTable else {
248+ XCTFail ( " Unexpected RenderBlockContent element " )
249+ return
250+ }
251+ decodedTableWithUnsetColumns = decodedTable
252+ }
253+
254+ let decodedTableWithLeftColumns : RenderBlockContent . Table
255+ do {
256+ let source = """
257+ | Column 1 | Column 2 |
258+ | :------------ | :------------ |
259+ | Cell 1 | Cell 2 |
260+ | Cell 3 | Cell 4 |
261+ """
262+ let document = Document ( parsing: source)
263+
264+ // Verifies that a markdown table renders correctly.
265+
266+ let result = try XCTUnwrap ( renderContentCompiler. visit ( document. child ( at: 0 ) !) )
267+ let renderedTable = try XCTUnwrap ( result. first as? RenderBlockContent )
268+ guard case let . table( decodedTable) = renderedTable else {
269+ XCTFail ( " Unexpected RenderBlockContent element " )
270+ return
271+ }
272+ decodedTableWithLeftColumns = decodedTable
273+ }
274+
275+ XCTAssertNotEqual ( decodedTableWithUnsetColumns, decodedTableWithLeftColumns)
276+ }
203277
204278 func testStrikethrough( ) throws {
205279 let ( bundle, context) = try testBundleAndContext ( named: " TestBundle " )
0 commit comments