File size: 817 Bytes
5fae594
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
 * Write anything out as a string. For error messages when tests fail. 
 */
function anyToString(thing){
   
   if( thing === null ) {
      return 'null';
   }
   
   if( thing === undefined ) {
      return 'undefined';
   }

   if( typeof thing == 'string' ) {
      return '(string)' + thing;
   }
   
   if( thing.constructor == Array ) {
      return '[' + thing.map(anyToString).join(', ') + ']';
   }      

   if( typeof thing == 'function' ) {
      return thing.name? 'function ' + thing.name : 'anon function'; 
   }
   
   if( typeof thing == 'object' ) {
         
      return (
               thing.constructor == Object? 
                  '' 
               :  '(' + (thing.constructor.name) + ')'
             ) 
             + JSON.stringify(thing);
   }
   
   return JSON.stringify(thing);
}