@@ -14,14 +14,67 @@ before(function (done) {
1414} ) ;
1515
1616describe ( 'Int64' , function ( ) {
17- it ( 'should throw if the low and high components are not numbers' ) ;
18- it ( 'should throw if the low and high components are not 32-bit integers' ) ;
19- it ( 'should default the high component to zero, if not provided' ) ;
20- it ( 'should expose the low and high components via getters' ) ;
21- it ( 'should reveal the full value via .toString()' ) ;
22- it ( 'should cast to its full value when the number is a safe number' ) ;
23- it ( 'should cast to a NaN when the number is not a safe number' ) ;
24- it ( 'should compare to other Int64s or other values via .equals()' ) ;
17+ it ( 'should throw if the low and high components are not numbers' , function ( ) {
18+ expect ( function ( ) { new Int64 ( ) } ) . to . throw ( TypeError ) ;
19+ expect ( function ( ) { new Int64 ( '123' , '123' ) } ) . to . throw ( TypeError ) ;
20+ expect ( function ( ) { new Int64 ( '123' ) } ) . to . throw ( TypeError ) ;
21+ expect ( function ( ) { new Int64 ( null , null ) } ) . to . throw ( TypeError ) ;
22+ expect ( function ( ) { new Int64 ( new Number ( 123 ) , new Number ( 123 ) ) } ) . to . throw ( TypeError ) ;
23+ expect ( function ( ) { new Int64 ( 123 , undefined ) } ) . to . throw ( TypeError ) ;
24+ new Int64 ( 123 , 123 ) ;
25+ } ) ;
26+ it ( 'should throw if the low and high components are not 32-bit integers' , function ( ) {
27+ expect ( function ( ) { new Int64 ( 123 , 12.2 ) } ) . to . throw ( TypeError ) ;
28+ expect ( function ( ) { new Int64 ( 123 , 2147483648 ) } ) . to . throw ( TypeError ) ;
29+ expect ( function ( ) { new Int64 ( 123 , - 2147483649 ) } ) . to . throw ( TypeError ) ;
30+ expect ( function ( ) { new Int64 ( 12.2 , 123 ) } ) . to . throw ( TypeError ) ;
31+ expect ( function ( ) { new Int64 ( 2147483648 , 123 ) } ) . to . throw ( TypeError ) ;
32+ expect ( function ( ) { new Int64 ( - 2147483649 , 123 ) } ) . to . throw ( TypeError ) ;
33+ expect ( function ( ) { new Int64 ( NaN , 123 ) } ) . to . throw ( TypeError ) ;
34+ expect ( function ( ) { new Int64 ( Infinity , 123 ) } ) . to . throw ( TypeError ) ;
35+ expect ( function ( ) { new Int64 ( - Infinity , 123 ) } ) . to . throw ( TypeError ) ;
36+ } ) ;
37+ it ( 'should expose the low and high components via getters' , function ( ) {
38+ var int = new Int64 ( 123 , 123 ) ;
39+ expect ( int . low ) . to . equal ( 123 ) ;
40+ expect ( int . high ) . to . equal ( 123 ) ;
41+ int . low = 22 ;
42+ int . high = 22 ;
43+ expect ( int . low ) . to . equal ( 123 ) ;
44+ expect ( int . high ) . to . equal ( 123 ) ;
45+ } ) ;
46+ it ( 'should default the high component to zero, if not provided' , function ( ) {
47+ var int = new Int64 ( 123 ) ;
48+ expect ( int . low ) . to . equal ( 123 ) ;
49+ expect ( int . high ) . to . equal ( 0 ) ;
50+ } ) ;
51+ it ( 'should reveal the full value when cast to a string' , function ( ) {
52+ expect ( String ( new Int64 ( 123 ) ) ) . to . equal ( '123' ) ;
53+ expect ( String ( new Int64 ( 123 , 123 ) ) ) . to . equal ( '528280977531' ) ;
54+ expect ( String ( new Int64 ( 123 , - 123 ) ) ) . to . equal ( '-528280977285' ) ;
55+ expect ( String ( new Int64 ( 4243423 , 234234234 ) ) ) . to . equal ( '1006028374637854687' ) ;
56+ } ) ;
57+ it ( 'should cast to its full value when the number is a safe number' , function ( ) {
58+ expect ( + ( new Int64 ( 123 ) ) ) . to . equal ( 123 ) ;
59+ expect ( + ( new Int64 ( 123 , 123 ) ) ) . to . equal ( 528280977531 ) ;
60+ expect ( + ( new Int64 ( 123 , - 123 ) ) ) . to . equal ( - 528280977285 ) ;
61+ } ) ;
62+ it ( 'should cast to a NaN when the number is not a safe number' , function ( ) {
63+ expect ( + ( new Int64 ( 4243423 , 234234234 ) ) ) . to . be . NaN ;
64+ } ) ;
65+ it ( 'should compare to other Int64s and other values via .equals()' , function ( ) {
66+ var int = new Int64 ( 123 , 123 ) ;
67+ expect ( int . equals ( int ) ) . to . be . true ;
68+ expect ( int . equals ( new Int64 ( 123 , 123 ) ) ) . to . be . true ;
69+ expect ( int . equals ( { low : 123 , high : 123 } ) ) . to . be . false ;
70+ expect ( int . equals ( 528280977531 ) ) . to . be . true ;
71+ expect ( int . equals ( '528280977531' ) ) . to . be . true ;
72+ int = new Int64 ( 4243423 , 234234234 ) ;
73+ expect ( int . equals ( new Int64 ( 4243423 , 234234234 ) ) ) . to . be . true ;
74+ expect ( int . equals ( String ( int ) ) ) . to . be . true ;
75+ expect ( int . equals ( + String ( int ) ) ) . to . be . false ;
76+ expect ( int . equals ( + int ) ) . to . be . false ;
77+ } ) ;
2578 it ( 'should bind to statements and transactions' ) ;
2679 it ( 'should get returned by operations after setting .safeIntegers()' ) ;
2780 it ( 'should react to changing settings inside an .each() callback' ) ;
0 commit comments