Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. var test = require('tape')
  2. var endent = require('./')
  3. test('object', t => {
  4. t.plan(1)
  5. var json = JSON.stringify(JSON.parse('[ "abc" ]'), null, 2)
  6. var someobj = {
  7. contact: {
  8. jack: '123456',
  9. tom: '654321'
  10. },
  11. name: 'template',
  12. color: 'blue',
  13. animals: ['bear', 'fish', 'dog', 'cat']
  14. }
  15. var colors = ['red', 'pink', 'white']
  16. var objectName = 'someobj'
  17. var dependencies = ['jquery', 'underscore', 'bootstrap']
  18. var dependencyTmpl = ``
  19. dependencies.forEach((d, i) => {
  20. dependencyTmpl += `var ${d} = require("${d}")\n`
  21. })
  22. var jsFile = endent`
  23. ${dependencyTmpl}
  24. module.exports = store
  25. function store (state, emitter) {
  26. emitter.on("DOMContentLoaded", function () {
  27. state["json"] = ${json}
  28. state["${objectName}"] = ${endent.pretty(someobj)}
  29. state["colors"] = ${endent.pretty(colors)}
  30. state["name"] = "${endent.pretty('jack')}"
  31. state["name2"] = "${'tom'}"
  32. state["number"] = ${endent.pretty(123)}
  33. state["number2"] = ${123}
  34. state["Iamundefined"] = ${endent.pretty()}
  35. state["Iamnull"] = ${endent.pretty(null)}
  36. state["Iamregexp"] = ${endent.pretty(/abc/)}
  37. })
  38. }
  39. `
  40. t.equal(jsFile, `var jquery = require("jquery")
  41. var underscore = require("underscore")
  42. var bootstrap = require("bootstrap")
  43. module.exports = store
  44. function store (state, emitter) {
  45. emitter.on("DOMContentLoaded", function () {
  46. state["json"] = [
  47. "abc"
  48. ]
  49. state["someobj"] = {
  50. "contact": {
  51. "jack": "123456",
  52. "tom": "654321"
  53. },
  54. "name": "template",
  55. "color": "blue",
  56. "animals": [
  57. "bear",
  58. "fish",
  59. "dog",
  60. "cat"
  61. ]
  62. }
  63. state["colors"] = [
  64. "red",
  65. "pink",
  66. "white"
  67. ]
  68. state["name"] = "jack"
  69. state["name2"] = "tom"
  70. state["number"] = 123
  71. state["number2"] = 123
  72. state["Iamundefined"] = undefined
  73. state["Iamnull"] = null
  74. state["Iamregexp"] = /abc/
  75. })
  76. }`)
  77. })
  78. test('string', t => {
  79. t.plan(1)
  80. const a = `
  81. hello
  82. world`
  83. const b = endent`
  84. foo.
  85. ${a}
  86. bar.`
  87. t.equal(b, `foo.
  88. hello
  89. world
  90. bar.`)
  91. })
  92. test('issue#1', t => {
  93. t.plan(1)
  94. const a = '"test"'
  95. const r = endent`
  96. {
  97. ${a}: null
  98. }
  99. `
  100. t.equal(r, `{
  101. "test": null
  102. }`)
  103. })
  104. test('issue#2', t => {
  105. t.plan(1)
  106. const r = endent`
  107. foo.
  108. x=${'hello\n world'}
  109. bar.
  110. `
  111. console.log(r)
  112. t.equal(r, `foo.
  113. x=hello
  114. world
  115. bar.`)
  116. })