function.test.js 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Created by Wu Jian Ping on - 2022/07/22.
  3. */
  4. const { expect } = require('chai')
  5. const path = require('path')
  6. const Searcher = require('..')
  7. const dbPath = path.join(__dirname, '..', '..', '..', 'data', 'ip2region.xdb')
  8. const buffer = Searcher.loadContentFromFile(dbPath)
  9. const searcher1 = Searcher.newWithBuffer(buffer)
  10. const vectorIndex = Searcher.loadVectorIndexFromFile(dbPath)
  11. const searcher2 = Searcher.newWithVectorIndex(dbPath, vectorIndex)
  12. const searcher3 = Searcher.newWithFileOnly(dbPath)
  13. describe('ip2region', () => {
  14. it('#newWithFileOnly and search', async () => {
  15. const d = await searcher3.search('218.4.167.70')
  16. expect(d.region).equal('中国|0|江苏省|苏州市|电信')
  17. })
  18. it('#newWithVectorIndex and search', async () => {
  19. const d = await searcher2.search('218.4.167.70')
  20. expect(d.region).equal('中国|0|江苏省|苏州市|电信')
  21. })
  22. it('#newWithBuffer and search', async () => {
  23. const d = await searcher1.search('218.4.167.70')
  24. expect(d.region).equal('中国|0|江苏省|苏州市|电信')
  25. })
  26. })