import pytest from cmdparse.parser import parse_table, parse_key_value, parse_delimited, parse_raw, parse_text def test_parse_table_with_pipes(): """Test parsing table with pipe separators.""" text = "| Name | Age | City |\n| Alice | 30 | NYC |\n| Bob | 25 | LA |" result = parse_table(text) assert len(result) == 2 assert result[0]['Name'] == 'Alice' assert result[1]['Name'] == 'Bob' def test_parse_table_without_pipes(): """Test parsing table without pipe separators.""" text = "Name Age City\nAlice 30 NYC\nBob 25 LA" result = parse_table(text) assert len(result) == 2 assert result[0]['Name'] == 'Alice' def test_parse_key_value_colon(): """Test parsing key-value with colon delimiter.""" text = "key1: value1\nkey2: value2" result = parse_key_value(text, ':') assert len(result) == 1 assert result[0]['key1'] == 'value1' def test_parse_key_value_equals(): """Test parsing key-value with equals delimiter.""" text = "key1=value1\nkey2=value2" result = parse_key_value(text, '=') assert len(result) == 1 assert result[0]['key1'] == 'value1' def test_parse_delimited_comma(): """Test parsing comma-delimited text.""" text = "name,age,city\nalice,30,nyc\nbob,25,la" result = parse_delimited(text, ',') assert len(result) == 2 assert result[0]['name'] == 'alice' def test_parse_raw(): """Test parsing raw text.""" text = "line1\nline2\nline3" result = parse_raw(text) assert len(result) == 3 assert result[0]['content'] == 'line1' def test_parse_text_auto_detect_table(): """Test auto-detection of table format.""" text = "| Header |\n| Value |" data, detected = parse_text(text) assert detected == 'table' def test_parse_text_auto_detect_key_value(): """Test auto-detection of key-value format.""" text = "key: value" data, detected = parse_text(text) assert detected in ('key_value_colon', 'key_value_block') def test_parse_text_empty_input(): """Test handling of empty input.""" data, detected = parse_text("") assert data == [] assert detected == 'empty'