1- var common = require ( " ../common" ) ;
1+ var common = require ( ' ../common' ) ;
22var assert = require ( 'assert' ) ;
33var a = require ( 'assert' ) ;
44
5- function makeBlock ( f ) {
6- var args = Array . prototype . slice . call ( arguments , 1 ) ;
7- return function ( ) {
8- return f . apply ( this , args ) ;
5+ function makeBlock ( f ) {
6+ var args = Array . prototype . slice . call ( arguments , 1 ) ;
7+ return function ( ) {
8+ return f . apply ( this , args ) ;
99 } ;
1010}
1111
1212assert . ok ( common . indirectInstanceOf ( a . AssertionError . prototype , Error ) ,
13- " a.AssertionError instanceof Error" ) ;
13+ ' a.AssertionError instanceof Error' ) ;
1414
1515assert . throws ( makeBlock ( a . ok , false ) ,
16- a . AssertionError , " ok(false)" ) ;
16+ a . AssertionError , ' ok(false)' ) ;
1717
1818assert . doesNotThrow ( makeBlock ( a . ok , true ) ,
19- a . AssertionError , " ok(true)" ) ;
19+ a . AssertionError , ' ok(true)' ) ;
2020
21- assert . doesNotThrow ( makeBlock ( a . ok , " test" ) , " ok('test')" ) ;
21+ assert . doesNotThrow ( makeBlock ( a . ok , ' test' ) , ' ok(\ 'test\')' ) ;
2222
2323assert . throws ( makeBlock ( a . equal , true , false ) , a . AssertionError , 'equal' ) ;
2424
@@ -30,95 +30,98 @@ assert.doesNotThrow(makeBlock(a.equal, null, undefined), 'equal');
3030
3131assert . doesNotThrow ( makeBlock ( a . equal , true , true ) , 'equal' ) ;
3232
33- assert . doesNotThrow ( makeBlock ( a . equal , 2 , "2" ) , 'equal' ) ;
33+ assert . doesNotThrow ( makeBlock ( a . equal , 2 , '2' ) , 'equal' ) ;
3434
3535assert . doesNotThrow ( makeBlock ( a . notEqual , true , false ) , 'notEqual' ) ;
3636
37- assert . throws ( makeBlock ( a . notEqual , true , true ) , a . AssertionError , 'notEqual' ) ;
37+ assert . throws ( makeBlock ( a . notEqual , true , true ) ,
38+ a . AssertionError , 'notEqual' ) ;
3839
39- assert . throws ( makeBlock ( a . strictEqual , 2 , "2" ) , a . AssertionError , 'strictEqual' ) ;
40+ assert . throws ( makeBlock ( a . strictEqual , 2 , '2' ) ,
41+ a . AssertionError , 'strictEqual' ) ;
4042
41- assert . throws ( makeBlock ( a . strictEqual , null , undefined ) , a . AssertionError , 'strictEqual' ) ;
43+ assert . throws ( makeBlock ( a . strictEqual , null , undefined ) ,
44+ a . AssertionError , 'strictEqual' ) ;
4245
43- assert . doesNotThrow ( makeBlock ( a . notStrictEqual , 2 , "2" ) , 'notStrictEqual' ) ;
46+ assert . doesNotThrow ( makeBlock ( a . notStrictEqual , 2 , '2' ) , 'notStrictEqual' ) ;
4447
4548// deepEquals joy!
4649// 7.2
47- assert . doesNotThrow ( makeBlock ( a . deepEqual , new Date ( 2000 , 3 , 14 ) , new Date ( 2000 , 3 , 14 ) ) ,
48- 'deepEqual date' ) ;
50+ assert . doesNotThrow ( makeBlock ( a . deepEqual , new Date ( 2000 , 3 , 14 ) ,
51+ new Date ( 2000 , 3 , 14 ) ) , 'deepEqual date' ) ;
4952
50- assert . throws ( makeBlock ( a . deepEqual , new Date ( ) , new Date ( 2000 , 3 , 14 ) ) ,
53+ assert . throws ( makeBlock ( a . deepEqual , new Date ( ) , new Date ( 2000 , 3 , 14 ) ) ,
5154 a . AssertionError ,
5255 'deepEqual date' ) ;
5356
5457// 7.3
55- assert . doesNotThrow ( makeBlock ( a . deepEqual , 4 , "4" ) , 'deepEqual == check' ) ;
58+ assert . doesNotThrow ( makeBlock ( a . deepEqual , 4 , '4' ) , 'deepEqual == check' ) ;
5659assert . doesNotThrow ( makeBlock ( a . deepEqual , true , 1 ) , 'deepEqual == check' ) ;
57- assert . throws ( makeBlock ( a . deepEqual , 4 , "5" ) ,
60+ assert . throws ( makeBlock ( a . deepEqual , 4 , '5' ) ,
5861 a . AssertionError ,
5962 'deepEqual == check' ) ;
6063
6164// 7.4
6265// having the same number of owned properties && the same set of keys
63- assert . doesNotThrow ( makeBlock ( a . deepEqual , { a :4 } , { a :4 } ) ) ;
64- assert . doesNotThrow ( makeBlock ( a . deepEqual , { a :4 , b :"2" } , { a :4 , b :"2" } ) ) ;
65- assert . doesNotThrow ( makeBlock ( a . deepEqual , [ 4 ] , [ "4" ] ) ) ;
66- assert . throws ( makeBlock ( a . deepEqual , { a :4 } , { a :4 , b :true } ) , a . AssertionError ) ;
67- assert . doesNotThrow ( makeBlock ( a . deepEqual , [ "a" ] , { 0 :"a" } ) ) ;
66+ assert . doesNotThrow ( makeBlock ( a . deepEqual , { a : 4 } , { a : 4 } ) ) ;
67+ assert . doesNotThrow ( makeBlock ( a . deepEqual , { a : 4 , b : '2' } , { a : 4 , b : '2' } ) ) ;
68+ assert . doesNotThrow ( makeBlock ( a . deepEqual , [ 4 ] , [ '4' ] ) ) ;
69+ assert . throws ( makeBlock ( a . deepEqual , { a : 4 } , { a : 4 , b : true } ) ,
70+ a . AssertionError ) ;
71+ assert . doesNotThrow ( makeBlock ( a . deepEqual , [ 'a' ] , { 0 : 'a' } ) ) ;
6872//(although not necessarily the same order),
69- assert . doesNotThrow ( makeBlock ( a . deepEqual , { a :4 , b : "1" } , { b :"1" , a : 4 } ) ) ;
70- var a1 = [ 1 , 2 , 3 ] ;
71- var a2 = [ 1 , 2 , 3 ] ;
72- a1 . a = " test" ;
73+ assert . doesNotThrow ( makeBlock ( a . deepEqual , { a : 4 , b : '1' } , { b : '1' , a : 4 } ) ) ;
74+ var a1 = [ 1 , 2 , 3 ] ;
75+ var a2 = [ 1 , 2 , 3 ] ;
76+ a1 . a = ' test' ;
7377a1 . b = true ;
7478a2 . b = true ;
75- a2 . a = "test" ;
76- assert . throws ( makeBlock ( a . deepEqual ,
77- Object . keys ( a1 ) ,
78- Object . keys ( a2 ) ) ,
79+ a2 . a = 'test' ;
80+ assert . throws ( makeBlock ( a . deepEqual , Object . keys ( a1 ) , Object . keys ( a2 ) ) ,
7981 a . AssertionError ) ;
8082assert . doesNotThrow ( makeBlock ( a . deepEqual , a1 , a2 ) ) ;
8183
8284// having an identical prototype property
8385var nbRoot = {
84- toString : function ( ) { return this . first + ' ' + this . last ; }
86+ toString : function ( ) { return this . first + ' ' + this . last ; }
8587} ;
8688
87- function nameBuilder ( first , last ) {
89+ function nameBuilder ( first , last ) {
8890 this . first = first ;
8991 this . last = last ;
9092 return this ;
9193}
9294nameBuilder . prototype = nbRoot ;
9395
94- function nameBuilder2 ( first , last ) {
96+ function nameBuilder2 ( first , last ) {
9597 this . first = first ;
9698 this . last = last ;
9799 return this ;
98100}
99101nameBuilder2 . prototype = nbRoot ;
100102
101103var nb1 = new nameBuilder ( 'Ryan' , 'Dahl' ) ;
102- var nb2 = new nameBuilder2 ( 'Ryan' , 'Dahl' ) ;
104+ var nb2 = new nameBuilder2 ( 'Ryan' , 'Dahl' ) ;
103105
104106assert . doesNotThrow ( makeBlock ( a . deepEqual , nb1 , nb2 ) ) ;
105107
106108nameBuilder2 . prototype = Object ;
107- nb2 = new nameBuilder2 ( 'Ryan' , 'Dahl' ) ;
109+ nb2 = new nameBuilder2 ( 'Ryan' , 'Dahl' ) ;
108110assert . throws ( makeBlock ( a . deepEqual , nb1 , nb2 ) , a . AssertionError ) ;
109111
110112// String literal + object blew up my implementation...
111113assert . throws ( makeBlock ( a . deepEqual , 'a' , { } ) , a . AssertionError ) ;
112114
113115// Testing the throwing
114- function thrower ( errorConstructor ) {
116+ function thrower ( errorConstructor ) {
115117 throw new errorConstructor ( 'test' ) ;
116118}
117119var aethrow = makeBlock ( thrower , a . AssertionError ) ;
118120aethrow = makeBlock ( thrower , a . AssertionError ) ;
119121
120122// the basic calls work
121- assert . throws ( makeBlock ( thrower , a . AssertionError ) , a . AssertionError , 'message' ) ;
123+ assert . throws ( makeBlock ( thrower , a . AssertionError ) ,
124+ a . AssertionError , 'message' ) ;
122125assert . throws ( makeBlock ( thrower , a . AssertionError ) , a . AssertionError ) ;
123126assert . throws ( makeBlock ( thrower , a . AssertionError ) ) ;
124127
@@ -133,37 +136,41 @@ try {
133136 threw = true ;
134137 assert . ok ( e instanceof TypeError , 'type' ) ;
135138}
136- assert . equal ( true , threw , 'a.throws with an explicit error is eating extra errors' , a . AssertionError ) ;
139+ assert . equal ( true , threw ,
140+ 'a.throws with an explicit error is eating extra errors' ,
141+ a . AssertionError ) ;
137142threw = false ;
138143
139144// doesNotThrow should pass through all errors
140145try {
141146 a . doesNotThrow ( makeBlock ( thrower , TypeError ) , a . AssertionError ) ;
142- } catch ( e ) {
143- threw = true
147+ } catch ( e ) {
148+ threw = true ;
144149 assert . ok ( e instanceof TypeError ) ;
145150}
146- assert . equal ( true , threw , 'a.doesNotThrow with an explicit error is eating extra errors' ) ;
151+ assert . equal ( true , threw ,
152+ 'a.doesNotThrow with an explicit error is eating extra errors' ) ;
147153
148154// key difference is that throwing our correct error makes an assertion error
149155try {
150156 a . doesNotThrow ( makeBlock ( thrower , TypeError ) , TypeError ) ;
151- } catch ( e ) {
152- threw = true
157+ } catch ( e ) {
158+ threw = true ;
153159 assert . ok ( e instanceof a . AssertionError ) ;
154160}
155- assert . equal ( true , threw , 'a.doesNotThrow is not catching type matching errors' ) ;
161+ assert . equal ( true , threw ,
162+ 'a.doesNotThrow is not catching type matching errors' ) ;
156163
157- assert . throws ( function ( ) { assert . ifError ( new Error ( 'test error' ) ) } ) ;
158- assert . doesNotThrow ( function ( ) { assert . ifError ( null ) } ) ;
159- assert . doesNotThrow ( function ( ) { assert . ifError ( ) } ) ;
164+ assert . throws ( function ( ) { assert . ifError ( new Error ( 'test error' ) ) } ) ;
165+ assert . doesNotThrow ( function ( ) { assert . ifError ( null ) } ) ;
166+ assert . doesNotThrow ( function ( ) { assert . ifError ( ) } ) ;
160167
161168// use a RegExp to validate error message
162- a . throws ( makeBlock ( thrower , TypeError ) , / t e s t / ) ;
169+ a . throws ( makeBlock ( thrower , TypeError ) , / t e s t / ) ;
163170
164171// use a fn to validate error object
165172a . throws ( makeBlock ( thrower , TypeError ) , function ( err ) {
166- if ( ! ( err instanceof TypeError ) || ! / t e s t / . test ( err ) ) {
167- return false ;
168- }
173+ if ( ! ( err instanceof TypeError ) || ! / t e s t / . test ( err ) ) {
174+ return false ;
175+ }
169176} ) ;
0 commit comments