MCPcopy Create free account
hub / github.com/buger/jsonparser / TestArrayEachWithWhiteSpace

Function TestArrayEachWithWhiteSpace

parser_test.go:1665–1713  ·  view source on GitHub ↗

Verifies: SYS-REQ-029 [boundary] MCDC SYS-REQ-029: addressed_array_is_well_formed=F, malformed_array_input_returns_error=T => TRUE

(t *testing.T)

Source from the content-addressed store, hash-verified

1663// Verifies: SYS-REQ-029 [boundary]
1664// MCDC SYS-REQ-029: addressed_array_is_well_formed=F, malformed_array_input_returns_error=T => TRUE
1665func TestArrayEachWithWhiteSpace(t *testing.T) {
1666 // Issue #159
1667 count := 0
1668 funcError := func([]byte, ValueType, int, error) { t.Errorf("Run func not allow") }
1669 funcSuccess := func(value []byte, dataType ValueType, index int, err error) {
1670 count++
1671
1672 switch count {
1673 case 1:
1674 if string(value) != `AAA` {
1675 t.Errorf("Wrong first item: %s", string(value))
1676 }
1677 case 2:
1678 if string(value) != `BBB` {
1679 t.Errorf("Wrong second item: %s", string(value))
1680 }
1681 case 3:
1682 if string(value) != `CCC` {
1683 t.Errorf("Wrong third item: %s", string(value))
1684 }
1685 default:
1686 t.Errorf("Should process only 3 items")
1687 }
1688 }
1689
1690 type args struct {
1691 data []byte
1692 cb func(value []byte, dataType ValueType, offset int, err error)
1693 keys []string
1694 }
1695 tests := []struct {
1696 name string
1697 args args
1698 wantErr bool
1699 }{
1700 {"Array with white space", args{[]byte(` ["AAA", "BBB", "CCC"]`), funcSuccess, []string{}}, false},
1701 {"Array with only one character after white space", args{[]byte(` 1`), funcError, []string{}}, true},
1702 {"Only white space", args{[]byte(` `), funcError, []string{}}, true},
1703 }
1704 for _, tt := range tests {
1705 t.Run(tt.name, func(t *testing.T) {
1706 _, err := ArrayEach(tt.args.data, tt.args.cb, tt.args.keys...)
1707 if (err != nil) != tt.wantErr {
1708 t.Errorf("ArrayEach() error = %v, wantErr %v", err, tt.wantErr)
1709 return
1710 }
1711 })
1712 }
1713}
1714
1715// Verifies: SYS-REQ-028 [boundary]
1716// MCDC SYS-REQ-028: addressed_array_is_empty=T, addressed_array_is_well_formed=T, empty_array_produces_no_callbacks=T => TRUE

Callers

nothing calls this directly

Calls 1

ArrayEachFunction · 0.85

Tested by

no test coverage detected