Skip to content

Commit

Permalink
fix: #20 remove extra \t characters
Browse files Browse the repository at this point in the history
  • Loading branch information
areYouLazy committed Jun 21, 2021
1 parent e0bfadd commit d1d62d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, " "))
}
8 changes: 4 additions & 4 deletions formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit d1d62d3

Please sign in to comment.