} else {
_, ok := d.parse_value_interface()
if !ok {
- panic(&SyntaxError{
- Offset: d.offset,
- What: errors.New("unexpected end of dict, no matching value for a given key"),
- })
+ return
}
continue
}
// now we need to actually parse it
if !d.parse_value(valuev) {
- panic(&SyntaxError{
- Offset: d.offset,
- What: errors.New("unexpected end of dict, no matching value for a given key"),
- })
+ return
}
if v.Kind() == reflect.Map {
return false
}
-// returns true if there was a value and it's now stored in 'v', otherwise there
-// was an end symbol ("e") and no value was stored
+// Returns true if there was a value and it's now stored in 'v', otherwise
+// there was an end symbol ("e") and no value was stored.
func (d *decoder) parse_value(v reflect.Value) bool {
// we support one level of indirection at the moment
if v.Kind() == reflect.Ptr {
valuei, ok := d.parse_value_interface()
if !ok {
- panic(&SyntaxError{
- Offset: d.offset,
- What: errors.New("unexpected end of dict, no matching value for a given key"),
- })
+ break
}
dict[key] = valuei
"reflect"
"testing"
+ "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
ret, _ := big.NewInt(-1).SetString("604919719469385652980544193299329427705624352086", 10)
return ret
}()},
+ {"d1:rd6:\xd4/\xe2F\x00\x01e1:t3:\x9a\x87\x011:v4:TR%=1:y1:re", map[string]interface{}{
+ "r": map[string]interface{}{},
+ "t": "\x9a\x87\x01",
+ "v": "TR%=",
+ "y": "r",
+ }},
}
func TestRandomDecode(t *testing.T) {
t.Error(err, test.data)
continue
}
- if !reflect.DeepEqual(test.expected, value) {
- t.Errorf("got: %v (%T), expected: %v (%T)\n",
- value, value, test.expected, test.expected)
- }
+ assert.EqualValues(t, test.expected, value)
}
}