Skip to content

Commit 7185eef

Browse files
committed
fix: store testcases as table<string[]>
1 parent b35e48c commit 7185eef

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

lua/leetcode-ui/group/case.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local Lines = require("leetcode-ui.lines")
99

1010
local Line = require("leetcode-ui.line")
1111

12-
---@alias case_body { input: string, raw_input: string, output: string, expected: string, std_output: string }
12+
---@alias case_body { input: string[], raw_input: string, output: string, expected: string, std_output: string }
1313

1414
---@class lc.ui.Case : lc.ui.Group
1515
---@field pre lc.ui.Lines
@@ -43,17 +43,16 @@ local function split_input(input)
4343
end
4444

4545
---@private
46-
---@param input string
46+
---@param input string[]
4747
function Case:input(input)
4848
local key = t("Input")
4949

5050
local group = Group({}, { spacing = 1 })
5151

52-
local s = split_input(input)
53-
for i = 1, #s do
52+
for i, case in ipairs(input) do
5453
local ok, param = pcall(function() return self.question.q.meta_data.params[i].name end)
5554
if ok then group:append(param .. " =", "leetcode_normal"):endl() end
56-
group:append(s[i]):endgrp()
55+
group:append(case):endgrp()
5756
end
5857

5958
local title = Line():append(key, "leetcode_normal")

lua/leetcode-ui/popup/console/testcase.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local ConsolePopup = require("leetcode-ui.popup.console")
44
local t = require("leetcode.translator")
55

66
---@class lc.ui.Console.TestcasePopup : lc.ui.Console.Popup
7-
---@field testcases string[]
7+
---@field testcases table<string[][]>
88
---@field extmarks integer[]
99
local Testcase = ConsolePopup:extend("LeetTestcasePopup")
1010

@@ -16,9 +16,10 @@ function Testcase:content()
1616

1717
local testcases = {}
1818
for tcase in vim.gsplit(str, "\n\n") do
19-
local case = tcase:gsub("\n", " ")
20-
table.insert(self.testcases, case)
21-
testcases = vim.list_extend(testcases, vim.split(tcase, "\n"))
19+
local s = vim.split(tcase, "\n")
20+
21+
table.insert(self.testcases, s)
22+
testcases = vim.list_extend(testcases, s)
2223
end
2324

2425
return testcases
@@ -29,8 +30,7 @@ function Testcase:populate()
2930
for i, case in ipairs(self.console.question.q.testcase_list) do
3031
if i ~= 1 then table.insert(tbl, "") end
3132

32-
-- TODO: Think of a better way to do this. Don't store testcases as a single strings
33-
table.insert(self.testcases, case:gsub("\n", " ")[1])
33+
table.insert(self.testcases, vim.split(case, "\n"))
3434

3535
for s in vim.gsplit(case, "\n", { trimempty = true }) do
3636
table.insert(tbl, s)

lua/leetcode/config/template.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
---| "erlang"
2020
---| "elixir"
2121
---| "bash"
22-
---| "html"
23-
---| "pythonml"
24-
---| "react"
25-
---| "vanillajs"
2622

2723
---@alias lc.hook
2824
---| "LeetEnter"

0 commit comments

Comments
 (0)