Skip to content

Commit

Permalink
Merge pull request #58 from bisakhmondal/fix_snippet
Browse files Browse the repository at this point in the history
Fix for wrapping multiline snippet copyright in tvsaver
  • Loading branch information
swinslow committed May 2, 2021
2 parents 2d832ae + 4cd473b commit cb47219
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

.vscode
.idea
.DS_Store
scratch/*
*.swp
Expand Down
2 changes: 1 addition & 1 deletion tvsaver/saver2v1/save_snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func renderSnippet2_1(sn *spdx.Snippet2_1, w io.Writer) error {
fmt.Fprintf(w, "SnippetLicenseComments: %s\n", textify(sn.SnippetLicenseComments))
}
if sn.SnippetCopyrightText != "" {
fmt.Fprintf(w, "SnippetCopyrightText: %s\n", sn.SnippetCopyrightText)
fmt.Fprintf(w, "SnippetCopyrightText: %s\n", textify(sn.SnippetCopyrightText))
}
if sn.SnippetComment != "" {
fmt.Fprintf(w, "SnippetComment: %s\n", textify(sn.SnippetComment))
Expand Down
35 changes: 35 additions & 0 deletions tvsaver/saver2v1/save_snippet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,38 @@ SnippetCopyrightText: Copyright (c) John Doe 20x6
t.Errorf("Expected %v, got %v", want.String(), got.String())
}
}

func TestSaver2_1SnippetWrapsCopyrightMultiline(t *testing.T) {
sn := &spdx.Snippet2_1{
SnippetSPDXIdentifier: spdx.ElementID("Snippet17"),
SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292"),
SnippetByteRangeStart: 17,
SnippetByteRangeEnd: 209,
SnippetLicenseConcluded: "GPL-2.0-or-later",
SnippetCopyrightText: `Copyright (c) John Doe 20x6
Copyright (c) John Doe 20x6`,
}

// what we want to get, as a buffer of bytes
want := bytes.NewBufferString(`SnippetSPDXIdentifier: SPDXRef-Snippet17
SnippetFromFileSPDXID: SPDXRef-File292
SnippetByteRange: 17:209
SnippetLicenseConcluded: GPL-2.0-or-later
SnippetCopyrightText: <text>Copyright (c) John Doe 20x6
Copyright (c) John Doe 20x6</text>
`)

// render as buffer of bytes
var got bytes.Buffer
err := renderSnippet2_1(sn, &got)
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}

// check that they match
c := bytes.Compare(want.Bytes(), got.Bytes())
if c != 0 {
t.Errorf("Expected %v, got %v", want.String(), got.String())
}
}
2 changes: 1 addition & 1 deletion tvsaver/saver2v2/save_snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func renderSnippet2_2(sn *spdx.Snippet2_2, w io.Writer) error {
fmt.Fprintf(w, "SnippetLicenseComments: %s\n", textify(sn.SnippetLicenseComments))
}
if sn.SnippetCopyrightText != "" {
fmt.Fprintf(w, "SnippetCopyrightText: %s\n", sn.SnippetCopyrightText)
fmt.Fprintf(w, "SnippetCopyrightText: %s\n", textify(sn.SnippetCopyrightText))
}
if sn.SnippetComment != "" {
fmt.Fprintf(w, "SnippetComment: %s\n", textify(sn.SnippetComment))
Expand Down
35 changes: 35 additions & 0 deletions tvsaver/saver2v2/save_snippet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,38 @@ SnippetCopyrightText: Copyright (c) John Doe 20x6
t.Errorf("Expected %v, got %v", want.String(), got.String())
}
}

func TestSaver2_2SnippetWrapsCopyrightMultiline(t *testing.T) {
sn := &spdx.Snippet2_2{
SnippetSPDXIdentifier: spdx.ElementID("Snippet17"),
SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292"),
SnippetByteRangeStart: 17,
SnippetByteRangeEnd: 209,
SnippetLicenseConcluded: "GPL-2.0-or-later",
SnippetCopyrightText: `Copyright (c) John Doe 20x6
Copyright (c) John Doe 20x6`,
}

// what we want to get, as a buffer of bytes
want := bytes.NewBufferString(`SnippetSPDXIdentifier: SPDXRef-Snippet17
SnippetFromFileSPDXID: SPDXRef-File292
SnippetByteRange: 17:209
SnippetLicenseConcluded: GPL-2.0-or-later
SnippetCopyrightText: <text>Copyright (c) John Doe 20x6
Copyright (c) John Doe 20x6</text>
`)

// render as buffer of bytes
var got bytes.Buffer
err := renderSnippet2_2(sn, &got)
if err != nil {
t.Errorf("Expected nil error, got %v", err)
}

// check that they match
c := bytes.Compare(want.Bytes(), got.Bytes())
if c != 0 {
t.Errorf("Expected %v, got %v", want.String(), got.String())
}
}

0 comments on commit cb47219

Please sign in to comment.