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
|
|
|
## Config file (JSON, YAML, TOML) validator tests.
|
|
|
|
|
|
|
|
|
|
import std/[unittest, strutils, strformat]
|
2026-07-08 10:01:58 +02:00
|
|
|
import ../src/nimcheck
|
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
|
|
|
import test_common
|
|
|
|
|
|
|
|
|
|
proc checkValid(result: ValidationResult, context: string = "") =
|
|
|
|
|
if result.errors.len > 0:
|
|
|
|
|
var msg = &"Expected valid, got {result.errors.len} error(s)"
|
|
|
|
|
if context.len > 0: msg.add(&" [{context}]")
|
|
|
|
|
for e in result.errors: msg.add(&"\n [{e.code}] {e.message}")
|
|
|
|
|
doAssert false, msg
|
|
|
|
|
|
|
|
|
|
suite "Config Validators":
|
|
|
|
|
test "JSON valid":
|
|
|
|
|
checkValid(validateSource(JsonGoodCode, flavor = lfJSON))
|
|
|
|
|
|
|
|
|
|
test "JSON invalid returns errors":
|
|
|
|
|
check validateSource(JsonBadCode, flavor = lfJSON).errors.len > 0
|
|
|
|
|
|
|
|
|
|
test "JSON valid file":
|
|
|
|
|
checkValid(validateFile("tests/fixtures/json/valid.json"))
|
|
|
|
|
|
|
|
|
|
test "JSON invalid file returns errors":
|
|
|
|
|
check validateFile("tests/fixtures/json/invalid.json").errors.len > 0
|
|
|
|
|
|
|
|
|
|
test "JSON detect":
|
|
|
|
|
check $detectFlavor(JsonGoodCode) == "json"
|
|
|
|
|
|
|
|
|
|
test "YAML valid":
|
|
|
|
|
checkValid(validateSource(YamlGoodCode, flavor = lfYAML))
|
|
|
|
|
|
|
|
|
|
test "YAML invalid returns errors":
|
|
|
|
|
check validateSource(YamlBadCode, flavor = lfYAML).errors.len > 0
|
|
|
|
|
|
|
|
|
|
test "YAML valid file":
|
|
|
|
|
checkValid(validateFile("tests/fixtures/yaml/valid.yaml"))
|
|
|
|
|
|
|
|
|
|
test "YAML invalid file returns errors":
|
|
|
|
|
check validateFile("tests/fixtures/yaml/invalid.yaml").errors.len > 0
|
|
|
|
|
|
|
|
|
|
test "YAML detect":
|
|
|
|
|
check $detectFlavor(YamlGoodCode) == "yaml"
|
|
|
|
|
|
|
|
|
|
test "TOML valid":
|
|
|
|
|
checkValid(validateSource(TomlGoodCode, flavor = lfTOML))
|
|
|
|
|
|
|
|
|
|
test "TOML invalid returns errors":
|
|
|
|
|
check validateSource(TomlBadCode, flavor = lfTOML).errors.len > 0
|
|
|
|
|
|
|
|
|
|
test "TOML valid file":
|
|
|
|
|
checkValid(validateFile("tests/fixtures/toml/valid.toml"))
|
|
|
|
|
|
|
|
|
|
test "TOML invalid file returns errors":
|
|
|
|
|
check validateFile("tests/fixtures/toml/invalid.toml").errors.len > 0
|
|
|
|
|
|
|
|
|
|
test "TOML detect":
|
|
|
|
|
check $detectFlavor(TomlGoodCode) == "toml"
|