Adding Delete() func to properties
Change-Id: Ifea9d67b6467f0373736d291a41d7d4685e697d7
diff --git a/properties.go b/properties.go
index 6201f8b..e7cac17 100644
--- a/properties.go
+++ b/properties.go
@@ -596,6 +596,15 @@
// ----------------------------------------------------------------------------
+// deletes the key from the map and its comments
+// abides by the rules of the builtin delete()
+func (p *Properties) Delete(key string) () {
+ delete(p.m, key)
+ delete(p.c, key)
+}
+
+// ----------------------------------------------------------------------------
+
// check expands all values and returns an error if a circular reference or
// a malformed expression was found.
func (p *Properties) check() error {
diff --git a/properties_test.go b/properties_test.go
index 6ae0b42..2615f32 100644
--- a/properties_test.go
+++ b/properties_test.go
@@ -797,6 +797,28 @@
c.Assert(func() { p.MustGetUint("max") }, PanicMatches, ".* out of range")
}
+func (s *TestSuite) TestDeleteKey(c *C) {
+ input := "#comments should also be gone\nkey=to-be-deleted"
+ p, err := parse(input)
+ c.Assert(err, IsNil)
+ c.Check(len(p.m), Equals, 1)
+ c.Check(len(p.c), Equals, 1)
+ p.Delete("key")
+ c.Check(len(p.m), Equals, 0)
+ c.Check(len(p.c), Equals, 0)
+}
+
+func (s *TestSuite) TestDeleteUnknownKey(c *C) {
+ input := "#comments should also be gone\nkey=to-be-deleted"
+ p, err := parse(input)
+ c.Assert(err, IsNil)
+ c.Check(len(p.m), Equals, 1)
+ c.Check(len(p.c), Equals, 1)
+ p.Delete("wrong-key")
+ c.Check(len(p.m), Equals, 1)
+ c.Check(len(p.c), Equals, 1)
+}
+
// ----------------------------------------------------------------------------
// tests all combinations of delimiters, leading and/or trailing whitespace and newlines.