'use strict'

/* eslint-env es6,node */

const test = require('tape')
const decode = require('../lazy')

const test_if = (cond, title, impl) => cond ? test(title, impl) : test.skip(title, impl)
const NODE_VER = parseInt(process.versions.node)

test_if(NODE_VER > 4, 'lazy dict', t => {
  const torrent = decode('d2:abi4e2:bci1e2:bei44e2:bble2:aale2:dxlee')

  t.true('ab' in torrent)
  t.is(torrent.ab, 4)
  t.is(torrent.x, void 0)
  t.deepEqual(Reflect.ownKeys(torrent).sort(), ['aa', 'ab', 'bb', 'bc', 'be', 'dx'])
  t.deepEqual(torrent, {})

  t.end()
})

test_if(NODE_VER > 4,'lazy list', t => {
  const torrent = decode('d2:abli4eee')

  t.deepEqual(torrent.ab, [4])
  t.end()
})

test_if(NODE_VER > 4,'lazy throws', t => {
  const torrent = decode('d2:abi4ee')

  t.throws(() => {
    torrent.x = 1
  }, `You can't change prop x`)

  t.throws(() => {
    delete torrent.ab
  }, `You can't delete prop ab`)

  t.end()
})


@@ -34,21 +34,19 @@
 ode */%0A%0A
-const
+var
  test = 
@@ -61,21 +61,19 @@
 'tape')%0A
-const
+var
  decode 
@@ -94,21 +94,19 @@
 lazy')%0A%0A
-const
+var
  test_if
@@ -181,21 +181,19 @@
 , impl)%0A
-const
+var
  NODE_VE
@@ -265,37 +265,35 @@
 dict', t =%3E %7B%0A  
-const
+var
  torrent = decod
@@ -577,37 +577,35 @@
 list', t =%3E %7B%0A  
-const
+var
  torrent = decod
@@ -716,13 +716,11 @@
 %7B%0A  
-const
+var
  tor

const => var