| 1 |
package namespace |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
) |
| 6 |
|
| 7 |
func TestNew(t *testing.T) { |
| 8 |
|
| 9 |
sampleURI := "https://www.spdx.org/rdf/terms" |
| 10 |
_, err := New(sampleURI) |
| 11 |
if err != nil { |
| 12 |
t.Errorf("error parsing a valid URI") |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
invalidURI := "invalid uri" |
| 17 |
_, err = New(invalidURI) |
| 18 |
if err == nil { |
| 19 |
t.Errorf("expected an error stating invalid URI") |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
func TestNamespace_Get(t *testing.T) { |
| 24 |
sampleURI := "https://www.spdx.org/rdf/terms" |
| 25 |
sampleNS, err := New(sampleURI) |
| 26 |
if err != nil { |
| 27 |
t.Errorf("error parsing a valid URI") |
| 28 |
return |
| 29 |
} |
| 30 |
fragment := "name" |
| 31 |
indexedURI := sampleNS.Get(fragment) |
| 32 |
if indexedURI.String() != sampleURI+"#"+fragment { |
| 33 |
t.Errorf("error adding fragment to the base URI") |
| 34 |
} |
| 35 |
} |