1 | (function() {
|
2 | var Assemble, Handlebars;
|
3 |
|
4 | require('should');
|
5 |
|
6 | Handlebars = require('handlebars');
|
7 |
|
8 | Assemble = require('../lib/helpers-lib');
|
9 |
|
10 | describe('toFixed', function() {
|
11 | describe('{{toFixed value}}', function() {
|
12 | return it('should return the value rounded to the nearest integer.', function() {
|
13 | var context, source, template;
|
14 |
|
15 | source = '{{toFixed value}}';
|
16 | template = Handlebars.compile(source);
|
17 | context = {
|
18 | value: 5.53231
|
19 | };
|
20 | return template(context).should.equal('6');
|
21 | });
|
22 | });
|
23 | return describe('{{toFixed value 3}}', function() {
|
24 | return it('should return the value rounded exactly n digits after the decimal place.', function() {
|
25 | var context, source, template;
|
26 |
|
27 | source = '{{toFixed value 3}}';
|
28 | template = Handlebars.compile(source);
|
29 | context = {
|
30 | value: 5.53231
|
31 | };
|
32 | return template(context).should.equal('5.532');
|
33 | });
|
34 | });
|
35 | });
|
36 |
|
37 | describe('toPrecision', function() {
|
38 | describe('{{toPrecision value}}', function() {
|
39 | return it('Returns the number in fixed-point or exponential notation rounded to n significant digits.', function() {
|
40 | var context, source, template;
|
41 |
|
42 | source = '{{toPrecision value}}';
|
43 | template = Handlebars.compile(source);
|
44 | context = {
|
45 | value: 555.322
|
46 | };
|
47 | return template(context).should.equal('6e+2');
|
48 | });
|
49 | });
|
50 | return describe('{{toPrecision value 4}}', function() {
|
51 | return it('should return the value rounded exactly n digits after the decimal place.', function() {
|
52 | var context, source, template;
|
53 |
|
54 | source = '{{toPrecision value 4}}';
|
55 | template = Handlebars.compile(source);
|
56 | context = {
|
57 | value: 555.322
|
58 | };
|
59 | return template(context).should.equal('555.3');
|
60 | });
|
61 | });
|
62 | });
|
63 |
|
64 | describe('toExponential', function() {
|
65 | describe('{{toExponential value}}', function() {
|
66 | return it('should return the number in fixed-point or exponential notation rounded to n significant digits.', function() {
|
67 | var context, source, template;
|
68 |
|
69 | source = '{{toExponential value}}';
|
70 | template = Handlebars.compile(source);
|
71 | context = {
|
72 | value: 5
|
73 | };
|
74 | return template(context).should.equal('5e+0');
|
75 | });
|
76 | });
|
77 | return describe('{{toExponential value 5}}', function() {
|
78 | return it('should return the number in fixed-point or exponential notation rounded to exactly n significant digits.', function() {
|
79 | var context, source, template;
|
80 |
|
81 | source = '{{toExponential value 5}}';
|
82 | template = Handlebars.compile(source);
|
83 | context = {
|
84 | value: 5
|
85 | };
|
86 | return template(context).should.equal('5.00000e+0');
|
87 | });
|
88 | });
|
89 | });
|
90 |
|
91 | describe('toInt', function() {
|
92 | return describe('{{toInt value}}', function() {
|
93 | return it('should return an integer.', function() {
|
94 | var context, source, template;
|
95 |
|
96 | source = '{{toInt value}}';
|
97 | template = Handlebars.compile(source);
|
98 | context = {
|
99 | value: '3cc'
|
100 | };
|
101 | return template(context).should.equal(3);
|
102 | });
|
103 | });
|
104 | });
|
105 |
|
106 | describe('toFloat', function() {
|
107 | return describe('{{toFloat value}}', function() {
|
108 | return it('should return a floating point number.', function() {
|
109 | var context, source, template;
|
110 |
|
111 | source = '{{toFloat value}}';
|
112 | template = Handlebars.compile(source);
|
113 | context = {
|
114 | value: '3.1cc'
|
115 | };
|
116 | return template(context).should.equal(3.1);
|
117 | });
|
118 | });
|
119 | });
|
120 |
|
121 | describe('addCommas', function() {
|
122 | return describe('{{addCommas value}}', function() {
|
123 | return it('should add commas to a number.', function() {
|
124 | var context, source, template;
|
125 |
|
126 | source = '{{addCommas value}}';
|
127 | template = Handlebars.compile(source);
|
128 | context = {
|
129 | value: 2222222
|
130 | };
|
131 | return template(context).should.equal('2,222,222');
|
132 | });
|
133 | });
|
134 | });
|
135 |
|
136 | }).call(this);
|