Some checks failed
CI / test (push) Has been cancelled
- Removed unused imports from test files (os, pytest, pathlib.Path, MagicMock, patch, numpy, sqlite3, IndexingService) - Updated CI workflow to only check shell-history-semantic-search project files instead of all files in shared src/ and tests/ directories - All 43 tests pass locally
86 lines
2.2 KiB
Python
86 lines
2.2 KiB
Python
import pytest
|
|
from datetime import datetime
|
|
|
|
from shell_history_search.parsers import (
|
|
BashParser,
|
|
ZshParser,
|
|
FishParser,
|
|
parse_shell_history,
|
|
)
|
|
from shell_history_search.models import HistoryEntry
|
|
|
|
|
|
class TestBashParser:
|
|
@pytest.fixture
|
|
def parser(self):
|
|
return BashParser()
|
|
|
|
def test_parse_single_entry(self, parser):
|
|
line = " 1234567890 ls -la"
|
|
entries = parser.parse(line)
|
|
assert len(entries) == 1
|
|
assert entries[0].command == "ls -la"
|
|
|
|
def test_parse_with_heredoc(self, parser):
|
|
line = " 1234567890 cat <<EOF\ndata\nEOF"
|
|
entries = parser.parse(line)
|
|
assert len(entries) == 1
|
|
assert "cat <<EOF" in entries[0].command
|
|
|
|
def test_parse_empty_line(self, parser):
|
|
entries = parser.parse("")
|
|
assert len(entries) == 0
|
|
|
|
def test_parse_whitespace_line(self, parser):
|
|
entries = parser.parse(" \n ")
|
|
assert len(entries) == 0
|
|
|
|
|
|
class TestZshParser:
|
|
@pytest.fixture
|
|
def parser(self):
|
|
return ZshParser()
|
|
|
|
def test_parse_zsh_entry(self, parser):
|
|
line = "; 1234567890; ls -la"
|
|
entries = parser.parse(line)
|
|
assert len(entries) == 1
|
|
assert entries[0].command == "ls -la"
|
|
|
|
def test_parse_multiline_zsh(self, parser):
|
|
lines = [
|
|
"; 1234567890; ls -la",
|
|
"; 1234567891; echo test"
|
|
]
|
|
entries = parser.parse_all(lines)
|
|
assert len(entries) == 2
|
|
|
|
|
|
class TestFishParser:
|
|
@pytest.fixture
|
|
def parser(self):
|
|
return FishParser()
|
|
|
|
def test_parse_fish_entry(self, parser):
|
|
line = "- cmd: ls -la\n when: 1234567890"
|
|
entries = parser.parse(line)
|
|
assert len(entries) == 1
|
|
assert entries[0].command == "ls -la"
|
|
|
|
def test_parse_fish_multiline(self, parser):
|
|
lines = [
|
|
"- cmd: ls -la",
|
|
" when: 1234567890",
|
|
"- cmd: echo test",
|
|
" when: 1234567891"
|
|
]
|
|
entries = parser.parse_all(lines)
|
|
assert len(entries) == 2
|
|
|
|
|
|
class TestParseShellHistory:
|
|
def test_parse_shell_history_auto(self):
|
|
lines = [" 1234567890 ls -la"]
|
|
entries = parse_shell_history(lines, shell='auto')
|
|
assert len(entries) >= 1
|