Fix memoization of functions called with keyset arguments
[hiphop-php.git] / hphp / test / ext / test_parser.cpp
blobc3bdf56f6de1be39d6a8a92ebc82f3917ad89811
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2016 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/test/ext/test_parser.h"
18 #include "hphp/compiler/parser/parser.h"
19 #include "hphp/compiler/code_generator.h"
20 #include "hphp/compiler/statement/statement_list.h"
21 #include "hphp/compiler/analysis/analysis_result.h"
22 #include "hphp/util/text-util.h"
24 ///////////////////////////////////////////////////////////////////////////////
26 static void strip_empty_block(std::string &s) {
27 if (s.size() >= 2 && s[0] == '{' && s[s.size() - 1] == '}') {
28 s = s.substr(1, s.size() - 2);
32 bool TestParser::SameCode(std::string code1, std::string code2) {
33 replaceAll(code1, "\n", "");
34 replaceAll(code2, "\n", "");
36 replaceAll(code1, "{{}}", "{}");
37 replaceAll(code2, "{{}}", "{}");
38 replaceAll(code1, "else {}", "");
39 replaceAll(code2, "else {}", "");
40 strip_empty_block(code1);
41 strip_empty_block(code2);
43 return code1 == code2;
46 bool TestParser::VerifyParser(const char *input, const char *output,
47 const char *file /* = "" */, int line /* = 0 */,
48 const char *output2 /* = NULL */) {
49 assert(input);
50 assert(output);
51 if (output2 == nullptr) output2 = output;
53 std::string oldTab = Option::Tab;
54 Option::Tab = "";
56 bool ret = true;
58 AnalysisResultPtr ar(new AnalysisResult());
59 StatementListPtr tree = Compiler::Parser::ParseString(input, ar);
60 std::ostringstream code;
61 CodeGenerator cg(&code);
62 tree->outputPHP(cg, ar);
63 if (!SameCode(code.str(), output)) {
64 printf("======================================\n"
65 "[Compiler] %s:%d:\n"
66 "======================================\n",
67 file, line);
68 printf("[%s]\nExpecting %d: [%s]\nGot %d: [%s]\n",
69 input, (int)strlen(output), output,
70 (int)code.str().length(), code.str().c_str());
71 ret = false;
75 Option::Tab = oldTab;
76 return ret;