From d1d62d3a358beb9841623acc00bee58d3795698e Mon Sep 17 00:00:00 2001 From: "emil@pandocchi.it" Date: Mon, 21 Jun 2021 15:24:26 +0200 Subject: [PATCH] fix: #20 remove extra \t characters --- formatter.go | 8 ++++---- formatter_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/formatter.go b/formatter.go index 13568c6..994e5bd 100644 --- a/formatter.go +++ b/formatter.go @@ -18,16 +18,16 @@ func lineFormatter(hfl HostsFileLine) string { if hfl.IsCommented { // check if there's a comment for that line if len(hfl.Comment) > 0 { - return fmt.Sprintf("# %-16s\t%s\t#%s", hfl.Address, strings.Join(hfl.Hostnames, " "), hfl.Comment) + return fmt.Sprintf("# %-16s %s #%s", hfl.Address, strings.Join(hfl.Hostnames, " "), hfl.Comment) } - return fmt.Sprintf("# %-16s\t%s", hfl.Address, strings.Join(hfl.Hostnames, " ")) + return fmt.Sprintf("# %-16s %s", hfl.Address, strings.Join(hfl.Hostnames, " ")) } // return the actual hosts entry if len(hfl.Comment) > 0 { - return fmt.Sprintf("%-16s\t%s\t#%s", hfl.Address, strings.Join(hfl.Hostnames, " "), hfl.Comment) + return fmt.Sprintf("%-16s %s #%s", hfl.Address, strings.Join(hfl.Hostnames, " "), hfl.Comment) } - return fmt.Sprintf("%-16s\t%s", hfl.Address, strings.Join(hfl.Hostnames, " ")) + return fmt.Sprintf("%-16s %s", hfl.Address, strings.Join(hfl.Hostnames, " ")) } diff --git a/formatter_test.go b/formatter_test.go index ae534d6..f1ddb64 100644 --- a/formatter_test.go +++ b/formatter_test.go @@ -24,7 +24,7 @@ func TestLineFormatter(t *testing.T) { l := lineFormatter(hfl) // define what we expect - w := "# 1.1.1.1 \tmy.host.name\t#This is a host" + w := "# 1.1.1.1 my.host.name #This is a host" // check if !strings.EqualFold(l, w) { @@ -34,7 +34,7 @@ func TestLineFormatter(t *testing.T) { // test without IsCommented hfl.IsCommented = false l = lineFormatter(hfl) - w = "1.1.1.1 \tmy.host.name\t#This is a host" + w = "1.1.1.1 my.host.name #This is a host" if !strings.EqualFold(l, w) { t.Fatalf(`IsCommented=false and Comment: wants '%q' got '%q'`, w, l) } @@ -43,7 +43,7 @@ func TestLineFormatter(t *testing.T) { hfl.IsCommented = true hfl.Comment = "" l = lineFormatter(hfl) - w = "# 1.1.1.1 \tmy.host.name" + w = "# 1.1.1.1 my.host.name" if !strings.EqualFold(l, w) { t.Fatalf(`IsCommented=true no Comment: wants '%q' got '%q'`, w, l) } @@ -52,7 +52,7 @@ func TestLineFormatter(t *testing.T) { hfl.IsCommented = false hfl.Comment = "" l = lineFormatter(hfl) - w = "1.1.1.1 \tmy.host.name" + w = "1.1.1.1 my.host.name" if !strings.EqualFold(l, w) { t.Fatalf(`IsCommented=false no Comment: wants '%q' got '%q'`, w, l) }