const t = require('ava')
const Parser = require('..').Parser

t('no ruby should do nothing', t => {
  let p = new Parser()
  t.deepEqual(p.parse('abc').join(''), 'abc')
})

t('no ruby should do nothing with possible auto', t => {
  let p = new Parser()
  t.deepEqual(p.parse('aあ字').join(''), 'aあ字')
})

t('parse should return undefined', t => {
  let p = new Parser()
  t.is(p.parse(), undefined)
})

t('auto parse with surrounding characters', t => {
  let p = new Parser()
  let result = p.parse('ab字（じ）cd')
  t.deepEqual([...result], ['ab', { rb: '字', rt: 'じ' }, 'cd'])
})

t('auto parse 2 characters', t => {
  let p = new Parser()
  let result = p.parse('今日（きょう）').filter(Boolean)
  t.deepEqual([...result], [{ rb: '今日', rt: 'きょう' }])
})

t('force parse', t => {
  let p = new Parser()
  let result = p.parse('（（cm））（センチ）').filter(Boolean)
  t.deepEqual([...result], [{ rb: 'cm', rt: 'センチ' }])
})

t('force parse with surrounding characters', t => {
  let p = new Parser()
  let result = p.parse('5（（cm））（センチ）/ms')
  t.deepEqual([...result], ['5', { rb: 'cm', rt: 'センチ' }, '/ms'])
})

t('inactive ruby + force ruby', t => {
  let p = new Parser()
  let result = p.parse('5000（（%））（パーセント）')
  t.deepEqual([...result], ['5000', { rb: '%', rt: 'パーセント' }])
})

t('parse isolated rb', t => {
  let p = new Parser()
  t.is(p.parse('a（（z））b').join(''), 'azb')
})

t('end with isolated rb', t => {
  let p = new Parser()
  t.is(p.parse('（（z））').join(''), 'z')
})

t("don't parse cut-off delimiters", t => {
  let p = new Parser()
  t.is(p.parse('a（（z）').join(''), 'a（（z）')
})

t('end with auto char', t => {
  let p = new Parser()
  t.is(p.parse('字').join(''), '字')
})

t('end with open rt', t => {
  let p = new Parser()
  t.is(p.parse('（（ji））（じ').join(''), 'ji（じ')
})

t('custom delimiters', t => {
  let p = new Parser()
  p.openRt = '【'
  p.closeRt = '】'
  p.openRb = '≪'
  p.closeRb = '≫'
  let result = p.parse('今日【きょう】6【ろく】7≪cm≫【センチ】')
  t.deepEqual(
    [...result],
    [
      { rb: '今日', rt: 'きょう' },
      { rb: '6', rt: 'ろく' },
      '7',
      { rb: 'cm', rt: 'センチ' }
    ]
  )
})

t('has ruby', t => {
  let p = new Parser()
  t.falsy(p.parse('abc').hasRuby)
  t.truthy(p.parse('字（じ）').hasRuby)
})

t('parse ka and noma', t => {
  let p = new Parser()
  let result = p.parse('ヶ（か）々（び）')
  t.deepEqual(
    [...result],
    [
      { rb: 'ヶ', rt: 'か' },
      { rb: '々', rt: 'び' }
    ]
  )
})

@@ -1761,16 +1761,198 @@
 %E3%81%98')%0A%7D)%0A%0A
+t('empty rt', t =%3E %7B%0A  let p = new Parser()%0A  let result = p.parse('%E6%95%99%EF%BC%88%E3%81%8D%E3%82%87%E3%81%86%EF%BC%89%E7%A7%91%EF%BC%88%EF%BC%89%E6%9B%B8%EF%BC%88%E3%81%97%E3%82%87%EF%BC%89')%0A  t.deepEqual(%0A    %5B...result%5D,%0A    %5B%7B rb: '%E6%95%99', rt: '%E3%81%8D%E3%82%87%E3%81%86' %7D, '%E7%A7%91', %7B rb: '%E6%9B%B8', rt: '%E3%81%97%E3%82%87' %7D%5D%0A  )%0A%7D)%0A%0A
 t('custo

add test for empty rt