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
|
|
|
## JavaScript language 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
|
|
|
|
|
|
|
|
|
|
proc checkInvalid(result: ValidationResult, context: string = "") =
|
|
|
|
|
if result.errors.len == 0:
|
|
|
|
|
doAssert false, &"Expected errors, got none [{context}]"
|
|
|
|
|
|
|
|
|
|
suite "JavaScript Validator":
|
|
|
|
|
test "valid JS code":
|
|
|
|
|
let result = validateSource(JsGoodCode, flavor = lfJavaScript)
|
|
|
|
|
checkValid(result)
|
|
|
|
|
|
|
|
|
|
test "invalid JS code returns errors":
|
|
|
|
|
let result = validateSource(JsBadCode, flavor = lfJavaScript)
|
|
|
|
|
checkInvalid(result)
|
|
|
|
|
|
|
|
|
|
test "valid .js file":
|
|
|
|
|
let result = validateFile("tests/fixtures/javascript/valid.js")
|
|
|
|
|
checkValid(result)
|
|
|
|
|
|
|
|
|
|
test "invalid .js file returns errors":
|
|
|
|
|
let result = validateFile("tests/fixtures/javascript/invalid.js")
|
|
|
|
|
check result.errors.len > 0
|
|
|
|
|
|
|
|
|
|
test "detectFlavor detects JavaScript":
|
|
|
|
|
check $detectFlavor(JsGoodCode) == "javascript"
|
|
|
|
|
|
|
|
|
|
test "inspectSource returns JSON":
|
|
|
|
|
let json = inspectSource(JsGoodCode, flavor = lfJavaScript)
|
|
|
|
|
check json.kind == JObject
|