match_data_test.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. suite('lunr.MatchData', function () {
  2. suite('#combine', function () {
  3. setup(function () {
  4. this.match = new lunr.MatchData('foo', 'title', {
  5. position: [1]
  6. })
  7. this.match.combine(new lunr.MatchData('bar', 'title', {
  8. position: [2]
  9. }))
  10. this.match.combine(new lunr.MatchData('baz', 'body', {
  11. position: [3]
  12. }))
  13. this.match.combine(new lunr.MatchData('baz', 'body', {
  14. position: [4]
  15. }))
  16. })
  17. test('#terms', function () {
  18. assert.sameMembers(['foo', 'bar', 'baz'], Object.keys(this.match.metadata))
  19. })
  20. test('#metadata', function () {
  21. assert.deepEqual(this.match.metadata.foo.title.position, [1])
  22. assert.deepEqual(this.match.metadata.bar.title.position, [2])
  23. assert.deepEqual(this.match.metadata.baz.body.position, [3, 4])
  24. })
  25. test('does not mutate source data', function () {
  26. var metadata = { foo: [1] },
  27. matchData1 = new lunr.MatchData('foo', 'title', metadata),
  28. matchData2 = new lunr.MatchData('foo', 'title', metadata)
  29. matchData1.combine(matchData2)
  30. assert.deepEqual(metadata.foo, [1])
  31. })
  32. })
  33. })