/**
 * Test Dependencies
 */
import './helper.js'
import chai from 'chai'
const expect = chai.expect
import sinonChai from 'sinon-chai'
chai.use(sinonChai)

import { Pointer } from '../src/pointer.js'

describe('Pointer', () => {
  describe('new Pointer', () => {
    it('""', () => {
      const pointer = new Pointer('')

      expect(pointer._path).to.equal('')
      expect(pointer._steps).to.be.undefined
      expect(pointer._topic).to.be.undefined

      expect(pointer.path).to.equal('')
      expect(pointer.steps).to.eql([])
      expect(pointer.topic).to.equal('#')

      expect(pointer.length).to.equal(0)

      expect(pointer == '').to.be.true
    })

    it('"/a"', () => {
      const pointer = new Pointer('/a')

      expect(pointer._path).to.equal('/a')
      expect(pointer._steps).to.be.undefined
      expect(pointer._topic).to.be.undefined

      expect(pointer.path).to.equal('/a')
      expect(pointer.steps).to.eql(['a'])
      expect(pointer.topic).to.equal('a')

      expect(pointer.length).to.equal(1)

      expect(pointer == '/a').to.be.true
    })

    it('"/a/b"', () => {
      const pointer = new Pointer('/a/b')

      expect(pointer._path).to.equal('/a/b')
      expect(pointer._steps).to.be.undefined
      expect(pointer._topic).to.be.undefined

      expect(pointer.path).to.equal('/a/b')
      expect(pointer.steps).to.eql(['a', 'b'])
      expect(pointer.topic).to.equal('a/b')

      expect(pointer.length).to.equal(2)

      expect(pointer == '/a/b').to.be.true
    })

    it('[]', () => {
      const pointer = new Pointer([])

      expect(pointer._path).to.be.undefined
      expect(pointer._steps).to.eql([])
      expect(pointer._topic).to.be.undefined

      expect(pointer.path).to.equal('')
      expect(pointer.steps).to.eql([])
      expect(pointer.topic).to.equal('#')

      expect(pointer.length).to.equal(0)

      expect(pointer == '').to.be.true
    })

    it('["a"]', () => {
      const pointer = new Pointer(['a'])

      expect(pointer._path).to.be.undefined
      expect(pointer._steps).to.eql(['a'])
      expect(pointer._topic).to.be.undefined

      expect(pointer.path).to.equal('/a')
      expect(pointer.steps).to.eql(['a'])
      expect(pointer.topic).to.equal('a')

      expect(pointer.length).to.equal(1)

      expect(pointer == '/a').to.be.true
    })

    it('["a", "b"]', () => {
      const pointer = new Pointer(['a', 'b'])

      expect(pointer._path).to.be.undefined
      expect(pointer._steps).to.eql(['a', 'b'])
      expect(pointer._topic).to.be.undefined

      expect(pointer.path).to.equal('/a/b')
      expect(pointer.steps).to.eql(['a', 'b'])
      expect(pointer.topic).to.equal('a/b')

      expect(pointer.length).to.equal(2)

      expect(pointer == '/a/b').to.be.true
    })

    it('"#"', () => {
      const pointer = new Pointer('#')

      expect(pointer._path).to.be.undefined
      expect(pointer._steps).to.be.undefined
      expect(pointer._topic).to.equal('#')

      expect(pointer.path).to.equal('')
      expect(pointer.steps).to.eql([])
      expect(pointer.topic).to.equal('#')

      expect(pointer.length).to.equal(0)

      expect(pointer == '').to.be.true
    })

    it('"a"', () => {
      const pointer = new Pointer('a')

      expect(pointer._path).to.be.undefined
      expect(pointer._steps).to.be.undefined
      expect(pointer._topic).to.equal('a')

      expect(pointer.path).to.equal('/a')
      expect(pointer.steps).to.eql(['a'])
      expect(pointer.topic).to.equal('a')

      expect(pointer.length).to.equal(1)

      expect(pointer == '/a').to.be.true
    })

    it('"a/b"', () => {
      const pointer = new Pointer('a/b')

      expect(pointer._path).to.be.undefined
      expect(pointer._steps).to.be.undefined
      expect(pointer._topic).to.equal('a/b')

      expect(pointer.path).to.equal('/a/b')
      expect(pointer.steps).to.eql(['a', 'b'])
      expect(pointer.topic).to.equal('a/b')

      expect(pointer.length).to.equal(2)

      expect(pointer == '/a/b').to.be.true
    })
  })

  describe('pointer.path =', () => {
    it('"/a"', () => {
      const pointer = new Pointer('')
      pointer.path = '/a'

      expect(pointer._path).to.equal('/a')
      expect(pointer._steps).to.be.undefined
      expect(pointer._topic).to.be.undefined

      expect(pointer.path).to.equal('/a')
      expect(pointer.steps).to.eql(['a'])
      expect(pointer.topic).to.equal('a')

      expect(pointer.length).to.equal(1)

      expect(pointer == '/a').to.be.true
    })

    it('"/a/b"', () => {
      const pointer = new Pointer('')
      pointer.path = '/a/b'

      expect(pointer._path).to.equal('/a/b')
      expect(pointer._steps).to.be.undefined
      expect(pointer._topic).to.be.undefined

      expect(pointer.path).to.equal('/a/b')
      expect(pointer.steps).to.eql(['a', 'b'])
      expect(pointer.topic).to.equal('a/b')

      expect(pointer.length).to.equal(2)

      expect(pointer == '/a/b').to.be.true
    })
  })

  describe('pointer.steps =', () => {
    it('["a"]', () => {
      const pointer = new Pointer([])
      pointer.steps = ['a']

      expect(pointer._path).to.be.undefined
      expect(pointer._steps).to.eql(['a'])
      expect(pointer._topic).to.be.undefined

      expect(pointer.path).to.equal('/a')
      expect(pointer.steps).to.eql(['a'])
      expect(pointer.topic).to.equal('a')

      expect(pointer.length).to.equal(1)

      expect(pointer == '/a').to.be.true
    })

    it('["a", "b"]', () => {
      const pointer = new Pointer([])
      pointer.steps = ['a', 'b']

      expect(pointer._path).to.be.undefined
      expect(pointer._steps).to.eql(['a', 'b'])
      expect(pointer._topic).to.be.undefined

      expect(pointer.path).to.equal('/a/b')
      expect(pointer.steps).to.eql(['a', 'b'])
      expect(pointer.topic).to.equal('a/b')

      expect(pointer.length).to.equal(2)

      expect(pointer == '/a/b').to.be.true
    })
  })

  describe('pointer.topic =', () => {
    it('"a"', () => {
      const pointer = new Pointer('#')
      pointer.topic = 'a'

      expect(pointer._path).to.be.undefined
      expect(pointer._steps).to.be.undefined
      expect(pointer._topic).to.equal('a')

      expect(pointer.path).to.equal('/a')
      expect(pointer.steps).to.eql(['a'])
      expect(pointer.topic).to.equal('a')

      expect(pointer.length).to.equal(1)

      expect(pointer == '/a').to.be.true
    })

    it('"a/b"', () => {
      const pointer = new Pointer('#')
      pointer.topic = 'a/b'

      expect(pointer._path).to.be.undefined
      expect(pointer._steps).to.be.undefined
      expect(pointer._topic).to.equal('a/b')

      expect(pointer.path).to.equal('/a/b')
      expect(pointer.steps).to.eql(['a', 'b'])
      expect(pointer.topic).to.equal('a/b')

      expect(pointer.length).to.equal(2)

      expect(pointer == '/a/b').to.be.true
    })
  })
})