diff options
author | Bisakh Mondal <bisakhmondal00@gmail.com> | 2021-03-22 21:52:57 +0530 |
---|---|---|
committer | Bisakh Mondal <bisakhmondal00@gmail.com> | 2021-03-22 21:53:01 +0530 |
commit | 4cd473b27ea6d369b641282c6ec7d67911d3e96d (patch) | |
tree | f2be928029af8b7a207097a82243572815ac5ea5 | |
parent | 42e18199b6c63eb39c1c3ea062e5417e8ab26068 (diff) | |
download | spdx-tools-4cd473b27ea6d369b641282c6ec7d67911d3e96d.tar.gz |
multiline snippet copyright wrapping
Signed-off-by: Bisakh Mondal <bisakhmondal00@gmail.com>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_snippet.go | 2 | ||||
-rw-r--r-- | tvsaver/saver2v1/save_snippet_test.go | 35 | ||||
-rw-r--r-- | tvsaver/saver2v2/save_snippet.go | 2 | ||||
-rw-r--r-- | tvsaver/saver2v2/save_snippet_test.go | 35 |
5 files changed, 73 insertions, 2 deletions
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later .vscode +.idea .DS_Store scratch/* *.swp diff --git a/tvsaver/saver2v1/save_snippet.go b/tvsaver/saver2v1/save_snippet.go index e82bc5a..645f7f5 100644 --- a/tvsaver/saver2v1/save_snippet.go +++ b/tvsaver/saver2v1/save_snippet.go @@ -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)) diff --git a/tvsaver/saver2v1/save_snippet_test.go b/tvsaver/saver2v1/save_snippet_test.go index 88b39c9..536545d 100644 --- a/tvsaver/saver2v1/save_snippet_test.go +++ b/tvsaver/saver2v1/save_snippet_test.go @@ -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()) + } +} diff --git a/tvsaver/saver2v2/save_snippet.go b/tvsaver/saver2v2/save_snippet.go index 5cf2f2a..a8ede6c 100644 --- a/tvsaver/saver2v2/save_snippet.go +++ b/tvsaver/saver2v2/save_snippet.go @@ -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)) diff --git a/tvsaver/saver2v2/save_snippet_test.go b/tvsaver/saver2v2/save_snippet_test.go index 72378b4..c4b16bd 100644 --- a/tvsaver/saver2v2/save_snippet_test.go +++ b/tvsaver/saver2v2/save_snippet_test.go @@ -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()) + } +} |