-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.lua
More file actions
154 lines (140 loc) · 4.18 KB
/
Copy pathrun_tests.lua
File metadata and controls
154 lines (140 loc) · 4.18 KB
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
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env lua
-- Simple test runner
package.path = "./?.lua;./lua/?.lua;./lua/ansillary/?.lua;./tests/?.lua;" .. package.path
-- Load test helper and set up mocks
local helper = require("tests.test_helper")
helper.setup_vim_mock()
-- Simple test framework
local tests_passed = 0
local tests_failed = 0
local current_describe = ""
local function describe(name, fn)
current_describe = name
print("\n" .. name)
fn()
end
local function it(name, fn)
local success, err = pcall(fn)
if success then
print(" ✓ " .. name)
tests_passed = tests_passed + 1
else
print(" ✗ " .. name .. ": " .. tostring(err))
tests_failed = tests_failed + 1
end
end
-- Mock assert functions
local assert = {}
assert.are = {}
assert.are.equal = function(expected, actual, message)
if expected ~= actual then
error((message or "") .. " Expected: " .. tostring(expected) .. ", got: " .. tostring(actual))
end
end
assert.is_true = function(value, message)
if not value then
error((message or "") .. " Expected true, got: " .. tostring(value))
end
end
assert.is_false = function(value, message)
if value then
error((message or "") .. " Expected false, got: " .. tostring(value))
end
end
assert.is_nil = function(value, message)
if value ~= nil then
error((message or "") .. " Expected nil, got: " .. tostring(value))
end
end
assert.is_not_nil = function(value, message)
if value == nil then
error((message or "") .. " Expected not nil, got nil")
end
end
assert.is_table = function(value, message)
if type(value) ~= "table" then
error((message or "") .. " Expected table, got: " .. type(value))
end
end
assert.is_string = function(value, message)
if type(value) ~= "string" then
error((message or "") .. " Expected string, got: " .. type(value))
end
end
assert.is_boolean = function(value, message)
if type(value) ~= "boolean" then
error((message or "") .. " Expected boolean, got: " .. type(value))
end
end
assert.are.same = function(expected, actual, message)
-- Simple table comparison
if type(expected) ~= type(actual) then
error((message or "") .. " Type mismatch")
end
if type(expected) == "table" then
for k, v in pairs(expected) do
if actual[k] ~= v then
error((message or "") .. " Table mismatch at key " .. tostring(k))
end
end
for k, v in pairs(actual) do
if expected[k] == nil then
error((message or "") .. " Unexpected key " .. tostring(k))
end
end
else
if expected ~= actual then
error((message or "") .. " Expected: " .. tostring(expected) .. ", got: " .. tostring(actual))
end
end
end
assert.has_no = {}
assert.has_no.errors = function(fn, message)
local success, err = pcall(fn)
if not success then
error((message or "") .. " Unexpected error: " .. tostring(err))
end
end
-- Make assert global
_G.assert = assert
_G.describe = describe
_G.it = it
-- Test basic functionality
describe("Basic functionality test", function()
it("should load regex module", function()
local regex = require("ansillary.regex")
assert.is_table(regex)
end)
it("should load config module", function()
local config = require("ansillary.config")
assert.is_table(config)
assert.is_boolean(config.conceal)
end)
it("should load highlights module", function()
local highlights = require("ansillary.highlights")
assert.is_table(highlights)
end)
it("should load main module", function()
local ansillary = require("ansillary.init")
assert.is_table(ansillary)
end)
end)
-- Test ANSI parsing with literal escape characters
describe("ANSI parsing", function()
it("should parse literal ESC sequences", function()
local regex = require("ansillary.regex")
-- Test with actual ESC character (ASCII 27)
local line = string.char(27) .. "[31mred" .. string.char(27) .. "[0m"
local start_pos, end_pos, code = regex.find_ansi_sequence(line, 1)
assert.is_not_nil(start_pos, "Should find ANSI sequence")
assert.are.equal("31", code)
end)
end)
-- Print results summary
print(string.format("\n\nTest Results: %d passed, %d failed", tests_passed, tests_failed))
if tests_failed > 0 then
os.exit(1)
else
print("All tests passed!")
os.exit(0)
end