Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions gitgalaxy/standards/language_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -11275,7 +11275,7 @@ class PrismConfigSchema(TypedDict):
"rules": {
# --- PHASE 1: LOGIC TOPOLOGY & STRUCTURE ---
"branch": re.compile(r"\b(if|else|switch|case|for|while|do)\b|\|"),
"args": re.compile(r"\$\d+|\$\$"),
"args": re.compile(r"(?<!\$)(?:\$\d+|\$\$)(?!\$|\d)"),
"structural_boundaries": re.compile(
r"\b(return|goto|break|continue)\b|%token\b|%type\b|%left\b|%right\b|%nonassoc\b"
),
Expand All @@ -11284,7 +11284,8 @@ class PrismConfigSchema(TypedDict):
# Excludes C/C++ constructs that share the identical "identifier:" shape
# (switch-case default labels, C++ access specifiers in embedded .ypp code).
"func_start": re.compile(
r"^[ \t]*(?!(?:case|default|public|private|protected)\b)([a-zA-Z_]\w*)(?=[ \t]*:)", re.M
r"^[ \t]*(?!(?:case|default|public|private|protected)\b)([a-zA-Z_]\w*)(?=(?:[ \t\n]|/\*(?:[^*]|\*[^/])*\*/)*:)",
re.M,
),
"class_start": None,
# --- PHASE 2: RISK & STRUCTURAL INTEGRITY ---
Expand Down
91 changes: 91 additions & 0 deletions tests/extraction/languages/test_yacc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import sys
from pathlib import Path

# Add tests/ to sys.path to allow importing _extraction_harness
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))

import pytest
from extraction._extraction_harness import (
assert_invalid_no_match,
assert_pathological_match,
assert_valid_match,
)

from gitgalaxy.standards.language_standards import LANGUAGE_DEFINITIONS

FUNCTION_CASES = {
"valid": [
("TargetFunc:", "TargetFunc"),
("TargetFunc :", "TargetFunc"),
("TargetFunc\n:", "TargetFunc"),
("TargetFunc /* comment */ :", "TargetFunc"),
("TargetFunc_1:", "TargetFunc_1"),
],
"invalid": [
"%token TargetFunc",
"case TargetFunc:",
"default:",
"public:",
"private:",
"protected:",
"// TargetFunc:",
'"TargetFunc:"',
],
"pathological": [
("TargetFunc \t :", "TargetFunc"),
],
}

ARGS_CASES = {
"valid": [
("$1", "$1"),
("$$", "$$"),
("$23", "$23"),
],
"invalid": [
"var",
"$$$",
"$_1",
],
"pathological": [],
}

CLASS_CASES = {"valid": [], "invalid": [], "pathological": []}

DEPENDENCY_CASES = {"valid": [], "invalid": [], "pathological": []}


@pytest.mark.parametrize("case", FUNCTION_CASES["valid"])
def test_valid_function_extraction(case):
pattern = LANGUAGE_DEFINITIONS["yacc"]["rules"]["func_start"]
assert_valid_match(pattern, case[0], case[1], "yacc.func_start")


@pytest.mark.parametrize("case", FUNCTION_CASES["invalid"])
def test_invalid_function_extraction(case):
pattern = LANGUAGE_DEFINITIONS["yacc"]["rules"]["func_start"]
assert_invalid_no_match(pattern, case, "yacc.func_start")


@pytest.mark.parametrize("case", FUNCTION_CASES["pathological"])
def test_pathological_function_extraction(case):
pattern = LANGUAGE_DEFINITIONS["yacc"]["rules"]["func_start"]
assert_pathological_match(pattern, case[0], case[1], "yacc.func_start")


@pytest.mark.parametrize("case", ARGS_CASES["valid"])
def test_valid_args_extraction(case):
pattern = LANGUAGE_DEFINITIONS["yacc"]["rules"]["args"]
assert_valid_match(pattern, case[0], case[1], "yacc.args")


@pytest.mark.parametrize("case", ARGS_CASES["invalid"])
def test_invalid_args_extraction(case):
pattern = LANGUAGE_DEFINITIONS["yacc"]["rules"]["args"]
assert_invalid_no_match(pattern, case, "yacc.args")


@pytest.mark.parametrize("case", ARGS_CASES["pathological"])
def test_pathological_args_extraction(case):
pattern = LANGUAGE_DEFINITIONS["yacc"]["rules"]["args"]
assert_pathological_match(pattern, case[0], case[1], "yacc.args")
6 changes: 1 addition & 5 deletions tests/extraction/test_function_extraction_strict.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@
"pathological": [("//TargetFunc \t EXEC ", "TargetFunc")],
},

"yacc": {
"valid": [("TargetFunc:", "TargetFunc")],
"invalid": ["%token TargetFunc", "case TargetFunc:"],
"pathological": [("TargetFunc \t :", "TargetFunc")],
},

"css": {
"valid": [("@media (max-width: 600px) {", "@media"), ("@keyframes TargetFunc {", "@keyframes")],
"invalid": [".TargetFunc {", "#TargetFunc {"],
Expand Down
Loading