Commit abdf4853 authored by David Symonds's avatar David Symonds

Define Len() for JSON Map.

R=rsc
APPROVED=rsc
DELTA=6  (5 added, 0 deleted, 1 changed)
OCL=28398
CL=28430
parent 9ab8129e
......@@ -33,7 +33,7 @@ type Json interface {
Bool() bool; // boolean (BoolKind)
Get(s string) Json; // field lookup (MapKind)
Elem(i int) Json; // element lookup (ArrayKind)
Len() int; // length (ArrayKind)
Len() int; // length (ArrayKind, MapKind)
}
// JsonToString returns the textual JSON syntax representation
......@@ -112,6 +112,7 @@ func (j *_Bool) String() string {
type _Map struct { m map[string]Json; _Null }
func (j *_Map) Kind() int { return MapKind }
func (j *_Map) Len() int { return len(j.m) }
func (j *_Map) Get(s string) Json {
if j.m == nil {
return Null
......
......@@ -64,6 +64,10 @@ func TestJsonMap(t *testing.T) {
if mapv == nil {
t.Fatalf("StringToJson(%#q) => nil, %v, %v", mapstr, ok, errtok);
}
if cnt := mapv.Len(); cnt != len(jsontests) {
t.Errorf("StringToJson(%#q).Len() => %v, want %v", mapstr, cnt,
len(jsontests));
}
for k,v := range values {
if v1 := mapv.Get(k); !Equal(v1, v) {
t.Errorf("MapTest: Walk(%#q) => %v, want %v", k, v1, v);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment