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) } }