2014-01-20 08:37:48 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								/* vim: set ts=2: */
							 | 
						
					
						
							
								
									
										
										
										
											2014-06-13 15:02:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								/*jshint -W041 */
							 | 
						
					
						
							
								
									
										
										
										
											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 dates = fs.readFileSync('./test/dates.tsv','utf8').split("\n");
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-02 18:47:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								var date2 = fs.readFileSync('./test/cal.tsv',  'utf8').split("\n");
							 | 
						
					
						
							
								
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								var times = fs.readFileSync('./test/times.tsv','utf8').split("\n");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function doit(data) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  var step = Math.ceil(data.length/100), i = 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  var headers = data[0].split("\t");
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  for(var j = 0; j <= 100; ++j) it(String(j), function() {
							 | 
						
					
						
							
								
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for(var k = 0; k <= step; ++k,++i) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-06-13 15:02:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      if(data[i] == null || data[i].length < 3) return;
							 | 
						
					
						
							
								
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      var d = data[i].replace(/#{255}/g,"").split("\t");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      for(var w = 1; w < headers.length; ++w) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-06-13 15:02:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        var expected = d[w], actual = SSF.format(headers[w], parseFloat(d[0]), {});
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if(actual != expected) throw new Error([actual, expected, w, headers[w],d[0],d,i].join("|"));
							 | 
						
					
						
							
								
									
										
										
										
											2014-06-13 15:02:06 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        actual = SSF.format(headers[w].toUpperCase(), parseFloat(d[0]), {});
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if(actual != expected) throw new Error([actual, expected, w, headers[w].toUpperCase(),d[0],d,i].join("|"));
							 | 
						
					
						
							
								
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-02 18:47:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								describe('time formats', function() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  doit(process.env.MINTEST ? times.slice(0,4000) : times);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								describe('date formats', function() {
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-02 18:47:03 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  doit(process.env.MINTEST ? dates.slice(0,4000) : dates);
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-12 07:34:36 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  if(0) doit(process.env.MINTEST ? date2.slice(0,1000) : date2);
							 | 
						
					
						
							
								
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  it('should fail for bad formats', function() {
							 | 
						
					
						
							
								
									
										
										
										
											2014-02-11 19:20:34 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    var bad = [];
							 | 
						
					
						
							
								
									
										
										
										
											2014-01-20 08:37:48 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    var chk = function(fmt){ return function(){ SSF.format(fmt,0); }; };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bad.forEach(function(fmt){assert.throws(chk(fmt));});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 |