## Common test patterns for Validatrix tests.
## 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
"""