UNPKG

3.56 kBtext/coffeescriptView Raw
1cc = require '../lib/coffeecup'
2
3describe 'CoffeeScript helper (function)', ->
4 describe "coffeescript -> alert 'hi'", ->
5 coffeescript_helper = """
6var __slice = Array.prototype.slice;
7var __hasProp = Object.prototype.hasOwnProperty;
8var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
9var __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; };
14var __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
23describe '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
29describe '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
35describe 'CoffeeScript helper (function) optimized', ->
36 describe "coffeescript -> alert 'hi'", ->
37 coffeescript_helper = """
38var __slice = Array.prototype.slice;
39var __hasProp = Object.prototype.hasOwnProperty;
40var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
41var __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; };
46var __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
55describe '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
61describe '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