power-assert-js / power-assert-formatter

Power Assert output formatter
MIT License
6 stars 3 forks source link

depth-limited custom stringify function #6

Closed twada closed 10 years ago

twada commented 10 years ago

Provide special purpose value stringify function for power-assert value formatting.

Depth-limitation

Trying to prune deep Object/Array elements (default depth = 1)

var foo = 'foo', bar = ['toto', 'tata'], baz = {name: 'hoge'};

assert.notDeepEqual([foo,bar,baz], new Array(foo, bar, baz))
                     |   |   |     |         |    |    |    
                     |   |   |     |         |    |    Object{name:"hoge"}
                     |   |   |     |         |    ["toto","tata"]
                     |   |   |     |         "foo"          
                     |   |   |     ["foo",#Array#,#Object#] 
                     |   |   Object{name:"hoge"}            
                     |   ["toto","tata"]                    
                     "foo"                                  

Value Rendering

function Person(name, age) {
    this.name = name;
    this.age = age;
}
var alice = new Person('alice', 3), bob = new Person('bob', 4);

assert(alice.age === bob.age)
       |     |   |   |   |   
       |     |   |   |   4   
       |     |   |   Person{name:"bob",age:4}
       |     3   false       
       Person{name:"alice",age:3}

$$$ [number] bob.age
### [number] alice.age
$=> 4
#=> 3

Other TODOs