import { BitArray } from '@zxing/library' ; import { assertEquals } from '../../../util/AssertUtils' ; import BinaryUtil from './BinaryUtil' ; author Pablo Orduña, University of Deusto (pablo.orduna deusto it ( 'BinaryUtilTest' , ( ) => { it ( 'testBuildBitArrayFromString' , ( ) => { let data = ' ..X..X.. ..XXX... XXXXXXXX ........' ; check ( data ) ; data = ' XXX..X..' ; check ( data ) ; data = ' XX' ; check ( data ) ; data = ' ....XX.. ..XX' ; check ( data ) ; data = ' ....XX.. ..XX..XX ....X.X. ........' ; check ( data ) ; } ) ; it ( 'testBuildBitArrayFromStringWithoutSpaces' , ( ) => { let data = ' ..X..X.. ..XXX... XXXXXXXX ........' ; checkWithoutSpaces ( data ) ; data = ' XXX..X..' ; checkWithoutSpaces ( data ) ; data = ' XX' ; checkWithoutSpaces ( data ) ; data = ' ....XX.. ..XX' ; checkWithoutSpaces ( data ) ; data = ' ....XX.. ..XX..XX ....X.X. ........' ; checkWithoutSpaces ( data ) ; } ) ; } ) ; const SPACE = /\s/ ; function check ( data ) { const binary = BinaryUtil . buildBitArrayFromString ( data ) ; assertEquals ( data , binary . toString ( ) ) ; } function checkWithoutSpaces ( data ) { const dataWithoutSpaces = data . replace ( SPACE , '' ) ; const binary = BinaryUtil . buildBitArrayFromStringWithoutSpaces ( dataWithoutSpaces ) ; assertEquals ( data , binary . toString ( ) ) ; }