From fb908caf90ed2fbde4a0cdb63ab511c67b452e27 Mon Sep 17 00:00:00 2001 From: Viktor Alenkov Date: Sun, 7 May 2023 12:19:46 +0300 Subject: [PATCH] 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 -}