1 |
commit: dc956e48bb51489eccf1be4793d556490aac2278 |
2 |
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Apr 4 05:29:06 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Apr 4 15:09:07 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=dc956e48 |
7 |
|
8 |
Add a method indicating whether a variable is unset |
9 |
|
10 |
--- |
11 |
src/core/interpreter.h | 8 ++++++++ |
12 |
src/core/tests/interpreter_test.cpp | 8 ++++++++ |
13 |
2 files changed, 16 insertions(+), 0 deletions(-) |
14 |
|
15 |
diff --git a/src/core/interpreter.h b/src/core/interpreter.h |
16 |
index 858916e..1ce1076 100644 |
17 |
--- a/src/core/interpreter.h |
18 |
+++ b/src/core/interpreter.h |
19 |
@@ -371,6 +371,14 @@ public: |
20 |
return true; |
21 |
} |
22 |
|
23 |
+ /// \brief check whether the value of the variable is unset |
24 |
+ /// \param variable name |
25 |
+ /// \return whether the value of the variable is unset |
26 |
+ bool is_unset(const std::string& name) |
27 |
+ { |
28 |
+ return !members.resolve(name); |
29 |
+ } |
30 |
+ |
31 |
/// \brief update the variable value, raise interpreter_exception if |
32 |
/// it's readonly, will define the variable if it doesn't exist |
33 |
/// \param variable name |
34 |
|
35 |
diff --git a/src/core/tests/interpreter_test.cpp b/src/core/tests/interpreter_test.cpp |
36 |
index c3f7888..6f8d0c4 100644 |
37 |
--- a/src/core/tests/interpreter_test.cpp |
38 |
+++ b/src/core/tests/interpreter_test.cpp |
39 |
@@ -53,6 +53,14 @@ TEST(interpreter, is_null) |
40 |
EXPECT_TRUE(walker.is_null("foo")); |
41 |
} |
42 |
|
43 |
+TEST(interpreter, is_unset) |
44 |
+{ |
45 |
+ interpreter walker; |
46 |
+ walker.define("foo", "hello"); |
47 |
+ EXPECT_FALSE(walker.is_unset("foo")); |
48 |
+ EXPECT_TRUE(walker.is_unset("bar")); |
49 |
+} |
50 |
+ |
51 |
TEST(interpreter, set_int_value) |
52 |
{ |
53 |
interpreter walker; |