summaryrefslogtreecommitdiff
path: root/src/main/interactive_shell.cpp
diff options
context:
space:
mode:
authorChristopher L. Conway <christopherleeconway@gmail.com>2010-10-24 16:37:00 +0000
committerChristopher L. Conway <christopherleeconway@gmail.com>2010-10-24 16:37:00 +0000
commitade732181ad2eabfb3a6eef46bdc9ea42d27246e (patch)
treed487a25c2cc7bfbf610b57e9b4cd5cba2701a4c4 /src/main/interactive_shell.cpp
parentd8a8f335f4043a0117f2b92af3d1e94f285e4d30 (diff)
Adding unit test for InteractiveShell
Diffstat (limited to 'src/main/interactive_shell.cpp')
-rw-r--r--src/main/interactive_shell.cpp41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/main/interactive_shell.cpp b/src/main/interactive_shell.cpp
index 587c07495..8437d61b2 100644
--- a/src/main/interactive_shell.cpp
+++ b/src/main/interactive_shell.cpp
@@ -52,25 +52,15 @@ Command* InteractiveShell::readCommand() {
line = sb.str();
// cout << "Input was '" << input << "'" << endl << flush;
- /* If we hit EOF, we're done. */
- if( d_in.eof() ) {
- input += line;
- break;
- }
+ Assert( !(d_in.fail() && !d_in.eof()) || line.empty() );
- /* Check for failure */
- if( d_in.fail() ) {
+ /* Check for failure. */
+ if( d_in.fail() && !d_in.eof() ) {
/* This should only happen if the input line was empty. */
Assert( line.empty() );
d_in.clear();
}
- /* Extract the newline delimiter from the stream too */
- int c = d_in.get();
- Assert( c == '\n' );
-
- // cout << "Next char is '" << (char)c << "'" << endl << flush;
-
/* Strip trailing whitespace. */
int n = line.length() - 1;
while( !line.empty() && isspace(line[n]) ) {
@@ -78,12 +68,31 @@ Command* InteractiveShell::readCommand() {
n--;
}
+ /* If we hit EOF, we're done. */
+ if( d_in.eof() ) {
+ input += line;
+
+ if( input.empty() ) {
+ /* Nothing left to parse. */
+ return NULL;
+ }
+
+ /* Some input left to parse, but nothing left to read.
+ Jump out of input loop. */
+ break;
+ }
+
+ /* Extract the newline delimiter from the stream too */
+ int c = d_in.get();
+ Assert( c == '\n' );
+
+ // cout << "Next char is '" << (char)c << "'" << endl << flush;
+
input += line;
/* If the last char was a backslash, continue on the next line. */
- if( !line.empty() && line[n] == '\\' ) {
- n = input.length() - 1;
- Assert( input[n] == '\\' );
+ n = input.length() - 1;
+ if( !line.empty() && input[n] == '\\' ) {
input[n] = '\n';
d_out << "... > " << flush;
} else {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback