From 91e066bbd6dc9dd782f1b9730685879d5e529346 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 18 Sep 2025 13:30:53 -0400 Subject: [PATCH] fix(scraper/codeforces): scrape multiple tc --- after/ftplugin/cptest.lua | 2 +- lua/cp/init.lua | 23 ++++++++++++----------- scrapers/atcoder.py | 3 +-- scrapers/codeforces.py | 11 ++++++----- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/after/ftplugin/cptest.lua b/after/ftplugin/cptest.lua index 166db14..35831f4 100644 --- a/after/ftplugin/cptest.lua +++ b/after/ftplugin/cptest.lua @@ -2,6 +2,6 @@ vim.opt_local.number = false vim.opt_local.relativenumber = false vim.opt_local.statuscolumn = "" vim.opt_local.signcolumn = "no" -vim.opt_local.foldcolumn = "0" vim.opt_local.wrap = true vim.opt_local.linebreak = true +vim.opt_local.foldcolumn = "0" diff --git a/lua/cp/init.lua b/lua/cp/init.lua index 3b2534a..68c9e8a 100644 --- a/lua/cp/init.lua +++ b/lua/cp/init.lua @@ -193,19 +193,20 @@ local function toggle_test_panel(is_debug) vim.api.nvim_win_set_buf(main_win, tab_buf) vim.api.nvim_set_option_value("filetype", "cptest", { buf = tab_buf }) - vim.cmd("split") - local content_win = vim.api.nvim_get_current_win() - vim.api.nvim_win_set_buf(content_win, actual_buf) + vim.cmd.split() + vim.api.nvim_win_set_buf(0, actual_buf) vim.api.nvim_set_option_value("filetype", "cptest", { buf = actual_buf }) - vim.cmd("vsplit") - local expected_win = vim.api.nvim_get_current_win() - vim.api.nvim_win_set_buf(expected_win, expected_buf) + vim.cmd.vsplit() + vim.api.nvim_win_set_buf(0, expected_buf) vim.api.nvim_set_option_value("filetype", "cptest", { buf = expected_buf }) + local expected_win = vim.fn.bufwinid(expected_buf) + local actual_win = vim.fn.bufwinid(actual_buf) + local test_windows = { tab_win = main_win, - actual_win = content_win, + actual_win = actual_win, expected_win = expected_win, } local test_buffers = { @@ -319,10 +320,10 @@ local function toggle_test_panel(is_debug) if enable_diff then vim.api.nvim_win_call(test_windows.expected_win, function() - vim.cmd("diffthis") + vim.cmd.diffthis() end) vim.api.nvim_win_call(test_windows.actual_win, function() - vim.cmd("diffthis") + vim.cmd.diffthis() end) end end @@ -355,10 +356,10 @@ local function toggle_test_panel(is_debug) refresh_test_panel() end - vim.keymap.set("n", "j", function() + vim.keymap.set("n", "", function() navigate_test_case(1) end, { buffer = test_buffers.tab_buf, silent = true }) - vim.keymap.set("n", "k", function() + vim.keymap.set("n", "", function() navigate_test_case(-1) end, { buffer = test_buffers.tab_buf, silent = true }) diff --git a/scrapers/atcoder.py b/scrapers/atcoder.py index 2166f55..3c86565 100644 --- a/scrapers/atcoder.py +++ b/scrapers/atcoder.py @@ -200,8 +200,7 @@ def main() -> None: test_list: list[dict[str, str]] = [] for input_data, output_data in tests: - normalized_input = "1\n" + input_data - test_list.append({"input": normalized_input, "expected": output_data}) + test_list.append({"input": input_data, "expected": output_data}) result = { "success": True, diff --git a/scrapers/codeforces.py b/scrapers/codeforces.py index 2a4e502..f8e2290 100644 --- a/scrapers/codeforces.py +++ b/scrapers/codeforces.py @@ -32,11 +32,12 @@ def scrape(url: str) -> list[tuple[str, str]]: continue for div in test_line_divs: + classes = div.get("class", []) class_name = next( ( cls - for cls in div.get("class", []) - if "test-example-line-" in cls + for cls in classes + if "test-example-line-" in cls and cls.split("-")[-1].isdigit() ), None, ) @@ -60,11 +61,12 @@ def scrape(url: str) -> list[tuple[str, str]]: continue for div in test_line_divs: + classes = div.get("class", []) class_name = next( ( cls - for cls in div.get("class", []) - if "test-example-line-" in cls + for cls in classes + if "test-example-line-" in cls and cls.split("-")[-1].isdigit() ), None, ) @@ -88,7 +90,6 @@ def scrape(url: str) -> list[tuple[str, str]]: prefixed_input = "1\n" + input_text tests.append((prefixed_input, output_text)) return tests - all_inputs = [] all_outputs = []