|
## PHP language validator tests.
|
|
|
|
import std/[unittest, strutils, strformat]
|
|
import ../src/nimcheck
|
|
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 "PHP Validator":
|
|
test "valid PHP code":
|
|
let result = validateSource(PhpGoodCode, flavor = lfPHP)
|
|
checkValid(result)
|
|
|
|
test "invalid PHP code returns errors":
|
|
let result = validateSource(PhpBadCode, flavor = lfPHP)
|
|
checkInvalid(result)
|
|
|
|
test "valid .php file":
|
|
let result = validateFile("tests/fixtures/php/valid.php")
|
|
checkValid(result)
|
|
|
|
test "invalid .php file returns errors":
|
|
let result = validateFile("tests/fixtures/php/invalid.php")
|
|
check result.errors.len > 0
|
|
|
|
test "detectFlavor detects PHP":
|
|
check $detectFlavor(PhpGoodCode) == "php"
|
|
|
|
test "inspectSource returns JSON":
|
|
let json = inspectSource(PhpGoodCode, flavor = lfPHP)
|
|
check json.kind == JObject
|