RenderKid.coffee 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. RenderKid = require '../src/RenderKid'
  2. {strip} = require '../src/AnsiPainter'
  3. match = (input, expected, setStuff) ->
  4. r = new RenderKid
  5. r.style
  6. span:
  7. display: 'inline'
  8. div:
  9. display: 'block'
  10. setStuff?(r)
  11. strip(r.render(input)).trim().should.equal expected.trim()
  12. describe "RenderKid", ->
  13. describe "constructor()", ->
  14. it "should work", ->
  15. new RenderKid
  16. describe "whitespace management - inline", ->
  17. it "shouldn't put extra whitespaces", ->
  18. input = """
  19. a<span>b</span>c
  20. """
  21. expected = """
  22. abc
  23. """
  24. match input, expected
  25. it "should allow 1 whitespace character on each side", ->
  26. input = """
  27. a<span> b </span>c
  28. """
  29. expected = """
  30. a b c
  31. """
  32. match input, expected
  33. it "should eliminate extra whitespaces inside text", ->
  34. input = """
  35. a<span>b1 \n b2</span>c
  36. """
  37. expected = """
  38. ab1 b2c
  39. """
  40. match input, expected
  41. it "should allow line breaks with <br />", ->
  42. input = """
  43. a<span>b1<br />b2</span>c
  44. """
  45. expected = """
  46. ab1\nb2c
  47. """
  48. match input, expected
  49. it "should allow line breaks with &nl;", ->
  50. input = """
  51. a<span>b1&nl;b2</span>c
  52. """
  53. expected = """
  54. ab1\nb2c
  55. """
  56. match input, expected
  57. it "should allow whitespaces with &sp;", ->
  58. input = """
  59. a<span>b1&sp;b2</span>c
  60. """
  61. expected = """
  62. ab1 b2c
  63. """
  64. match input, expected
  65. describe "whitespace management - block", ->
  66. it "should add one linebreak between two blocks", ->
  67. input = """
  68. <div>a</div>
  69. <div>b</div>
  70. """
  71. expected = """
  72. a
  73. b
  74. """
  75. match input, expected
  76. it "should ignore empty blocks", ->
  77. input = """
  78. <div>a</div>
  79. <div></div>
  80. <div>b</div>
  81. """
  82. expected = """
  83. a
  84. b
  85. """
  86. match input, expected
  87. it "should add an extra linebreak between two adjacent blocks inside an inline", ->
  88. input = """
  89. <span>
  90. <div>a</div>
  91. <div>b</div>
  92. </span>
  93. """
  94. expected = """
  95. a
  96. b
  97. """
  98. match input, expected
  99. it "example: div(marginBottom:1)+div", ->
  100. input = """
  101. <div class="first">a</div>
  102. <div>b</div>
  103. """
  104. expected = """
  105. a
  106. b
  107. """
  108. match input, expected, (r) ->
  109. r.style '.first': marginBottom: 1
  110. it "example: div+div(marginTop:1)", ->
  111. input = """
  112. <div>a</div>
  113. <div class="second">b</div>
  114. """
  115. expected = """
  116. a
  117. b
  118. """
  119. match input, expected, (r) ->
  120. r.style '.second': marginTop: 1
  121. it "example: div(marginBottom:1)+div(marginTop:1)", ->
  122. input = """
  123. <div class="first">a</div>
  124. <div class="second">b</div>
  125. """
  126. expected = """
  127. a
  128. b
  129. """
  130. match input, expected, (r) ->
  131. r.style
  132. '.first': marginBottom: 1
  133. '.second': marginTop: 1
  134. it "example: div(marginBottom:2)+div(marginTop:1)", ->
  135. input = """
  136. <div class="first">a</div>
  137. <div class="second">b</div>
  138. """
  139. expected = """
  140. a
  141. b
  142. """
  143. match input, expected, (r) ->
  144. r.style
  145. '.first': marginBottom: 2
  146. '.second': marginTop: 1
  147. it "example: div(marginBottom:2)+span+div(marginTop:1)", ->
  148. input = """
  149. <div class="first">a</div>
  150. <span>span</span>
  151. <div class="second">b</div>
  152. """
  153. expected = """
  154. a
  155. span
  156. b
  157. """
  158. match input, expected, (r) ->
  159. r.style
  160. '.first': marginBottom: 2
  161. '.second': marginTop: 1