diff options
Diffstat (limited to 'test/TestSupport.mc')
| -rw-r--r-- | test/TestSupport.mc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/TestSupport.mc b/test/TestSupport.mc new file mode 100644 index 0000000..f6fa4b7 --- /dev/null +++ b/test/TestSupport.mc @@ -0,0 +1,53 @@ +// Author: cirakg & claude ai +// Summary: Small helpers shared by the Monkey C unit tests (reading vector rows, reporting mismatches). + +import Toybox.Lang; +import Toybox.Test; + +(:test) +module TestSupport { + + // One row of a TestVectors table. + function row(table as Array, index as Number) as Array { + return table[index] as Array; + } + + function str(r as Array, column as Number) as String { + return r[column] as String; + } + + function bytes(r as Array, column as Number) as ByteArray { + return Bytes.fromHex(r[column] as String); + } + + function num(r as Array, column as Number) as Number { + return r[column] as Number; + } + + // Numbers above 2^31 are stored as Long literals in the tables. + function long(r as Array, column as Number) as Long { + return (r[column] as Number or Long).toLong(); + } + + function alg(r as Array, column as Number) as Hashes.Algorithm { + return r[column] as Hashes.Algorithm; + } + + // Compare bytes; log both sides on mismatch. Returns true when equal. + function sameBytes(logger as Test.Logger, what as String, actual as ByteArray, expected as ByteArray) as Boolean { + if (Bytes.equal(actual, expected)) { + return true; + } + logger.error(what + ": got " + Bytes.toHex(actual) + ", expected " + Bytes.toHex(expected)); + return false; + } + + // Compare strings; log both sides on mismatch. + function sameString(logger as Test.Logger, what as String, actual as String, expected as String) as Boolean { + if (actual.equals(expected)) { + return true; + } + logger.error(what + ": got '" + actual + "', expected '" + expected + "'"); + return false; + } +} |
