@@ -1383,6 +1383,56 @@ func TestArrayEach(t *testing.T) {
13831383 }, "a" , "b" )
13841384}
13851385
1386+ func TestArrayEachWithWhiteSpace (t * testing.T ) {
1387+ //Issue #159
1388+ count := 0
1389+ funcError := func ([]byte , ValueType , int , error ) { t .Errorf ("Run func not allow" ) }
1390+ funcSuccess := func (value []byte , dataType ValueType , index int , err error ) {
1391+ count ++
1392+
1393+ switch count {
1394+ case 1 :
1395+ if string (value ) != `AAA` {
1396+ t .Errorf ("Wrong first item: %s" , string (value ))
1397+ }
1398+ case 2 :
1399+ if string (value ) != `BBB` {
1400+ t .Errorf ("Wrong second item: %s" , string (value ))
1401+ }
1402+ case 3 :
1403+ if string (value ) != `CCC` {
1404+ t .Errorf ("Wrong third item: %s" , string (value ))
1405+ }
1406+ default :
1407+ t .Errorf ("Should process only 3 items" )
1408+ }
1409+ }
1410+
1411+ type args struct {
1412+ data []byte
1413+ cb func (value []byte , dataType ValueType , offset int , err error )
1414+ keys []string
1415+ }
1416+ tests := []struct {
1417+ name string
1418+ args args
1419+ wantErr bool
1420+ }{
1421+ {"Array with white space" , args {[]byte (` ["AAA", "BBB", "CCC"]` ), funcSuccess , []string {}}, false },
1422+ {"Array with only one character after white space" , args {[]byte (` 1` ), funcError , []string {}}, true },
1423+ {"Only white space" , args {[]byte (` ` ), funcError , []string {}}, true },
1424+ }
1425+ for _ , tt := range tests {
1426+ t .Run (tt .name , func (t * testing.T ) {
1427+ _ , err := ArrayEach (tt .args .data , tt .args .cb , tt .args .keys ... )
1428+ if (err != nil ) != tt .wantErr {
1429+ t .Errorf ("ArrayEach() error = %v, wantErr %v" , err , tt .wantErr )
1430+ return
1431+ }
1432+ })
1433+ }
1434+ }
1435+
13861436func TestArrayEachEmpty (t * testing.T ) {
13871437 funcError := func ([]byte , ValueType , int , error ) { t .Errorf ("Run func not allow" ) }
13881438
0 commit comments