@@ -1780,3 +1780,120 @@ def test_omit_null_dimensions(self):
17801780
17811781 # dimensionsがNoneの場合は省略
17821782 assert "dimensions" not in sheet
1783+
1784+ def test_search_cells_include_row_data_true (self ):
1785+ """include_row_data=Trueで行データが含まれることのテスト"""
1786+ excel_bytes = self ._create_test_excel ()
1787+ self .mock_download_client .download_file .return_value = excel_bytes
1788+
1789+ parser = SharePointExcelParser (self .mock_download_client )
1790+ result_json = parser .search_cells (
1791+ "/test/file.xlsx" , "John" , include_row_data = True
1792+ )
1793+
1794+ result = json .loads (result_json )
1795+ assert result ["match_count" ] == 1
1796+ match = result ["matches" ][0 ]
1797+ assert match ["coordinate" ] == "A2"
1798+ assert match ["value" ] == "John"
1799+
1800+ # row_dataが含まれる
1801+ assert "row_data" in match
1802+ row_data = match ["row_data" ]
1803+ # A2="John", B2=25 の2セル
1804+ assert len (row_data ) == 2
1805+ coords = [c ["coordinate" ] for c in row_data ]
1806+ assert "A2" in coords
1807+ assert "B2" in coords
1808+ # 値の確認
1809+ values = {c ["coordinate" ]: c ["value" ] for c in row_data }
1810+ assert values ["A2" ] == "John"
1811+ assert values ["B2" ] == 25
1812+
1813+ def test_search_cells_include_row_data_false_default (self ):
1814+ """デフォルト(include_row_data=False)でrow_dataが含まれないことのテスト"""
1815+ excel_bytes = self ._create_test_excel ()
1816+ self .mock_download_client .download_file .return_value = excel_bytes
1817+
1818+ parser = SharePointExcelParser (self .mock_download_client )
1819+ result_json = parser .search_cells ("/test/file.xlsx" , "John" )
1820+
1821+ result = json .loads (result_json )
1822+ assert result ["match_count" ] == 1
1823+ match = result ["matches" ][0 ]
1824+ assert "row_data" not in match
1825+
1826+ def test_search_cells_include_row_data_multiple_matches_same_row (self ):
1827+ """同一行に複数マッチ時、各マッチにrow_dataが含まれることのテスト"""
1828+ wb = Workbook ()
1829+ ws = wb .active
1830+ ws .title = "Sheet1"
1831+ ws ["A1" ] = "売上報告"
1832+ ws ["B1" ] = "売上合計"
1833+ ws ["C1" ] = 1000
1834+
1835+ excel_bytes = BytesIO ()
1836+ wb .save (excel_bytes )
1837+ excel_bytes .seek (0 )
1838+
1839+ self .mock_download_client .download_file .return_value = excel_bytes .getvalue ()
1840+
1841+ parser = SharePointExcelParser (self .mock_download_client )
1842+ result_json = parser .search_cells (
1843+ "/test/file.xlsx" , "売上" , include_row_data = True
1844+ )
1845+
1846+ result = json .loads (result_json )
1847+ assert result ["match_count" ] == 2
1848+
1849+ # 各マッチにrow_dataが独立して含まれる
1850+ for match in result ["matches" ]:
1851+ assert "row_data" in match
1852+ # 同一行なので同じrow_data(A1, B1, C1の3セル)
1853+ assert len (match ["row_data" ]) == 3
1854+
1855+ def test_search_cells_include_row_data_null_cells_excluded (self ):
1856+ """nullセルがrow_dataから除外されることのテスト"""
1857+ wb = Workbook ()
1858+ ws = wb .active
1859+ ws .title = "Sheet1"
1860+ ws ["A1" ] = "Name"
1861+ # B1 is None (null)
1862+ ws ["C1" ] = "Value"
1863+
1864+ excel_bytes = BytesIO ()
1865+ wb .save (excel_bytes )
1866+ excel_bytes .seek (0 )
1867+
1868+ self .mock_download_client .download_file .return_value = excel_bytes .getvalue ()
1869+
1870+ parser = SharePointExcelParser (self .mock_download_client )
1871+ result_json = parser .search_cells (
1872+ "/test/file.xlsx" , "Name" , include_row_data = True
1873+ )
1874+
1875+ result = json .loads (result_json )
1876+ assert result ["match_count" ] == 1
1877+ row_data = result ["matches" ][0 ]["row_data" ]
1878+ # nullセルは除外される(A1とC1のみ)
1879+ coords = [c ["coordinate" ] for c in row_data ]
1880+ assert "A1" in coords
1881+ assert "C1" in coords
1882+ assert "B1" not in coords
1883+
1884+ def test_search_cells_include_row_data_multiple_sheets (self ):
1885+ """複数シート検索時にinclude_row_dataが正しく動作すること"""
1886+ excel_bytes = self ._create_multi_sheet_excel ()
1887+ self .mock_download_client .download_file .return_value = excel_bytes
1888+
1889+ parser = SharePointExcelParser (self .mock_download_client )
1890+ result_json = parser .search_cells (
1891+ "/test/file.xlsx" , "Data" , include_row_data = True
1892+ )
1893+
1894+ result = json .loads (result_json )
1895+ assert result ["match_count" ] == 2
1896+
1897+ for match in result ["matches" ]:
1898+ assert "row_data" in match
1899+ assert len (match ["row_data" ]) >= 1
0 commit comments