Skip to content

Commit 119ec35

Browse files
committed
feat: norm_ins
1 parent ba871c0 commit 119ec35

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

lua/leetcode-ui/group/case.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ local Case = Group:extend("LeetCase")
2222

2323
---@private
2424
---@param input string[]
25-
function Case:input(input) return Input("Input", input, self.question.q.meta_data.params) end
25+
function Case:input(input)
26+
input = vim.tbl_map(utils.norm_ins, input)
27+
return Input("Input", input, self.question.q.meta_data.params)
28+
end
2629

2730
---@private
2831
---@param output string
@@ -31,7 +34,7 @@ function Case:output(output, expected)
3134
local key = t("Output")
3235

3336
local title = Line():append(key, "leetcode_normal")
34-
local pre = Pre(title, Line():append(output))
37+
local pre = Pre(title, Line():append(utils.norm_ins(output)))
3538

3639
return pre
3740
end
@@ -43,7 +46,7 @@ function Case:expected(expected, output)
4346
local key = t("Expected")
4447
local title = Line():append(key, "leetcode_normal")
4548

46-
local pre = Pre(title, Line():append(expected))
49+
local pre = Pre(title, Line():append(utils.norm_ins(expected)))
4750

4851
return pre
4952
end

lua/leetcode-ui/group/pre/stdout.lua

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ local Pre = require("leetcode-ui.group.pre")
22
local t = require("leetcode.translator")
33
local Line = require("leetcode-ui.line")
44
local Lines = require("leetcode-ui.lines")
5+
6+
local utils = require("leetcode.utils")
57
local log = require("leetcode.logger")
68

79
---@class lc.ui.Stdout : lc.ui.Pre
810
local Stdout = Pre:extend("LeetStdout")
911

10-
local function norm(str)
11-
local ins = vim.inspect(str)
12-
return ins:sub(2, #ins - 1)
13-
end
14-
1512
---@param output string
1613
---
1714
---@return lc.ui.Lines | nil
@@ -25,7 +22,7 @@ function Stdout:init(output)
2522

2623
local lines = Lines()
2724
for i = 1, #output_list do
28-
lines:append(norm(output_list[i])):endl()
25+
lines:append(utils.norm_ins(output_list[i])):endl()
2926
end
3027

3128
local title = Line():append((" %s"):format(t("Stdout")), "leetcode_alt")

lua/leetcode/utils.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,9 @@ end
9898

9999
function utils.auth_guard() assert(config.auth.is_signed_in, "User not logged-in") end
100100

101+
function utils.norm_ins(str)
102+
local ins = vim.inspect(str)
103+
return ins:sub(2, #ins - 1)
104+
end
105+
101106
return utils

0 commit comments

Comments
 (0)