1 | cc = require '../lib/coffeecup'
|
2 |
|
3 | describe 'CoffeeScript helper (function)', ->
|
4 | describe "coffeescript -> alert 'hi'", ->
|
5 | coffeescript_helper = """
|
6 | var __slice = Array.prototype.slice;
|
7 | var __hasProp = Object.prototype.hasOwnProperty;
|
8 | var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
9 | var __extends = function(child, parent) {
|
10 | for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
11 | function ctor() { this.constructor = child; }
|
12 | ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype;
|
13 | return child; };
|
14 | var __indexOf = Array.prototype.indexOf || function(item) {
|
15 | for (var i = 0, l = this.length; i < l; i++) {
|
16 | if (this[i] === item) return i;
|
17 | } return -1; };
|
18 | """.replace /\n/g, ''
|
19 | it "should render <script>#{coffeescript_helper}(function () {\n return alert('hi');\n }).call(this);</script>", ->
|
20 | h = -> coffeescript -> alert 'hi'
|
21 | cc.render(h).should.equal "<script>#{coffeescript_helper}(function () {\n return alert('hi');\n }).call(this);</script>"
|
22 |
|
23 | describe 'CoffeeScript helper (string)', ->
|
24 | describe 'coffeescript "alert \'hi\'\"', ->
|
25 | it 'should render <script type="text/coffeescript">alert \'hi\'</script>', ->
|
26 | h = -> coffeescript "alert 'hi'"
|
27 | cc.render(h).should.equal '<script type="text/coffeescript">alert \'hi\'</script>'
|
28 |
|
29 | describe 'CoffeeScript helper (object)', ->
|
30 | describe "coffeescript src: 'script.coffee'", ->
|
31 | it 'should render <script src="script.coffee" type="text/coffeescript"></script>', ->
|
32 | h = -> coffeescript src: 'script.coffee'
|
33 | cc.render(h).should.equal '<script src="script.coffee" type="text/coffeescript"></script>'
|
34 |
|
35 | describe 'CoffeeScript helper (function) optimized', ->
|
36 | describe "coffeescript -> alert 'hi'", ->
|
37 | coffeescript_helper = """
|
38 | var __slice = Array.prototype.slice;
|
39 | var __hasProp = Object.prototype.hasOwnProperty;
|
40 | var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
41 | var __extends = function(child, parent) {
|
42 | for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
43 | function ctor() { this.constructor = child; }
|
44 | ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype;
|
45 | return child; };
|
46 | var __indexOf = Array.prototype.indexOf || function(item) {
|
47 | for (var i = 0, l = this.length; i < l; i++) {
|
48 | if (this[i] === item) return i;
|
49 | } return -1; };
|
50 | """.replace /\n/g, ''
|
51 | it "should render <script>#{coffeescript_helper}(function () {\n return alert('hi');\n }).call(this);</script>", ->
|
52 | h = -> coffeescript -> alert 'hi'
|
53 | cc.render(h, optimized: true).should.equal "<script>#{coffeescript_helper}(function () {\n return alert('hi');\n }).call(this);</script>"
|
54 |
|
55 | describe 'CoffeeScript helper (string) optimized', ->
|
56 | describe 'coffeescript "alert \'hi\'\"', ->
|
57 | it 'should render <script type="text/coffeescript">alert \'hi\'</script>', ->
|
58 | h = -> coffeescript "alert 'hi'"
|
59 | cc.render(h, optimized: true).should.equal '<script type="text/coffeescript">alert \'hi\'</script>'
|
60 |
|
61 | describe 'CoffeeScript helper (object) optimized', ->
|
62 | describe "coffeescript src: 'script.coffee'", ->
|
63 | it 'should render <script src="script.coffee" type="text/coffeescript"></script>', ->
|
64 | h = -> coffeescript src: 'script.coffee'
|
65 | cc.render(h, optimized: true).should.equal '<script src="script.coffee" type="text/coffeescript"></script>'
|
66 |
|
67 |
|