Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/libbash:master commit in: src/core/, src/core/tests/
Date: Fri, 27 May 2011 23:04:27
Message-Id: b36f96514be51edfa2fa147157972a627adcc292.betelgeuse@gentoo
1 commit: b36f96514be51edfa2fa147157972a627adcc292
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Wed May 25 15:04:32 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Thu May 26 14:56:30 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=b36f9651
7
8 Core: return default value when name doesn't exist
9
10 The interpreter class would throw an exception if the variable name
11 was "" and would return the default value if the variable couldn't
12 be find. Now this behavior is unified by returning the default value.
13
14 ---
15 src/core/interpreter.cpp | 3 ++-
16 src/core/tests/interpreter_test.cpp | 2 ++
17 2 files changed, 4 insertions(+), 1 deletions(-)
18
19 diff --git a/src/core/interpreter.cpp b/src/core/interpreter.cpp
20 index 2337e87..c8611d6 100644
21 --- a/src/core/interpreter.cpp
22 +++ b/src/core/interpreter.cpp
23 @@ -101,7 +101,8 @@ std::string interpreter::get_string(pANTLR3_BASE_TREE node)
24 std::shared_ptr<variable> interpreter::resolve_variable(const std::string& name) const
25 {
26 if(name.empty())
27 - throw interpreter_exception("Variable name shouldn't be empty");
28 + return std::shared_ptr<variable>();
29 +
30 // positional parameter
31 if(isdigit(name[0]) && !local_members.empty())
32 {
33
34 diff --git a/src/core/tests/interpreter_test.cpp b/src/core/tests/interpreter_test.cpp
35 index ab24449..0322a6b 100644
36 --- a/src/core/tests/interpreter_test.cpp
37 +++ b/src/core/tests/interpreter_test.cpp
38 @@ -34,6 +34,7 @@ TEST(interpreter, define_resolve_int)
39 walker.define("aint", 4);
40 EXPECT_EQ(4, walker.resolve<int>("aint"));
41 EXPECT_EQ(0, walker.resolve<int>("undefined"));
42 + EXPECT_EQ(0, walker.resolve<int>(""));
43 }
44
45 TEST(interpreter, define_resolve_string)
46 @@ -42,6 +43,7 @@ TEST(interpreter, define_resolve_string)
47 walker.define("astring", "hello");
48 EXPECT_STREQ("hello", walker.resolve<string>("astring").c_str());
49 EXPECT_STREQ("", walker.resolve<string>("undefined").c_str());
50 + EXPECT_STREQ("", walker.resolve<string>("").c_str());
51 }
52
53 TEST(interpreter, define_resolve_array)