# Copyright 2026 jCloud # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import pytest from src.jcloud_docsgen.utils import markdown_table @pytest.mark.parametrize( ( 'header,body,allow_markdown_table,force_row_le' 'ngths,one_line_values,missing_value,expected' ), [ ( [], [], False, False, True, '--', '', ), ( [], [('a',)], False, False, True, '--', '', ), ( ['a'], [], False, False, True, '--', '', ), ( ['a'], [(1,)], True, False, True, '--', """| a | | --- | | 1 |""", ), ( ['a'], [(1, 2)], True, False, True, '--', """| a | | --- | | 1 |""", ), ( ['a', 'b'], [(1, 2)], True, False, True, '--', """| a | b | | --- | --- | | 1 | 2 |""", ), ( ['a', 'b'], [(1,)], True, False, True, '--', """| a | b | | --- | --- | | 1 | -- |""", ), ( ['a', 'b'], [()], True, False, True, '--', """| a | b | | --- | --- | | -- | -- |""", ), ( ['a', 'b'], [(1, 2), (3, 4)], True, False, True, '--', """| a | b | | --- | --- | | 1 | 2 | | 3 | 4 |""", ), ( ['a'], [('line1\nline2',)], True, False, True, '--', """| a | | --- | | line1 line2 |""", ), ( ['a'], [('line1\nline2',)], True, False, False, '--', """| a | | --- | | line1\nline2 |""", ), ( ['a'], [('line1\nline2 | 2',)], True, False, False, '--', """| a | | --- | | line1\nline2 \\| 2 |""", ), ( ['a'], [('line1\nline2 | 2',)], True, False, True, '--', """| a | | --- | | line1 line2 \\| 2 |""", ), ( ['a'], [('1 | 2',)], True, False, True, '--', """| a | | --- | | 1 \\| 2 |""", ), ( ['a'], [('1 |',)], True, False, True, '--', """| a | | --- | | 1 \\| |""", ), ( ['a'], [('|',)], True, False, True, '--', """| a | | --- | | \\| |""", ), ( ['a'], [('| 2',)], True, False, True, '--', """| a | | --- | | \\| 2 |""", ), ( [], [], False, False, True, '--', '', ), ( [], [('a',)], False, False, True, '--', '', ), ( ['a'], [], False, False, True, '--', '', ), ( ['a'], [(1,)], False, False, True, '--', '- a: 1', ), ( ['a'], [(1, 2)], False, False, True, '--', '- a: 1', ), ( ['a', 'b'], [(1, 2)], False, False, True, '--', """- a: 1 b: 2""", ), ( ['a', 'b'], [(1,)], False, False, True, '--', """- a: 1 b: --""", ), ( ['a', 'b'], [()], False, False, True, '--', """- a: -- b: --""", ), ( ['a', 'b'], [(1, 2), (3, 4)], False, False, True, '--', """- a: 1 b: 2 - a: 3 b: 4""", ), ( ['a'], [('line1\nline2',)], False, False, True, '--', '- a: line1 line2', ), ( ['a'], [('line1\nline2',)], False, False, False, '--', '- a: line1\nline2', ), ], ) def test_markdown_table( header, body, allow_markdown_table, force_row_lengths, one_line_values, missing_value, expected, ): assert ( markdown_table( header, body, allow_markdown_table=allow_markdown_table, force_row_lengths=force_row_lengths, one_line_values=one_line_values, missing_value=missing_value, ) == expected ) @pytest.mark.parametrize( ( 'header,body,allow_markdown_table,force_row_lengths,one_line_v' 'alues,missing_value,expected_exception,expected_exception_msg' ), [ ( ['a'], [(1, 2)], True, True, True, '--', ValueError, 'expected 1 value, got 2', ), ( ['a'], [(1, 2, 3)], True, True, True, '--', ValueError, 'expected 1 value, got 3', ), ( ['a'], [()], True, True, True, '--', ValueError, 'expected 1 value, got 0', ), ( ['a', 'b'], [()], True, True, True, '--', ValueError, 'expected 2 values, got 0', ), ( ['a', 'b'], [(1,)], True, True, True, '--', ValueError, 'expected 2 values, got 1', ), ( ['a', 'b'], [(1, 2, 3)], True, True, True, '--', ValueError, 'expected 2 values, got 3', ), ( ['a'], [(1, 2)], False, True, True, '--', ValueError, 'expected 1 value, got 2', ), ( ['a'], [(1, 2, 3)], False, True, True, '--', ValueError, 'expected 1 value, got 3', ), ( ['a'], [()], False, True, True, '--', ValueError, 'expected 1 value, got 0', ), ( ['a', 'b'], [()], False, True, True, '--', ValueError, 'expected 2 values, got 0', ), ( ['a', 'b'], [(1,)], False, True, True, '--', ValueError, 'expected 2 values, got 1', ), ( ['a', 'b'], [(1, 2, 3)], False, True, True, '--', ValueError, 'expected 2 values, got 3', ), ], ) def test_markdown_table_exceptions( header, body, allow_markdown_table, force_row_lengths, one_line_values, missing_value, expected_exception, expected_exception_msg, ): with pytest.raises(expected_exception) as exc_info: markdown_table( header, body, allow_markdown_table=allow_markdown_table, force_row_lengths=force_row_lengths, one_line_values=one_line_values, missing_value=missing_value, ) assert str(exc_info.value) == expected_exception_msg