Also removes the ordered keys Change-Id: Ie3dad6dfecbe7f07643fed1d4ef56dd840dc926a
diff --git a/properties.go b/properties.go index e7cac17..44f9c1f 100644 --- a/properties.go +++ b/properties.go
@@ -596,11 +596,18 @@ // ---------------------------------------------------------------------------- -// deletes the key from the map and its comments +// deletes the key from the map and comments // abides by the rules of the builtin delete() func (p *Properties) Delete(key string) () { delete(p.m, key) delete(p.c, key) + newKeys := []string{} + for _, k := range p.k { + if k != key { + newKeys = append(newKeys, key) + } + } + p.k = newKeys } // ----------------------------------------------------------------------------
diff --git a/properties_test.go b/properties_test.go index 2615f32..8d4c7c0 100644 --- a/properties_test.go +++ b/properties_test.go
@@ -798,14 +798,16 @@ } func (s *TestSuite) TestDeleteKey(c *C) { - input := "#comments should also be gone\nkey=to-be-deleted" + input := "#comments should also be gone\nkey=to-be-deleted\nsecond=key" p, err := parse(input) c.Assert(err, IsNil) - c.Check(len(p.m), Equals, 1) + c.Check(len(p.m), Equals, 2) c.Check(len(p.c), Equals, 1) + c.Check(len(p.k), Equals, 2) p.Delete("key") - c.Check(len(p.m), Equals, 0) + c.Check(len(p.m), Equals, 1) c.Check(len(p.c), Equals, 0) + c.Check(len(p.k), Equals, 1) } func (s *TestSuite) TestDeleteUnknownKey(c *C) { @@ -814,9 +816,11 @@ c.Assert(err, IsNil) c.Check(len(p.m), Equals, 1) c.Check(len(p.c), Equals, 1) + c.Check(len(p.k), Equals, 1) p.Delete("wrong-key") c.Check(len(p.m), Equals, 1) c.Check(len(p.c), Equals, 1) + c.Check(len(p.k), Equals, 1) } // ----------------------------------------------------------------------------