0
mirror of https://github.com/valentineus/go-metatrader4.git synced 2025-06-08 18:13:34 +03:00
go-metatrader4/internal/proto/proto_test.go

40 lines
946 B
Go
Raw Normal View History

2025-06-04 12:08:19 +04:00
package proto
import (
"strings"
"testing"
)
func TestEncodeParamsOrder(t *testing.T) {
params := map[string]string{"B": "2", "A": "1"}
encoded1, err := EncodeParams(params)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// encode again with different map order
encoded2, err := EncodeParams(map[string]string{"A": "1", "B": "2"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if encoded1 != encoded2 {
t.Fatalf("expected deterministic encode, got %s vs %s", encoded1, encoded2)
}
}
func TestDecodeResponse(t *testing.T) {
// "привет" in Cyrillic
original := "привет"
params := map[string]string{"MSG": original}
enc, err := EncodeParams(params)
if err != nil {
t.Fatalf("encode params: %v", err)
}
dec, err := DecodeResponse(enc)
if err != nil {
t.Fatalf("decode: %v", err)
}
if !strings.Contains(dec, original) {
t.Fatalf("expected to contain %q, got %q", original, dec)
}
}