From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: test/
Date: Thu, 31 Mar 2011 12:32:31 +0000 (UTC) [thread overview]
Message-ID: <f7c40576759f562a3911b2adbc49eabb4e94a0e4.betelgeuse@gentoo> (raw)
commit: f7c40576759f562a3911b2adbc49eabb4e94a0e4
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Mar 31 03:13:53 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Mar 31 08:29:31 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=f7c40576
Refactor unit test to allow adding new rules
Extract some logic into subclass in order to make it possible to
add new rules.
---
test/walker_test.cpp | 67 +++++++++++++++++++++++++++----------------------
1 files changed, 37 insertions(+), 30 deletions(-)
diff --git a/test/walker_test.cpp b/test/walker_test.cpp
index 41720ad..c026605 100644
--- a/test/walker_test.cpp
+++ b/test/walker_test.cpp
@@ -38,10 +38,9 @@ class walker_test: public ::testing::Test
pANTLR3_INPUT_STREAM input;
plibbashLexer lxr;
pANTLR3_COMMON_TOKEN_STREAM tstream;
- plibbashParser psr;
- libbashParser_arithmetics_return langAST;
- pANTLR3_COMMON_TREE_NODE_STREAM nodes;
protected:
+ pANTLR3_COMMON_TREE_NODE_STREAM nodes;
+ plibbashParser psr;
virtual void SetUp()
{
walker = shared_ptr<interpreter>(new interpreter);
@@ -55,30 +54,13 @@ protected:
lxr->free(lxr);
input->close(input);
}
- void init_walker(const char* script);
+ void init_parser(const char*);
public:
plibbashWalker treePsr;
shared_ptr<interpreter> walker;
-
- int run_arithmetic(const char* script)
- {
- init_walker(script);
- return treePsr->arithmetics(treePsr);
- }
-
- void check_arithmetic_assignment(const char* script,
- const string& name,
- int exp_value)
- {
- // the return value of the arithmetic expression should be equal to
- // the new value of the variable
- EXPECT_EQ(exp_value, run_arithmetic(script));
- EXPECT_EQ(exp_value, walker->resolve<int>(name));
- }
};
-
-void walker_test::init_walker(const char *script){
+void walker_test::init_parser(const char *script){
auto start = reinterpret_cast<pANTLR3_UINT8>(const_cast<char *>(script));
input = antlr3NewAsciiStringInPlaceStream(start,
@@ -115,17 +97,42 @@ void walker_test::init_walker(const char *script){
ANTLR3_FPRINTF(stderr, "Out of memory trying to allocate parser\n");
FAIL();
}
+}
- langAST = psr->arithmetics(psr);
- nodes = antlr3CommonTreeNodeStreamNewTree(langAST.tree,
+class arithmetic_walker: public walker_test
+{
+ libbashParser_arithmetics_return langAST;
+protected:
+ void init_walker(const char* script)
+ {
+ init_parser(script);
+ langAST = psr->arithmetics(psr);
+ nodes = antlr3CommonTreeNodeStreamNewTree(langAST.tree,
ANTLR3_SIZE_HINT);
- treePsr = libbashWalkerNew(nodes);
- walker->define("value", 100);
- set_interpreter(walker);
-}
+ treePsr = libbashWalkerNew(nodes);
+ walker->define("value", 100);
+ set_interpreter(walker);
+ }
+
+ int run_arithmetic(const char* script)
+ {
+ init_walker(script);
+ return treePsr->arithmetics(treePsr);
+ }
+
+ void check_arithmetic_assignment(const char* script,
+ const string& name,
+ int exp_value)
+ {
+ // the return value of the arithmetic expression should be equal to
+ // the new value of the variable
+ EXPECT_EQ(exp_value, run_arithmetic(script));
+ EXPECT_EQ(exp_value, walker->resolve<int>(name));
+ }
+};
#define TEST_BINARY_ARITHMETIC(name, script, exp_value)\
- TEST_F(walker_test, name)\
+ TEST_F(arithmetic_walker, name)\
{EXPECT_EQ(exp_value, run_arithmetic(script));}
TEST_BINARY_ARITHMETIC(logicor_true, "0 || -2", 1)
@@ -167,7 +174,7 @@ TEST_BINARY_ARITHMETIC(complex_cal2, "10*${value}<<3%2**5", 8000)
TEST_BINARY_ARITHMETIC(complex_cal3, "(20&5|3||1*100-20&5*10)+~(2*5)", -10)
#define TEST_ARITHMETIC_ASSIGNMENT(name, script, var_name, exp_value)\
- TEST_F(walker_test, name) \
+ TEST_F(arithmetic_walker, name) \
{ check_arithmetic_assignment(script, var_name, exp_value); }
TEST_ARITHMETIC_ASSIGNMENT(assignment, "new_var=10", "new_var", 10)
next reply other threads:[~2011-03-31 12:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-31 12:32 Petteri Räty [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-06-19 19:15 [gentoo-commits] proj/libbash:master commit in: test/ Petteri Räty
2011-06-09 8:15 Petteri Räty
2011-05-27 23:03 Petteri Räty
2011-05-24 14:40 Petteri Räty
2011-04-03 10:16 Petteri Räty
2011-04-02 15:50 Petteri Räty
2011-03-30 12:48 Petteri Räty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f7c40576759f562a3911b2adbc49eabb4e94a0e4.betelgeuse@gentoo \
--to=betelgeuse@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox