Files
five/hbrtl/crypto_test.go
Charles KWON OhJun 59568f3301 Five v0.9 — Harbour + Go fusion language
- Compiler: PP → Lexer → Parser → Analyzer → Gengo pipeline
- Parser: 232/236 (98%) Harbour compatibility, registry-based dispatch
- RTL: 351 Harbour-compatible functions
- RDD: DBF/NTX/CDX engines with Rushmore bitmap optimization
- Go Interop: IMPORT + pkg.Func() + obj:Method() with FastPath (15M calls/sec)
- HB_FUNC API: Full Harbour C API compatible Go bridge
- Concurrency: SPAWN/LAUNCH/GOROUTINE, <-, WATCH, PARALLEL FOR, ASYNC/AWAIT
- Extensions: Multi-return, DEFER, Slice, f-string, Nil-safe ?:, CONST
- Macro Compiler: Runtime AST parsing and evaluation
- Debugger: TUI debugger with source display, breakpoints, stepping
- FRB: Native + Pcode dual mode runtime binary
- Tests: 13 packages ALL PASS

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 09:41:50 +09:00

69 lines
1.6 KiB
Go

package hbrtl
import (
"five/hbrt"
"testing"
)
func setupVM() (*hbrt.VM, *hbrt.Thread) {
vm := hbrt.NewVM()
RegisterRTL(vm)
t := vm.NewThread()
return vm, t
}
// helper: call a 1-arg string function and get string result
func callStr1(t *testing.T, th *hbrt.Thread, fn func(*hbrt.Thread), arg string) string {
th.PushString(arg)
th.PendingParams2(1)
fn(th)
return th.GetRetValue().AsString()
}
func TestHbMD5(t *testing.T) {
_, th := setupVM()
result := callStr1(t, th, HbMD5, "hello")
expected := "5d41402abc4b2a76b9719d911017c592"
if result != expected {
t.Errorf("HB_MD5('hello') = %q, want %q", result, expected)
}
}
func TestHbSHA256(t *testing.T) {
_, th := setupVM()
result := callStr1(t, th, HbSHA256, "hello")
expected := "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
if result != expected {
t.Errorf("HB_SHA256('hello') = %q, want %q", result, expected)
}
}
func TestHbBase64(t *testing.T) {
_, th := setupVM()
// Encode
result := callStr1(t, th, HbBase64Encode, "Hello World")
expected := "SGVsbG8gV29ybGQ="
if result != expected {
t.Errorf("HB_BASE64ENCODE('Hello World') = %q, want %q", result, expected)
}
// Decode
decoded := callStr1(t, th, HbBase64Decode, expected)
if decoded != "Hello World" {
t.Errorf("HB_BASE64DECODE(%q) = %q, want %q", expected, decoded, "Hello World")
}
}
func TestHbCRC32(t *testing.T) {
_, th := setupVM()
th.PushString("hello")
th.PendingParams2(1)
HbCRC32(th)
result := th.GetRetValue().AsLong()
// CRC32 of "hello" = 907060870
if result != 907060870 {
t.Errorf("HB_CRC32('hello') = %d, want %d", result, 907060870)
}
}