aboutsummaryrefslogtreecommitdiff
path: root/internal/proto/proto_test.go
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2025-06-04 11:08:19 +0300
committerGitHub <noreply@github.com>2025-06-04 11:08:19 +0300
commit7240595478fedec02e9e47c704976cf56a66d3e8 (patch)
tree300165d4ecf00fed03d33b36863370384cbdc7ce /internal/proto/proto_test.go
parent76dc648f33a9f96e68d5c9000032c2b986bd5a3d (diff)
downloadgo-metatrader4-7240595478fedec02e9e47c704976cf56a66d3e8.tar.xz
go-metatrader4-7240595478fedec02e9e47c704976cf56a66d3e8.zip
First version
Diffstat (limited to 'internal/proto/proto_test.go')
-rw-r--r--internal/proto/proto_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/proto/proto_test.go b/internal/proto/proto_test.go
new file mode 100644
index 0000000..0e7e644
--- /dev/null
+++ b/internal/proto/proto_test.go
@@ -0,0 +1,39 @@
+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)
+ }
+}