-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from specter25/jsonparser1
[GSoC'21] Pr:3 . bugfixes in json parser 2v2
- Loading branch information
Showing
26 changed files
with
182 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later | ||
|
||
package jsonloader | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
|
||
parser2v2 "github.com/spdx/tools-golang/jsonloader/parser2v2" | ||
"github.com/spdx/tools-golang/spdx" | ||
) | ||
|
||
// Takes in a file Reader and returns the pertaining spdx document | ||
// or the error if any is encountered while setting the doc. | ||
func Load2_2(content io.Reader) (*spdx.Document2_2, error) { | ||
//convert io.Reader to a slice of bytes and call the parser | ||
buf := new(bytes.Buffer) | ||
buf.ReadFrom(content) | ||
var doc, err = parser2v2.Load2_2(buf.Bytes()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return doc, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later | ||
|
||
package jsonloader | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/spdx/tools-golang/spdx" | ||
) | ||
|
||
func TestLoad2_2(t *testing.T) { | ||
|
||
file, err := os.Open("./parser2v2/jsonfiles/jsonloadertest.json") | ||
if err != nil { | ||
panic(fmt.Errorf("error opening File: %s", err)) | ||
} | ||
|
||
type args struct { | ||
content io.Reader | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *spdx.Document2_2 | ||
wantErr bool | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "success test", | ||
args: args{ | ||
content: file, | ||
}, | ||
want: &spdx.Document2_2{ | ||
CreationInfo: &spdx.CreationInfo2_2{ | ||
DataLicense: "CC0-1.0", | ||
SPDXVersion: "SPDX-2.2", | ||
SPDXIdentifier: "DOCUMENT", | ||
DocumentName: "SPDX-Tools-v2.0", | ||
ExternalDocumentReferences: make(map[string]spdx.ExternalDocumentRef2_2), | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := Load2_2(tt.args.content) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("Load2_2() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got.CreationInfo, tt.want.CreationInfo) { | ||
t.Errorf("Load2_2() = %v, want %v", got.CreationInfo, tt.want.CreationInfo) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"SPDXID" : "SPDXRef-DOCUMENT", | ||
"spdxVersion" : "SPDX-2.2", | ||
"name" : "SPDX-Tools-v2.0", | ||
"dataLicense" : "CC0-1.0" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
jsonloader2v2/parse_annotations.go → jsonloader/parser2v2/parse_annotations.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
jsonloader2v2/parse_annotations_test.go → ...oader/parser2v2/parse_annotations_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
jsonloader2v2/parse_creation_info.go → jsonloader/parser2v2/parse_creation_info.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
jsonloader2v2/parse_creation_info_test.go → ...der/parser2v2/parse_creation_info_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
jsonloader2v2/parse_files.go → jsonloader/parser2v2/parse_files.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
jsonloader2v2/parse_files_test.go → jsonloader/parser2v2/parse_files_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
jsonloader2v2/parse_other_license.go → jsonloader/parser2v2/parse_other_license.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
jsonloader2v2/parse_other_license_test.go → ...der/parser2v2/parse_other_license_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
jsonloader2v2/parse_package_test.go → jsonloader/parser2v2/parse_package_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
jsonloader2v2/parse_reationship.go → jsonloader/parser2v2/parse_relationship.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
jsonloader2v2/parse_reationship_test.go → ...ader/parser2v2/parse_relationship_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.