testform functions
testform functions [nombre] [opciones]El comando testform functions permite inspeccionar, explorar y evaluar interactivamente la biblioteca de funciones integradas del motor de expresiones de Testform. Estas funciones se utilizan tanto en locals.yml para cómputos dinámicos como en las condiciones de validación de variables.yml.
Modos de Uso
Sección titulada «Modos de Uso»1. Catálogo General de Funciones
Sección titulada «1. Catálogo General de Funciones»Si ejecutas el comando sin argumentos, muestra todas las funciones disponibles organizadas por categoría:
testform functionsSalida en terminal:
Testform Expression Engine — Built-in Functions Catalog
Available in locals.yml expressions, variables.yml validation conditions, and CLI:
• String & Text: lower(string) → Converts all letters in a string to lowercase. upper(string) → Converts all letters in a string to uppercase. trim(string, [cutset]) → Removes leading and trailing whitespace or specified characters. trimprefix(string, prefix) → Removes the specified prefix from the beginning of a string. trimsuffix(string, suffix) → Removes the specified suffix from the end of a string. startswith(string, prefix) → Returns true if the string begins with the specified prefix. endswith(string, suffix) → Returns true if the string ends with the specified suffix. replace(string, search, replacement) → Replaces all occurrences of a search string. split(separator, string) → Divides a string into a list of substrings. join(separator, list) → Concatenates elements of a list into a single string. format(format, ...args) → Formats a string using verbs (%s, %d, %j, %%). substr(string, offset, length) → Extracts a substring from offset up to length characters.
• Collections & Logic: coalesce(...args) → Returns the first argument that is not null or empty. lookup(map, key, [default]) → Retrieves the value of a key from a map. contains(list_or_string, value) → Checks whether a list or string contains a value. length(value) → Returns the number of elements, keys, or characters. element(list, index) → Retrieves an element at the specified index. slice(list, start, [end]) → Returns a sublist of elements. merge(...maps) → Merges multiple maps into a single map.
• System & Encoding: env(name) → Reads an environment variable from the host process. uuid() → Generates a random RFC 4122 version 4 UUID. timestamp() → Returns current UTC date and time formatted in ISO 8601. jsonencode(value) → Serializes a value into a standard JSON string. jsondecode(string) → Parses a JSON string into its native data structure. file(path) → Reads the contents of a local file as UTF-8 text.2. Documentación Detallada de una Función
Sección titulada «2. Documentación Detallada de una Función»Para consultar la firma completa, tipos de argumentos y ejemplos de una función en particular:
testform functions formatSalida en terminal:
Testform Expression Function: format Category: String & Text Signature: format(format, ...args) -> string Description: Formats a string using verbs (%s for string, %d for integer, %j for JSON, %% for literal %).
Arguments: - format [string]: Format string containing placeholders. - args [any...]: Values to interpolate.
Examples: $ format("%s/%s", var.base_url, "api/v1") => "https://example.com/api/v1" $ format("run-%03d", 5) => "run-5"Otro ejemplo:
testform functions contains3. Evaluación en Vivo con --eval
Sección titulada «3. Evaluación en Vivo con --eval»Puedes probar cualquier expresión matemática, lógica o llamada a funciones en tiempo real directamente desde tu terminal para verificar su resultado y tipo:
testform functions --eval "format('%s/%s', 'https://api.empresa.com', 'v1')"Salida:
Expression Evaluation: Input: format('%s/%s', 'https://api.empresa.com', 'v1') Type: string Result: "https://api.empresa.com/v1"Evaluando colecciones y lógica:
testform functions --eval "contains(['dev', 'staging', 'prod'], 'qa')"Salida:
Expression Evaluation: Input: contains(['dev', 'staging', 'prod'], 'qa') Type: boolean Result: falseOpciones
Sección titulada «Opciones»| Opción | Descripción |
|---|---|
[nombre] |
Nombre de la función estándar a consultar (lower, upper, format, contains, etc.). |
--eval "<expr>" |
Evalúa una expresión de prueba en vivo e imprime el tipo y valor resultante. |
Códigos de Salida
Sección titulada «Códigos de Salida»0: Comando ejecutado exitosamente.1: Expresión malformada o error de sintaxis en el AST.