2026-07-08 10:01:58 +02:00
|
|
|
## Common test patterns for Nimcheck tests.
|
feat: add initial validatrix project with multi-language validator framework
Establish the Validatrix source code validation framework in Nim, including core detection, tokenization, and validation infrastructure for 10 languages (bash, HTML, JavaScript, Jinja, JSON, Nim, PHP, Python, TOML, YAML). The initial commit introduces the main validatrix.nim entry point with public API (validateSource, validateFile, inspectSource), a comprehensive test suite with per-language test files, build configuration via Makefile and .nimble, detailed LESSONS_LEARNED.md documenting 14 bug classes found during development, and a .gitignore excluding compiled binaries, logs, and build artifacts. The detector module provides extension-to-flavor mapping for 40+ file extensions and content-based language detection, while the debug module supports conditional compilation with -d:validatrixDebug for detailed tokenization logging.
2026-07-08 06:25:59 +02:00
|
|
|
## This module provides code snippets used across test suites.
|
|
|
|
|
## Import it, then reference the const values directly.
|
|
|
|
|
|
|
|
|
|
import std/[strutils, json]
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
NimGoodCode* = """
|
|
|
|
|
proc add*(a, b: int): int =
|
|
|
|
|
## Add two numbers.
|
|
|
|
|
result = a + b
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
NimBadCode* = """
|
|
|
|
|
proc add*(a, b: int): int =
|
|
|
|
|
## Add two numbers.
|
|
|
|
|
result = a + b
|
|
|
|
|
let x = "
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
BashGoodCode* = """
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
echo "Hello, world!"
|
|
|
|
|
for i in 1 2 3; do
|
|
|
|
|
echo $i
|
|
|
|
|
done
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
BashBadCode* = """
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
echo ${unclosed
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
PythonGoodCode* = """
|
|
|
|
|
def hello(name: str) -> str:
|
|
|
|
|
return f"Hello, {name}!"
|
|
|
|
|
|
|
|
|
|
class Greeter:
|
|
|
|
|
def __init__(self, prefix: str):
|
|
|
|
|
self.prefix = prefix
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
PythonBadCode* = """
|
|
|
|
|
def broken():
|
|
|
|
|
x = "
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
JsGoodCode* = """
|
|
|
|
|
function greet(name) {
|
|
|
|
|
return `Hello, ${name}!`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nums = [1, 2, 3];
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
JsBadCode* = """
|
|
|
|
|
function broken() {
|
|
|
|
|
const x = `
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
PhpGoodCode* = """
|
|
|
|
|
<?php
|
|
|
|
|
function greet(string $name): string {
|
|
|
|
|
return "Hello, $name!";
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
PhpBadCode* = """<?php
|
|
|
|
|
$a = "unclosed_end"""
|
|
|
|
|
|
|
|
|
|
HtmlGoodCode* = """
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<head><title>Test</title></head>
|
|
|
|
|
<body><p>Hello</p></body>
|
|
|
|
|
</html>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
HtmlBadCode* = """
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<body><p>Unclosed tag
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
JinjaGoodCode* = """
|
|
|
|
|
{% extends "base.html" %}
|
|
|
|
|
{% block content %}
|
|
|
|
|
<h1>{{ title }}</h1>
|
|
|
|
|
<p>{{ content }}</p>
|
|
|
|
|
{% endblock %}
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
JsonGoodCode* = """{"name": "test", "value": 42}"""
|
|
|
|
|
JsonBadCode* = """{"name": "test", "value": }"""
|
|
|
|
|
|
|
|
|
|
YamlGoodCode* = """
|
|
|
|
|
name: test
|
|
|
|
|
version: 1.0
|
|
|
|
|
dependencies:
|
|
|
|
|
- lib1
|
|
|
|
|
- lib2
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
YamlBadCode* = """
|
|
|
|
|
name: test
|
|
|
|
|
: invalid
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
TomlGoodCode* = """
|
|
|
|
|
[package]
|
|
|
|
|
name = "test"
|
|
|
|
|
version = "1.0.0"
|
|
|
|
|
|
|
|
|
|
[[dependencies]]
|
|
|
|
|
name = "lib"
|
|
|
|
|
version = "2.0"
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
TomlBadCode* = """
|
|
|
|
|
[package]
|
|
|
|
|
name = "test"
|
|
|
|
|
invalid line
|
|
|
|
|
"""
|