From 4ecc4104dadf92d66de9c42496eb87e6c60c582f Mon Sep 17 00:00:00 2001 From: Kiith-Sa Date: Mon, 9 Sep 2013 22:39:46 +0200 Subject: [PATCH] Minor opBinaryRight style, doc & test changes. --- source/dyaml/node.d | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/source/dyaml/node.d b/source/dyaml/node.d index 11ccd28..47cd921 100644 --- a/source/dyaml/node.d +++ b/source/dyaml/node.d @@ -1226,43 +1226,46 @@ struct Node } /** - * Report whether the given key is found. + * Determine whether a key is in a mapping, and access its value. * * This method can only be called on mapping nodes. * - * Returns: - * A pointer to the value of the given key, or null if not found. + * Params: key = Key to search for. * - * Be careful! Modifying the mapping with any other function can - * invalidate the pointer. + * Returns: A pointer to the value (as a Node) corresponding to key, + * or null if not found. * - * Params: key = Key to search for. + * Note: Any modification to the node can invalidate the returned + * pointer. * + * See_Also: contains */ Node* opBinaryRight(string op, K)(K key) @trusted if (op == "in") { - enforce(isMapping(), - new Error("Trying to use 'in' on a " ~ - nodeTypeString ~ " node", - startMark_)); + enforce(isMapping, new Error("Trying to use 'in' on a " ~ + nodeTypeString ~ " node", startMark_)); auto idx = findPair(key); - if (idx < 0) { + if(idx < 0) + { return null; - } else { - return &get!(Node.Pair[])[idx].value; + } + else + { + return &(get!(Node.Pair[])[idx].value); } } unittest { writeln(`D:YAML Node opBinaryRight!"in" unittest`); - auto nd = Node(["foo", "baz"], ["bar", "qux"]); - assert("bad" !in nd && ("bad" in nd) is null); - Node* foo = "foo" in nd; + auto mapping = Node(["foo", "baz"], ["bar", "qux"]); + assert("bad" !in mapping && ("bad" in mapping) is null); + Node* foo = "foo" in mapping; assert(foo !is null); assert(*foo == Node("bar")); + assert(foo.get!string == "bar"); *foo = Node("newfoo"); - assert(nd["foo"] == Node("newfoo")); + assert(mapping["foo"] == Node("newfoo")); } /**