term_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package gold
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "strings"
  5. "testing"
  6. )
  7. func TestLiteralEqual(t *testing.T) {
  8. var t1 Literal
  9. t1.Value = "test1"
  10. t1.Language = "en"
  11. assert.True(t, t1.Equal(NewLiteralWithLanguage("test1", "en")))
  12. assert.False(t, t1.Equal(NewLiteralWithLanguage("test2", "en")))
  13. assert.True(t, t1.Equal(NewLiteralWithLanguage("test1", "en")))
  14. assert.False(t, t1.Equal(NewLiteralWithLanguage("test1", "fr")))
  15. t1.Language = ""
  16. t1.Datatype = NewResource("http://www.w3.org/2001/XMLSchema#string")
  17. assert.False(t, t1.Equal(NewLiteral("test1")))
  18. assert.True(t, t1.Equal(NewLiteralWithDatatype("test1", NewResource("http://www.w3.org/2001/XMLSchema#string"))))
  19. assert.False(t, t1.Equal(NewLiteralWithDatatype("test1", NewResource("http://www.w3.org/2001/XMLSchema#int"))))
  20. }
  21. func TestNewLiteralWithLanguage(t *testing.T) {
  22. s := NewLiteralWithLanguage("test", "en")
  23. assert.Equal(t, "\"test\"@en", s.String())
  24. }
  25. func TestNewLiteralWithDatatype(t *testing.T) {
  26. s := NewLiteralWithDatatype("test", NewResource("http://www.w3.org/2001/XMLSchema#string"))
  27. assert.Equal(t, "\"test\"^^<http://www.w3.org/2001/XMLSchema#string>", s.String())
  28. }
  29. func TestNewLiteralWithLanguageAndDatatype(t *testing.T) {
  30. s := NewLiteralWithLanguageAndDatatype("test", "en", NewResource("http://www.w3.org/2001/XMLSchema#string"))
  31. assert.Equal(t, "\"test\"@en", s.String())
  32. s = NewLiteralWithLanguageAndDatatype("test", "", NewResource("http://www.w3.org/2001/XMLSchema#string"))
  33. assert.Equal(t, "\"test\"^^<http://www.w3.org/2001/XMLSchema#string>", s.String())
  34. }
  35. func TestNewBlankNode(t *testing.T) {
  36. id := NewBlankNode("n1")
  37. assert.Equal(t, "_:n1", id.String())
  38. }
  39. func TestNewAnonNode(t *testing.T) {
  40. id := NewAnonNode()
  41. assert.True(t, strings.Contains(id.String(), "_:anon"))
  42. }
  43. func TestBNodeEqual(t *testing.T) {
  44. var id1 BlankNode
  45. id1.ID = "n1"
  46. id2 := NewBlankNode("n1")
  47. assert.True(t, id1.Equal(id2))
  48. id3 := NewBlankNode("n2")
  49. assert.False(t, id1.Equal(id3))
  50. }