import { spawnSync } from 'child_process' ; import { Variables } from '../src/variables' ; const substitutions = [ [ 'uva-prd' , '${var%%-*}' ] , [ 'uva-prd' , '${var##*-}' ] , [ 'app-uva-hva-prd' , '${var%%-*}' ] , [ 'app-uva-hva-prd' , '${var##*-}' ] ] ; let errors = 0 ; console . log ( 'substitution    input                          ouput   expected             result' ) ; console . log ( '----------------------------------------------------------------------------------' ) ; for ( const [ input , substitution ] of substitutions ) { const ouput = Variables . expand ( substitution , [ [ 'var' , input ] ] ) ; const result = spawnSync ( 'bash' , [ '-c' , 'var=' + input + ' ; echo ' + substitution ] ) ; const expected = result . stdout . toString ( ) . trim ( ) ; const success = expected === ouput ; console . log ( substitution . padEnd ( 16 ) + input . padEnd ( 15 ) + '    ( ' + ouput . padStart ( 15 ) + ' = ' + expected . padEnd ( 15 ) + ' )    ' + ( success ? 'oke' : 'error' ) ) ; if ( ! success ) errors ++ ; } console . log ( ) ; console . log ( 'Errors:' , errors ) ;