Skip to content

Commit

Permalink
Merge pull request #427 from Manoramsharma/pathch-new-line
Browse files Browse the repository at this point in the history
BUG: Removed extra newline in kcl.mod
  • Loading branch information
Peefy authored Aug 6, 2024
2 parents 0b4d413 + 00c403b commit 04d2b16
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
1 change: 0 additions & 1 deletion pkg/package/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (dep *Dependencies) MarshalTOML() string {
sb.WriteString(NEWLINE)
sb.WriteString(dep.MarshalTOML())
}
sb.WriteString(NEWLINE)
}
return sb.String()
}
Expand Down
54 changes: 54 additions & 0 deletions pkg/package/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/BurntSushi/toml"
Expand Down Expand Up @@ -286,3 +287,56 @@ func TestMarshalOciUrlIntoFile(t *testing.T) {
assert.Equal(t, utils.RmNewline(string(expectKclModFileContents)), utils.RmNewline(writeKclModFileContents))
}
}

func TestInitEmptyPkg(t *testing.T) {
modfile := ModFile{
Pkg: Package{
Name: "MyKcl",
Edition: "v0.0.1",
Version: "v0.0.1",
Include: []string{"src/", "README.md", "LICENSE"},
Exclude: []string{"target/", ".git/", "*.log"},
},
Dependencies: Dependencies{
orderedmap.NewOrderedMap[string, Dependency](),
},
}

dep := Dependency{
Name: "MyKcl1",
FullName: "MyKcl1_v0.0.2",
Source: downloader.Source{
Git: &downloader.Git{
Url: "https://github.com/test/MyKcl1.git",
Tag: "v0.0.2",
},
},
}

ociDep := Dependency{
Name: "MyOciKcl1",
FullName: "MyOciKcl1_0.0.1",
Version: "0.0.1",
Source: downloader.Source{
Oci: &downloader.Oci{
Tag: "0.0.1",
},
},
}

modfile.Dependencies.Deps.Set("MyOciKcl1_0.0.1", ociDep)
modfile.Dependencies.Deps.Set("MyKcl1_v0.0.2", dep)

got_data := modfile.MarshalTOML()

expected_data, _ := os.ReadFile(filepath.Join(getTestDir(testTomlDir), "expected.toml"))
expected_toml := string(expected_data)

expected_toml = strings.ReplaceAll(expected_toml, "\r\n", "\n")
got_data = strings.ReplaceAll(got_data, "\r\n", "\n")

fmt.Printf("expected_toml: '%q'\n", expected_toml)

fmt.Printf("modfile: '%q'\n", got_data)
assert.Equal(t, expected_toml, got_data)
}

0 comments on commit 04d2b16

Please sign in to comment.