field_ref_test.js 1016 B

1234567891011121314151617181920212223242526272829303132333435
  1. suite('lunr.FieldRef', function () {
  2. suite('#toString', function () {
  3. test('combines document ref and field name', function () {
  4. var fieldName = "title",
  5. documentRef = "123",
  6. fieldRef = new lunr.FieldRef (documentRef, fieldName)
  7. assert.equal(fieldRef.toString(), "title/123")
  8. })
  9. })
  10. suite('.fromString', function () {
  11. test('splits string into parts', function () {
  12. var fieldRef = lunr.FieldRef.fromString("title/123")
  13. assert.equal(fieldRef.fieldName, "title")
  14. assert.equal(fieldRef.docRef, "123")
  15. })
  16. test('docRef contains join character', function () {
  17. var fieldRef = lunr.FieldRef.fromString("title/http://example.com/123")
  18. assert.equal(fieldRef.fieldName, "title")
  19. assert.equal(fieldRef.docRef, "http://example.com/123")
  20. })
  21. test('string does not contain join character', function () {
  22. var s = "docRefOnly"
  23. assert.throws(function () {
  24. lunr.FieldRef.fromString(s)
  25. })
  26. })
  27. })
  28. })