| 
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 |  |  | /* vim: set ts=2: */ | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  | /*jshint loopfunc:true, mocha:true, node:true */ | 
					
						
							| 
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 |  |  | var SSF = require('../'); | 
					
						
							|  |  |  | var fs = require('fs'), assert = require('assert'); | 
					
						
							|  |  |  | var data = JSON.parse(fs.readFileSync('./test/oddities.json','utf8')); | 
					
						
							|  |  |  | describe('oddities', function() { | 
					
						
							|  |  |  |   data.forEach(function(d) { | 
					
						
							| 
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 |  |  |     it(String(d[0]), function(){ | 
					
						
							| 
									
										
										
										
											2014-06-13 15:02:06 +00:00
										 |  |  |       for(var j=1;j<d.length;++j) { | 
					
						
							| 
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 |  |  |         if(d[j].length == 2) { | 
					
						
							|  |  |  |           var expected = d[j][1], actual = SSF.format(d[0], d[j][0], {}); | 
					
						
							|  |  |  |           assert.equal(actual, expected); | 
					
						
							| 
									
										
										
										
											2014-03-28 21:28:39 +00:00
										 |  |  |         } else if(d[j][2] !== "#") assert.throws(function() { SSF.format(d[0], d[j][0]); }); | 
					
						
							| 
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2014-02-11 19:20:34 +00:00
										 |  |  |   it('should fail for bad formats', function() { | 
					
						
							|  |  |  |     var bad = ['##,##']; | 
					
						
							|  |  |  |     var chk = function(fmt){ return function(){ SSF.format(fmt,0); }; }; | 
					
						
							|  |  |  |     bad.forEach(function(fmt){assert.throws(chk(fmt));}); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2024-04-27 23:49:12 +00:00
										 |  |  |   it('should handle NaN values and infinities', function() { | 
					
						
							|  |  |  |     assert.equal(SSF.format('#,##0.0; (#,##0.0); "-"', NaN), " -"); | 
					
						
							|  |  |  |     assert.equal(SSF.format('#,##0.0; (#,##0.0); "-"', Infinity), " -"); | 
					
						
							|  |  |  |     assert.equal(SSF.format('#,##0.0; (#,##0.0); "-"', -Infinity), " -"); | 
					
						
							| 
									
										
										
										
											2024-07-04 19:54:34 +00:00
										 |  |  |     ["0.00", "General"].forEach(function(fmt) { | 
					
						
							| 
									
										
										
										
											2024-05-31 07:16:53 +00:00
										 |  |  |       assert.equal(SSF.format(fmt, NaN), "#VALUE!"); | 
					
						
							|  |  |  |       assert.equal(SSF.format(fmt, Infinity), "#DIV/0!"); | 
					
						
							|  |  |  |       assert.equal(SSF.format(fmt, -Infinity), "#DIV/0!"); | 
					
						
							| 
									
										
										
										
											2024-07-04 19:54:34 +00:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2024-04-27 23:49:12 +00:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 |  |  | }); |