aboutsummaryrefslogtreecommitdiff
path: root/node_modules/renderkid/test/RenderKid.coffee
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/renderkid/test/RenderKid.coffee
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/renderkid/test/RenderKid.coffee')
-rw-r--r--node_modules/renderkid/test/RenderKid.coffee273
1 files changed, 273 insertions, 0 deletions
diff --git a/node_modules/renderkid/test/RenderKid.coffee b/node_modules/renderkid/test/RenderKid.coffee
new file mode 100644
index 00000000..3ca4852f
--- /dev/null
+++ b/node_modules/renderkid/test/RenderKid.coffee
@@ -0,0 +1,273 @@
+RenderKid = require '../src/RenderKid'
+{strip} = require '../src/AnsiPainter'
+
+match = (input, expected, setStuff) ->
+ r = new RenderKid
+ r.style
+ span:
+ display: 'inline'
+ div:
+ display: 'block'
+
+ setStuff?(r)
+ strip(r.render(input)).trim().should.equal expected.trim()
+
+describe "RenderKid", ->
+ describe "constructor()", ->
+ it "should work", ->
+ new RenderKid
+
+ describe "whitespace management - inline", ->
+ it "shouldn't put extra whitespaces", ->
+ input = """
+
+ a<span>b</span>c
+
+ """
+
+ expected = """
+
+ abc
+
+ """
+
+ match input, expected
+
+ it "should allow 1 whitespace character on each side", ->
+ input = """
+
+ a<span> b </span>c
+
+ """
+
+ expected = """
+
+ a b c
+
+ """
+
+ match input, expected
+
+ it "should eliminate extra whitespaces inside text", ->
+ input = """
+
+ a<span>b1 \n b2</span>c
+
+ """
+
+ expected = """
+
+ ab1 b2c
+
+ """
+
+ match input, expected
+
+ it "should allow line breaks with <br />", ->
+ input = """
+
+ a<span>b1<br />b2</span>c
+
+ """
+
+ expected = """
+
+ ab1\nb2c
+
+ """
+
+ match input, expected
+
+ it "should allow line breaks with &nl;", ->
+ input = """
+
+ a<span>b1&nl;b2</span>c
+
+ """
+
+ expected = """
+
+ ab1\nb2c
+
+ """
+
+ match input, expected
+
+ it "should allow whitespaces with &sp;", ->
+ input = """
+
+ a<span>b1&sp;b2</span>c
+
+ """
+
+ expected = """
+
+ ab1 b2c
+
+ """
+
+ match input, expected
+
+ describe "whitespace management - block", ->
+ it "should add one linebreak between two blocks", ->
+ input = """
+
+ <div>a</div>
+ <div>b</div>
+
+ """
+
+ expected = """
+
+ a
+ b
+
+ """
+
+ match input, expected
+
+ it "should ignore empty blocks", ->
+ input = """
+
+ <div>a</div>
+ <div></div>
+ <div>b</div>
+
+ """
+
+ expected = """
+
+ a
+ b
+
+ """
+
+ match input, expected
+
+ it "should add an extra linebreak between two adjacent blocks inside an inline", ->
+ input = """
+
+ <span>
+ <div>a</div>
+ <div>b</div>
+ </span>
+
+ """
+
+ expected = """
+
+ a
+
+ b
+
+ """
+
+ match input, expected
+
+ it "example: div(marginBottom:1)+div", ->
+ input = """
+
+ <div class="first">a</div>
+ <div>b</div>
+
+ """
+
+ expected = """
+
+ a
+
+ b
+
+ """
+
+ match input, expected, (r) ->
+ r.style '.first': marginBottom: 1
+
+ it "example: div+div(marginTop:1)", ->
+ input = """
+
+ <div>a</div>
+ <div class="second">b</div>
+
+ """
+
+ expected = """
+
+ a
+
+ b
+
+ """
+
+ match input, expected, (r) ->
+ r.style '.second': marginTop: 1
+
+ it "example: div(marginBottom:1)+div(marginTop:1)", ->
+ input = """
+
+ <div class="first">a</div>
+ <div class="second">b</div>
+
+ """
+
+ expected = """
+
+ a
+
+
+ b
+
+ """
+
+ match input, expected, (r) ->
+ r.style
+ '.first': marginBottom: 1
+ '.second': marginTop: 1
+
+ it "example: div(marginBottom:2)+div(marginTop:1)", ->
+ input = """
+
+ <div class="first">a</div>
+ <div class="second">b</div>
+
+ """
+
+ expected = """
+
+ a
+
+
+
+ b
+
+ """
+
+ match input, expected, (r) ->
+ r.style
+ '.first': marginBottom: 2
+ '.second': marginTop: 1
+
+ it "example: div(marginBottom:2)+span+div(marginTop:1)", ->
+ input = """
+
+ <div class="first">a</div>
+ <span>span</span>
+ <div class="second">b</div>
+
+ """
+
+ expected = """
+
+ a
+
+
+ span
+
+ b
+
+ """
+
+ match input, expected, (r) ->
+ r.style
+ '.first': marginBottom: 2
+ '.second': marginTop: 1 \ No newline at end of file