@@ -54,6 +54,79 @@ describe('parsers', function () {
5454 bla : 6
5555 } )
5656 } )
57+
58+ it ( 'reset returnBuffers option' , function ( ) {
59+ var res = 'test'
60+ var replyCount = 0
61+ function checkReply ( reply ) {
62+ if ( replyCount === 0 ) {
63+ assert . strictEqual ( reply , res )
64+ } else {
65+ assert . strictEqual ( reply . inspect ( ) , Buffer ( res ) . inspect ( ) )
66+ }
67+ replyCount ++
68+ }
69+ var parser = JavascriptParser ( {
70+ returnReply : checkReply ,
71+ returnError : returnError
72+ } )
73+ parser . execute ( new Buffer ( '+test\r\n' ) )
74+ parser . execute ( new Buffer ( '+test' ) )
75+ parser . setReturnBuffers ( true )
76+ assert . strictEqual ( replyCount , 1 )
77+ parser . execute ( new Buffer ( '\r\n' ) )
78+ assert . strictEqual ( replyCount , 2 )
79+ } )
80+
81+ it ( 'reset returnBuffers option with wrong input' , function ( ) {
82+ var parser = JavascriptParser ( {
83+ returnReply : returnReply ,
84+ returnError : returnError
85+ } )
86+ assert . throws ( function ( ) {
87+ parser . setReturnBuffers ( null )
88+ } , function ( err ) {
89+ assert . strictEqual ( err . message , 'The returnBuffers argument has to be a boolean' )
90+ assert ( err instanceof TypeError )
91+ return true
92+ } )
93+ } )
94+
95+ it ( 'reset stringNumbers option' , function ( ) {
96+ var res = 123
97+ var replyCount = 0
98+ function checkReply ( reply ) {
99+ if ( replyCount === 0 ) {
100+ assert . strictEqual ( reply , res )
101+ } else {
102+ assert . strictEqual ( reply , String ( res ) )
103+ }
104+ replyCount ++
105+ }
106+ var parser = JavascriptParser ( {
107+ returnReply : checkReply ,
108+ returnError : returnError
109+ } )
110+ parser . execute ( new Buffer ( ':123\r\n' ) )
111+ assert . strictEqual ( replyCount , 1 )
112+ parser . setStringNumbers ( true )
113+ parser . execute ( new Buffer ( ':123\r\n' ) )
114+ assert . strictEqual ( replyCount , 2 )
115+ } )
116+
117+ it ( 'reset stringNumbers option with wrong input' , function ( ) {
118+ var parser = JavascriptParser ( {
119+ returnReply : returnReply ,
120+ returnError : returnError
121+ } )
122+ assert . throws ( function ( ) {
123+ parser . setStringNumbers ( null )
124+ } , function ( err ) {
125+ assert . strictEqual ( err . message , 'The stringNumbers argument has to be a boolean' )
126+ assert ( err instanceof TypeError )
127+ return true
128+ } )
129+ } )
57130 } )
58131
59132 parsers . forEach ( function ( Parser ) {
@@ -100,6 +173,18 @@ describe('parsers', function () {
100173 replyCount = 0
101174 } )
102175
176+ it ( 'reset parser' , function ( ) {
177+ function checkReply ( reply ) {
178+ assert . strictEqual ( reply , 'test' )
179+ replyCount ++
180+ }
181+ var parser = newParser ( checkReply )
182+ parser . execute ( new Buffer ( '$123\r\naaa' ) )
183+ parser . reset ( )
184+ parser . execute ( new Buffer ( '+test\r\n' ) )
185+ assert . strictEqual ( replyCount , 1 )
186+ } )
187+
103188 it ( 'should not set the bufferOffset to a negative value' , function ( done ) {
104189 if ( Parser . name === 'HiredisReplyParser' ) {
105190 return this . skip ( )
0 commit comments