Step 168: split oversized headers
This commit is contained in:
@@ -46,16 +46,12 @@ int main() {
|
||||
int headerCount = 0;
|
||||
int overs = 0;
|
||||
std::vector<std::string> allowlist = {
|
||||
(srcDir / "ast" / "CppGenerator.h").string(),
|
||||
(srcDir / "ast" / "JavaGenerator.h").string(),
|
||||
(srcDir / "ast" / "JavaScriptGenerator.h").string(),
|
||||
(srcDir / "ast" / "Parser.h").string(),
|
||||
(srcDir / "CodeEditorWidget.h").string(),
|
||||
(srcDir / "EditorState.h").string(),
|
||||
(srcDir / "EditorUtils.h").string(),
|
||||
(srcDir / "panels" / "BottomPanel.h").string(),
|
||||
(srcDir / "panels" / "EditorPanel.h").string(),
|
||||
(srcDir / "SyntaxHighlighter.h").string()
|
||||
(srcDir / "panels" / "EditorPanel.h").string()
|
||||
};
|
||||
for (const auto& entry : fs::recursive_directory_iterator(srcDir)) {
|
||||
if (!entry.is_regular_file()) continue;
|
||||
|
||||
34
editor/tests/step168_integration_test.cpp
Normal file
34
editor/tests/step168_integration_test.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "ast/Parser.h"
|
||||
#include "SyntaxHighlighter.h"
|
||||
|
||||
static void expect(bool cond, const std::string& name, int& passed, int& failed) {
|
||||
if (cond) {
|
||||
std::cout << "Test " << (passed + failed + 1) << " PASS: " << name << "\n";
|
||||
++passed;
|
||||
} else {
|
||||
std::cout << "Test " << (passed + failed + 1) << " FAIL: " << name << "\n";
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int passed = 0;
|
||||
int failed = 0;
|
||||
|
||||
const std::string py = "def f(x):\n return x + 1\n";
|
||||
auto result = TreeSitterParser::parsePythonWithDiagnostics(py);
|
||||
expect(result.module != nullptr, "parsePythonWithDiagnostics returns module", passed, failed);
|
||||
expect(!result.hasErrors(), "parsePythonWithDiagnostics no errors", passed, failed);
|
||||
|
||||
auto spans = SyntaxHighlighter::highlight("def f():\n return 1\n", "python");
|
||||
expect(!spans.empty(), "syntax highlighter returns spans", passed, failed);
|
||||
expect(std::string(SyntaxHighlighter::categoryName(TokenCategory::Keyword)) == "keyword",
|
||||
"categoryName keyword", passed, failed);
|
||||
|
||||
std::cout << "\n=== Step 168 Integration Results: " << passed << " passed, "
|
||||
<< failed << " failed ===\n";
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
83
editor/tests/step168_test.cpp
Normal file
83
editor/tests/step168_test.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
static void expect(bool cond, const std::string& name, int& passed, int& failed) {
|
||||
if (cond) {
|
||||
std::cout << "Test " << (passed + failed + 1) << " PASS: " << name << "\n";
|
||||
++passed;
|
||||
} else {
|
||||
std::cout << "Test " << (passed + failed + 1) << " FAIL: " << name << "\n";
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
|
||||
static int countLines(const std::string& path) {
|
||||
std::ifstream in(path);
|
||||
if (!in.is_open()) return -1;
|
||||
int lines = 0;
|
||||
std::string line;
|
||||
while (std::getline(in, line)) {
|
||||
++lines;
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int passed = 0;
|
||||
int failed = 0;
|
||||
|
||||
const int maxHeaderLines = 600;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
fs::path root = fs::current_path();
|
||||
fs::path srcDir = root / "editor" / "src";
|
||||
if (!fs::exists(srcDir)) {
|
||||
srcDir = root / "src";
|
||||
}
|
||||
|
||||
std::vector<fs::path> headers = {
|
||||
srcDir / "CodeEditorWidget.h",
|
||||
srcDir / "CodeEditorRendering.h",
|
||||
srcDir / "CodeEditorRenderHelpers.h",
|
||||
srcDir / "CodeEditorSelection.h",
|
||||
srcDir / "SyntaxHighlighter.h",
|
||||
srcDir / "SyntaxLanguages.h",
|
||||
srcDir / "SyntaxHighlighterPython.h",
|
||||
srcDir / "SyntaxHighlighterCpp.h",
|
||||
srcDir / "SyntaxHighlighterJavaScript.h",
|
||||
srcDir / "SyntaxHighlighterJava.h",
|
||||
srcDir / "SyntaxHighlighterRust.h",
|
||||
srcDir / "SyntaxHighlighterGo.h",
|
||||
srcDir / "SyntaxHighlighterElisp.h",
|
||||
srcDir / "SyntaxHighlighterOrg.h",
|
||||
srcDir / "ast" / "Parser.h",
|
||||
srcDir / "ast" / "PythonParser.h",
|
||||
srcDir / "ast" / "CppParser.h",
|
||||
srcDir / "ast" / "ElispParser.h",
|
||||
srcDir / "ast" / "JavaScriptParser.h",
|
||||
srcDir / "ast" / "TypeScriptParser.h",
|
||||
srcDir / "ast" / "JavaParser.h",
|
||||
srcDir / "ast" / "RustParser.h",
|
||||
srcDir / "ast" / "GoParser.h",
|
||||
srcDir / "ast" / "CppGenerator.h",
|
||||
srcDir / "ast" / "CppGeneratorTypes.h",
|
||||
};
|
||||
|
||||
for (const auto& path : headers) {
|
||||
expect(fs::exists(path), "exists " + path.string(), passed, failed);
|
||||
int lines = countLines(path.string());
|
||||
expect(lines > 0, "read " + path.string(), passed, failed);
|
||||
if (lines > 0) {
|
||||
expect(lines <= maxHeaderLines,
|
||||
"line limit " + path.string() + " (" + std::to_string(lines) + ")",
|
||||
passed, failed);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "\n=== Step 168 Results: " << passed << " passed, "
|
||||
<< failed << " failed ===\n";
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user