File size: 4,277 Bytes
53b2ac9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# SPDX-License-Identifier: MIT
"""Tests for new TrashClaw plugins: markdown_table, text_diff, timer."""
import sys
import os
import unittest
import pytest

# Add project root to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))


class TestMarkdownTable:
    """Tests for the markdown_table plugin."""

    def setup_method(self):
        from plugins.markdown_table import run
        self.run = run

    def test_basic_csv(self):
        result = self.run(data="Name,Age,City\nAlice,30,NYC\nBob,25,LA")
        assert "| Name" in result
        assert "| Alice" in result
        assert "---" in result

    def test_tab_separated(self):
        result = self.run(data="Col1\tCol2\nA\tB")
        assert "| Col1" in result
        assert "| A" in result

    def test_custom_delimiter(self):
        result = self.run(data="a;b;c\n1;2;3", delimiter=";")
        assert "| a" in result

    def test_right_align(self):
        result = self.run(data="X,Y\n1,2", align="right")
        assert "-:" in result

    def test_center_align(self):
        result = self.run(data="X,Y\n1,2", align="center")
        assert ":-" in result and "-:" in result

    def test_empty_data(self):
        result = self.run(data="")
        assert "Error" in result

    def test_single_row(self):
        result = self.run(data="Header1,Header2")
        assert "| Header1" in result

    def test_uneven_columns(self):
        result = self.run(data="A,B,C\n1,2\n3,4,5")
        assert "| A" in result


class TestTextDiff:
    """Tests for the text_diff plugin."""

    def setup_method(self):
        from plugins.text_diff import run
        self.run = run

    def test_identical_texts(self):
        result = self.run(text_a="hello", text_b="hello")
        assert "identical" in result.lower()

    def test_single_line_change(self):
        result = self.run(text_a="hello world", text_b="hello earth")
        assert "-hello world" in result
        assert "+hello earth" in result

    def test_multiline_diff(self):
        a = "line1\nline2\nline3"
        b = "line1\nchanged\nline3"
        result = self.run(text_a=a, text_b=b)
        assert "-line2" in result
        assert "+changed" in result

    def test_added_lines(self):
        a = "line1\nline2"
        b = "line1\nline2\nline3"
        result = self.run(text_a=a, text_b=b)
        assert "+line3" in result

    def test_empty_to_content(self):
        result = self.run(text_a="", text_b="new content")
        assert "+new content" in result

    def test_custom_context(self):
        a = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"
        b = "1\n2\n3\n4\nX\n6\n7\n8\n9\n10"
        result = self.run(text_a=a, text_b=b, context_lines=1)
        assert "@@" in result


class TestTimer:
    """Tests for the timer plugin."""

    def setup_method(self):
        from plugins.timer import run, _timers
        self.run = run
        _timers.clear()

    def test_start(self):
        result = self.run(action="start", name="test1")
        assert "started" in result.lower()

    def test_check(self):
        self.run(action="start", name="test1")
        result = self.run(action="check", name="test1")
        assert "elapsed" in result.lower()

    def test_stop(self):
        self.run(action="start", name="test1")
        result = self.run(action="stop", name="test1")
        assert "stopped" in result.lower()

    def test_check_nonexistent(self):
        result = self.run(action="check", name="nope")
        assert "not found" in result.lower()

    def test_stop_nonexistent(self):
        result = self.run(action="stop", name="nope")
        assert "not found" in result.lower()

    def test_list_empty(self):
        result = self.run(action="list")
        assert "no active" in result.lower()

    def test_list_active(self):
        self.run(action="start", name="t1")
        self.run(action="start", name="t2")
        result = self.run(action="list")
        assert "t1" in result
        assert "t2" in result

    def test_unknown_action(self):
        result = self.run(action="invalid")
        assert "unknown" in result.lower()

class TestUntestedTool(unittest.TestCase):
    def test_untested_tool(self):
        # Implement test cases here
        pass