From ed632f5989af394157ee65d9b2c803a03c9536d9 Mon Sep 17 00:00:00 2001 From: Viktor Alenkov Date: Sun, 7 May 2023 11:55:45 +0300 Subject: [PATCH 1/4] Add support Web Assembly --- env_wasm.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 env_wasm.go diff --git a/env_wasm.go b/env_wasm.go new file mode 100644 index 0000000..7b10cad --- /dev/null +++ b/env_wasm.go @@ -0,0 +1,12 @@ +package env + +import "strings" + +func toMap(env []string) map[string]string { + r := map[string]string{} + for _, e := range env { + p := strings.SplitN(e, "=", 2) + r[p[0]] = p[1] + } + return r +} From fb908caf90ed2fbde4a0cdb63ab511c67b452e27 Mon Sep 17 00:00:00 2001 From: Viktor Alenkov Date: Sun, 7 May 2023 12:19:46 +0300 Subject: [PATCH 2/4] Refactoring --- env_wasm.go => env-tomap.go | 2 ++ env_unix_test.go => env-tomap_test.go | 14 +++++++++----- env_windows.go => env-tomap_windows.go | 2 ++ env_windows_test.go => env-tomap_windows_test.go | 14 +++++++++----- env_unix.go | 15 --------------- 5 files changed, 22 insertions(+), 25 deletions(-) rename env_wasm.go => env-tomap.go (90%) rename env_unix_test.go => env-tomap_test.go (52%) rename env_windows.go => env-tomap_windows.go (96%) rename env_windows_test.go => env-tomap_windows_test.go (75%) delete mode 100644 env_unix.go diff --git a/env_wasm.go b/env-tomap.go similarity index 90% rename from env_wasm.go rename to env-tomap.go index 7b10cad..80fcea0 100644 --- a/env_wasm.go +++ b/env-tomap.go @@ -1,3 +1,5 @@ +//go:build !windows + package env import "strings" diff --git a/env_unix_test.go b/env-tomap_test.go similarity index 52% rename from env_unix_test.go rename to env-tomap_test.go index 3998f26..9c1e680 100644 --- a/env_unix_test.go +++ b/env-tomap_test.go @@ -1,3 +1,5 @@ +//go:build !windows + package env import "testing" @@ -5,9 +7,11 @@ import "testing" func TestUnix(t *testing.T) { envVars := []string{":=/test/unix", "PATH=:/test_val1:/test_val2", "VAR=REGULARVAR"} result := toMap(envVars) - isEqual(t, map[string]string{ - ":": "/test/unix", - "PATH": ":/test_val1:/test_val2", - "VAR": "REGULARVAR", - }, result) + isEqual( + t, map[string]string{ + ":": "/test/unix", + "PATH": ":/test_val1:/test_val2", + "VAR": "REGULARVAR", + }, result, + ) } diff --git a/env_windows.go b/env-tomap_windows.go similarity index 96% rename from env_windows.go rename to env-tomap_windows.go index e12123c..43b8502 100644 --- a/env_windows.go +++ b/env-tomap_windows.go @@ -1,3 +1,5 @@ +//go:build windows + package env import "strings" diff --git a/env_windows_test.go b/env-tomap_windows_test.go similarity index 75% rename from env_windows_test.go rename to env-tomap_windows_test.go index ccca2be..3a12a25 100644 --- a/env_windows_test.go +++ b/env-tomap_windows_test.go @@ -1,3 +1,5 @@ +//go:build windows + package env import "testing" @@ -7,9 +9,11 @@ import "testing" func TestToMapWindows(t *testing.T) { envVars := []string{"=::=::\\", "=C:=C:\\test", "VAR=REGULARVAR"} result := toMap(envVars) - isEqual(t, map[string]string{ - "=::": "::\\", - "=C:": "C:\\test", - "VAR": "REGULARVAR", - }, result) + isEqual( + t, map[string]string{ + "=::": "::\\", + "=C:": "C:\\test", + "VAR": "REGULARVAR", + }, result, + ) } diff --git a/env_unix.go b/env_unix.go deleted file mode 100644 index 411d438..0000000 --- a/env_unix.go +++ /dev/null @@ -1,15 +0,0 @@ -//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris -// +build darwin dragonfly freebsd linux netbsd openbsd solaris - -package env - -import "strings" - -func toMap(env []string) map[string]string { - r := map[string]string{} - for _, e := range env { - p := strings.SplitN(e, "=", 2) - r[p[0]] = p[1] - } - return r -} From 7bd99b4027b1d84d65f24953dbd76b111605ee5c Mon Sep 17 00:00:00 2001 From: Viktor Alenkov Date: Wed, 10 May 2023 06:14:57 +0300 Subject: [PATCH 3/4] Elimination of remarks --- env-tomap_test.go | 11 +++++------ env-tomap_windows_test.go | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/env-tomap_test.go b/env-tomap_test.go index 9c1e680..1d7485b 100644 --- a/env-tomap_test.go +++ b/env-tomap_test.go @@ -7,11 +7,10 @@ import "testing" func TestUnix(t *testing.T) { envVars := []string{":=/test/unix", "PATH=:/test_val1:/test_val2", "VAR=REGULARVAR"} result := toMap(envVars) - isEqual( - t, map[string]string{ - ":": "/test/unix", - "PATH": ":/test_val1:/test_val2", - "VAR": "REGULARVAR", - }, result, + isEqual(t, map[string]string{ + ":": "/test/unix", + "PATH": ":/test_val1:/test_val2", + "VAR": "REGULARVAR", + }, result, ) } diff --git a/env-tomap_windows_test.go b/env-tomap_windows_test.go index 3a12a25..054405d 100644 --- a/env-tomap_windows_test.go +++ b/env-tomap_windows_test.go @@ -9,11 +9,10 @@ import "testing" func TestToMapWindows(t *testing.T) { envVars := []string{"=::=::\\", "=C:=C:\\test", "VAR=REGULARVAR"} result := toMap(envVars) - isEqual( - t, map[string]string{ - "=::": "::\\", - "=C:": "C:\\test", - "VAR": "REGULARVAR", - }, result, + isEqual(t, map[string]string{ + "=::": "::\\", + "=C:": "C:\\test", + "VAR": "REGULARVAR", + }, result, ) } From 77ef1c44da4c9c28b4529be57ab2559d6f8a4dc2 Mon Sep 17 00:00:00 2001 From: Viktor Alenkov Date: Wed, 10 May 2023 06:16:46 +0300 Subject: [PATCH 4/4] Elimination of remarks --- env-tomap_test.go | 3 +-- env-tomap_windows_test.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/env-tomap_test.go b/env-tomap_test.go index 1d7485b..2f7840c 100644 --- a/env-tomap_test.go +++ b/env-tomap_test.go @@ -11,6 +11,5 @@ func TestUnix(t *testing.T) { ":": "/test/unix", "PATH": ":/test_val1:/test_val2", "VAR": "REGULARVAR", - }, result, - ) + }, result) } diff --git a/env-tomap_windows_test.go b/env-tomap_windows_test.go index 054405d..d54262e 100644 --- a/env-tomap_windows_test.go +++ b/env-tomap_windows_test.go @@ -13,6 +13,5 @@ func TestToMapWindows(t *testing.T) { "=::": "::\\", "=C:": "C:\\test", "VAR": "REGULARVAR", - }, result, - ) + }, result) }