// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
package parser2v2
import (
"reflect"
"testing"
gordfParser "github.com/spdx/gordf/rdfloader/parser"
)
func Test_rdfParser2_2_getExtractedLicensingInfoFromNode(t *testing.T) {
var parser *rdfParser2_2
var err error
var node *gordfParser.Node
// TestCase 1: invalid predicate must raise an error
parser, _ = parserFromBodyContent(`
LicenseRef-Freeware
freeware
`)
node = parser.gordfParserObj.Triples[0].Subject
_, err = parser.getExtractedLicensingInfoFromNode(node)
if err == nil {
t.Errorf("expected an error saying invalid predicate, got ")
}
// TestCase 2: valid input
parser, _ = parserFromBodyContent(`
LicenseRef-Freeware
freeware
`)
node = parser.gordfParserObj.Triples[0].Subject
_, err = parser.getExtractedLicensingInfoFromNode(node)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
}
func Test_rdfParser2_2_extractedLicenseToOtherLicense(t *testing.T) {
// nothing to test for this function.
parser, _ := parserFromBodyContent(`
LicenseRef-Freeware
freeware
`)
node := parser.gordfParserObj.Triples[0].Subject
extLicense, _ := parser.getExtractedLicensingInfoFromNode(node)
othLic := parser.extractedLicenseToOtherLicense(extLicense)
if othLic.LicenseIdentifier != extLicense.licenseID {
t.Errorf("expected %v, got %v", othLic.LicenseIdentifier, extLicense.licenseID)
}
if othLic.ExtractedText != extLicense.extractedText {
t.Errorf("expected %v, got %v", othLic.ExtractedText, extLicense.extractedText)
}
if othLic.LicenseComment != extLicense.comment {
t.Errorf("expected %v, got %v", othLic.LicenseComment, extLicense.comment)
}
if !reflect.DeepEqual(othLic.LicenseCrossReferences, extLicense.seeAlso) {
t.Errorf("expected %v, got %v", othLic.LicenseCrossReferences, extLicense.seeAlso)
}
if othLic.LicenseName != extLicense.name {
t.Errorf("expected %v, got %v", othLic.LicenseName, extLicense.name)
}
}