@@ -114,6 +114,51 @@ describe('G-code Interpreter', () => {
114114 } ) ;
115115 } ) ;
116116
117+ describe ( 'Default handler' , ( ) => {
118+ it ( 'should call default handler if no matching handler found.' , ( done ) => {
119+ let i = 0 ;
120+ let defaultHandlerCalled = 0 ;
121+ const file = 'test/fixtures/default-handler.nc' ;
122+ const string = fs . readFileSync ( file , 'utf8' ) ;
123+ const runner = new Interpreter ( {
124+ handlers : {
125+ 'G0' : ( params ) => {
126+ } ,
127+ 'G1' : ( params ) => {
128+ }
129+ } ,
130+ defaultHandler : ( cmd , params ) => {
131+ // G9999 P1
132+
133+ defaultHandlerCalled ++ ;
134+ }
135+ } ) ;
136+ const results = runner . loadFromStringSync ( string , ( data , index ) => {
137+ expect ( i ) . to . be . equal ( index ) ;
138+ ++ i ;
139+ } ) ;
140+ expect ( defaultHandlerCalled ) . to . be . equal ( 1 ) ;
141+ expect ( results ) . to . be . an ( 'array' ) ;
142+ expect ( results . length ) . to . be . equal ( 3 ) ;
143+ expect ( results ) . to . deep . equal ( [
144+ {
145+ line : 'G0 X0 Y0 Z0' ,
146+ words : [ [ 'G' , 0 ] , [ 'X' , 0 ] , [ 'Y' , 0 ] , [ 'Z' , 0 ] ]
147+ } ,
148+ {
149+ line : 'G1 X10 Y10' ,
150+ words : [ [ 'G' , 1 ] , [ 'X' , 10 ] , [ 'Y' , 10 ] ]
151+ } ,
152+ {
153+ line : 'G9999 P1' ,
154+ words : [ [ 'G' , 9999 ] , [ 'P' , 1 ] ]
155+ }
156+ ] ) ;
157+
158+ done ( ) ;
159+ } ) ;
160+ } ) ;
161+
117162 describe ( 'G-code: circle' , ( ) => {
118163 it ( 'should call each function with the expected number of times.' , ( done ) => {
119164 const calls = { } ;
0 commit comments