diff options
author | Christopher L. Conway <christopherleeconway@gmail.com> | 2010-10-24 16:37:00 +0000 |
---|---|---|
committer | Christopher L. Conway <christopherleeconway@gmail.com> | 2010-10-24 16:37:00 +0000 |
commit | ade732181ad2eabfb3a6eef46bdc9ea42d27246e (patch) | |
tree | d487a25c2cc7bfbf610b57e9b4cd5cba2701a4c4 /src/main/interactive_shell.cpp | |
parent | d8a8f335f4043a0117f2b92af3d1e94f285e4d30 (diff) |
Adding unit test for InteractiveShell
Diffstat (limited to 'src/main/interactive_shell.cpp')
-rw-r--r-- | src/main/interactive_shell.cpp | 41 |
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 { |