|
KiCad PCB EDA Suite
|
Files | |
| test_text_eval_numeric_compat.cpp | |
| Test suite for text_eval system using examples adapted from numeric_evaluator tests. | |
| test_text_eval_parser.cpp | |
| Test suite for text_eval_parser routines. | |
| test_text_eval_parser_core.cpp | |
| Test suite for low-level text_eval_parser functionality. | |
| test_text_eval_parser_datetime.cpp | |
| Test suite for text_eval_parser date and time functionality. | |
| test_text_eval_parser_integration.cpp | |
| Integration tests for text_eval_parser functionality including real-world scenarios. | |
| test_text_eval_parser_vcs.cpp | |
| Test suite for text_eval_parser VCS functionality. | |
| test_text_eval_render.cpp | |
| Test rendering helper functions with expression evaluation. | |
This directory contains test suites for the KiCad text evaluation parser functionality.
test_text_eval_parser.cppHigh-level integration tests using the EXPRESSION_EVALUATOR wrapper class.
abs, sqrt, pow, floor, ceil, round, min, max, sum, avgupper, lower, concat, beforefirst, beforelast, afterfirst, afterlast, replaceformat, fixed, currencytoday, now, dateformat, weekdaynameif statements with boolean logicrandom() number generationtest_text_eval_parser_core.cppLow-level unit tests for the core parser components. Tests the internal API including:
test_text_eval_parser_datetime.cppSpecialized tests for date and time functionality:
today() and now() function validationtest_text_eval_parser_vcs.cppSpecialized tests for version control system (VCS) functionality:
test_text_eval_parser_integration.cppIntegration tests simulating real-world KiCad usage scenarios:
abs(x) - Absolute valuesqrt(x) - Square root (with negative input validation)pow(x, y) - Power/exponentiationfloor(x) - Round down to integerceil(x) - Round up to integerround(x, [precision]) - Round to specified decimal placesmin(...) - Minimum of multiple valuesmax(...) - Maximum of multiple valuessum(...) - Sum of multiple valuesavg(...) - Average of multiple valuesshunt(r1, r2) - Parallel resistance calculation: (r1×r2)/(r1+r2)db(ratio) - Power ratio to decibels: 10×log₁₀(ratio)dbv(ratio) - Voltage/current ratio to decibels: 20×log₁₀(ratio)fromdb(db) - Decibels to power ratio: 10^(dB/10)fromdbv(db) - Decibels to voltage/current ratio: 10^(dB/20)enearest(value, [series]) - Nearest E-series standard value (default: E24)eup(value, [series]) - Next higher E-series standard value (default: E24)edown(value, [series]) - Next lower E-series standard value (default: E24)upper(str) - Convert to uppercaselower(str) - Convert to lowercaseconcat(...) - Concatenate multiple valuesbeforefirst(str, c) - Substringbeforelast(str, c) - Substringafterfirst(str, c) - Substringafterlast(str, c) - Substringreplace(str, substrold, substrnew) - Replace all instances of substrold in str with substrnewformat(num, [decimals]) - Format number with specified precisionfixed(num, [decimals]) - Fixed decimal formattingcurrency(amount, [symbol]) - Currency formattingtoday() - Current date as days since epochnow() - Current timestamp as seconds since epochdateformat(days, [format]) - Format date stringweekdayname(days) - Get weekday name for datevcsidentifier([length]) - Current HEAD commit identifier (default: 40 chars, min: 4)vcsbranch() - Current branch namevcsauthor() - HEAD commit author namevcsauthoremail() - HEAD commit author emailvcscommitter() - HEAD commit committer namevcscommitteremail() - HEAD commit committer emailvcscommitdate([format]) - HEAD commit date (formats: "ISO", "US", "EU", "Chinese", "Japanese", "Korean", "long", "short")vcsnearestlabel([match], [anyTags]) - Nearest label from HEAD (match pattern, anyTags: 0=annotated only, 1=all tags)vcslabeldistance([match], [anyTags]) - Number of commits since nearest labelvcsdirty([includeUntracked]) - Repository dirty status: "1" if dirty, "0" if cleanvcsdirtysuffix([suffix], [includeUntracked]) - Custom suffix if dirty (default: "-dirty"), empty if cleanvcsfileidentifier(file, [length]) - Last commit identifier that modified filevcsfileauthor(file) - Author of last commit that modified filevcsfileauthoremail(file) - Author email of last commit that modified filevcsfilecommitter(file) - Committer of last commit that modified filevcsfilecommitteremail(file) - Committer email of last commit that modified filevcsfilecommitdate(file, [format]) - Date of last commit that modified fileNote: All VCS functions return empty strings when not in a VCS repository. File paths are relative to repository root.
if(condition, true_value, false_value) - Conditional evaluationrandom() - Random number between 0 and 1+ - Addition (also string concatenation)- - Subtraction (also unary minus)* - Multiplication/ - Division (with zero-division error handling)% - Modulo (with zero-modulo error handling)^ - Exponentiation (right-associative)Variables are referenced using ${variable_name} syntax and can be:
evaluator.SetVariable()Calculations are embedded in text using @{expression} syntax:
"Result: @{2 + 3}" → "Result: 5""Hello ${name}!" → "Hello World!" (with variable substitution)"Area: @{${width} * ${height}} mm²" → "Area: 100 mm²"The parser collects errors for later diagnostics. However, a string with multiple expressions may be partially evaluated. It will return an error for every expression that was not fully evaluated.