Repositorio del curso CCOM4030 el semestre B91 del proyecto kilometro0

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict'
  2. var test = require('tap').test
  3. var Parse = require('./')
  4. function successTests (value) {
  5. test('parse successfully with the function', function (t) {
  6. t.plan(2)
  7. var result = Parse(value)
  8. t.error(result.err)
  9. t.deepEqual(result.value, JSON.parse(value))
  10. })
  11. test('parse successfully with the constructor', function (t) {
  12. t.plan(2)
  13. var result = new Parse(value)
  14. t.error(result.err)
  15. t.deepEqual(result.value, JSON.parse(value))
  16. })
  17. }
  18. function failureTests (value) {
  19. var expectedErr
  20. try {
  21. JSON.parse(value)
  22. } catch (err) {
  23. expectedErr = err
  24. }
  25. test('parse unsuccessfully with the function', function (t) {
  26. t.plan(2)
  27. var result = Parse(value)
  28. t.notOk(result.value, 'no value')
  29. t.equal(result.err.message, expectedErr.message)
  30. })
  31. test('parse successfully with the constructor', function (t) {
  32. t.plan(2)
  33. var result = new Parse(value)
  34. t.notOk(result.value, 'no value')
  35. t.equal(result.err.message, expectedErr.message)
  36. })
  37. }
  38. successTests('{ "object": 32 }')
  39. failureTests('{ "object": 32')