[prettyprint] r589 committed - ...

0 views
Skip to first unread message

prett...@googlecode.com

unread,
Jul 9, 2010, 11:46:44 AM7/9/10
to pp-d...@googlegroups.com
Revision: 589
Author: thockin
Date: Fri Jul 9 08:45:37 2010
Log:
Fix the parse_and_validate test, add new cases.


http://code.google.com/p/prettyprint/source/detail?r=589

Modified:
/trunk/language/environment.cpp
/trunk/language/environment.h
/trunk/language/tests/parse_and_validate_test.cpp

=======================================
--- /trunk/language/environment.cpp Thu Jul 8 08:05:06 2010
+++ /trunk/language/environment.cpp Fri Jul 9 08:45:37 2010
@@ -22,15 +22,15 @@
if (!file) {
return NULL;
}
+ // RAII for file.
+ boost::shared_ptr<FILE> file_ptr(file, fclose);
+
return parse_file(file, name);
}

const ParsedFile *
Environment::parse_file(FILE *file, const string &name)
{
- // RAII for file.
- boost::shared_ptr<FILE> file_ptr(file, fclose);
-
// Parse the file.
std::auto_ptr<ParsedFile> parsed_file_ptr(new ParsedFile());
ParsedFile *current_file = parsed_file_ptr.get();
=======================================
--- /trunk/language/environment.h Thu Jul 8 08:05:06 2010
+++ /trunk/language/environment.h Fri Jul 9 08:45:37 2010
@@ -84,12 +84,13 @@
}
~Environment();

- // Open and parse a file name. The caller owns the returned pointer.
+ // Open and parse a file name. This object owns the returned pointer.
// Returns NULL on failure.
const ParsedFile *
parse_file(const string &name);
- // Parse an already opened file. The caller owns both the FILE pointer
- // and the returned pointer. Returns NULL on failure.
+ // Parse an already opened file. This object owns the returned pointer.
+ // This does not take ownership of the FILE pointer. Returns NULL on
+ // failure.
const ParsedFile *
parse_file(FILE *file, const string &name);

=======================================
--- /trunk/language/tests/parse_and_validate_test.cpp Thu Jul 8 08:05:06
2010
+++ /trunk/language/tests/parse_and_validate_test.cpp Fri Jul 9 08:45:37
2010
@@ -10,7 +10,8 @@
static util::PipeFile *pipef;
static const pp::language::ParsedFile *parsed_file;

-TEST_SETUP_EACH() {
+static void reinit()
+{
delete env;
env = new pp::language::Environment();

@@ -18,9 +19,12 @@
pipef = new util::PipeFile();
TEST_ASSERT(pipef->open() == true);

- delete parsed_file;
parsed_file = NULL;
}
+
+TEST_SETUP_EACH() {
+ reinit();
+}

static void
write_to_pipe(const string &str)
@@ -49,6 +53,66 @@
"tuple<int,string> tis; \n"
"var v; \n"
) == 0);
+ reinit();
+
+ TEST_ASSERT(parse_and_validate(
+ "bool b = true; \n"
+ "func f = ${}; \n"
+ "int i = -1; \n"
+ "list<int> li = [93,76]; \n"
+ "string s = \"foo\"; \n"
+ "tuple<int,string> tis = [93, \"seven-six\"]; \n"
+ "var v = 12345; \n"
+ ) == 0);
+ reinit();
+
+ TEST_ASSERT(parse_and_validate(
+ "list l = [ 0, 0 ]; \n"
+ "tuple t = [ 93, \"seven-six\" ]; \n"
+ ) == 0);
+ reinit();
+
+ TEST_ASSERT(parse_and_validate(
+ "const tuple t = [ false ]; \n"
+ "bool b = t[0]; \n"
+ ) == 0);
+ reinit();
+
+ try {
+ parse_and_validate(
+ "const list l = [true, true]; \n"
+ "int i = l[0]; \n"
+ );
+ TEST_FAIL();
+ } catch (pp::language::SyntaxError &e) {
+ } catch (...) {
+ TEST_FAIL();
+ }
+ reinit();
+
+ try {
+ parse_and_validate(
+ "const tuple t = [ false ]; \n"
+ "int i = t[0]; \n"
+ );
+ TEST_FAIL();
+ } catch (pp::language::SyntaxError &e) {
+ } catch (...) {
+ TEST_FAIL();
+ }
+ reinit();
+
+ try {
+ parse_and_validate(
+ "const tuple t = [ false ]; \n"
+ "var i = t[1]; \n"
+ );
+ TEST_FAIL();
+ } catch (pp::language::SyntaxError &e) {
+ } catch (...) {
+ TEST_FAIL();
+ }
+ reinit();
}

// vim: set ai tabstop=4 shiftwidth=4 noexpandtab:

Reply all
Reply to author
Forward
0 new messages