Exemplo n.º 1
0
bool TestParser::VerifyParser(const char *input, const char *output,
                              const char *file /* = "" */, int line /* = 0 */,
                              const char *output2 /* = NULL */) {
  ASSERT(input);
  ASSERT(output);
  if (output2 == NULL) output2 = output;

  string oldTab = Option::Tab;
  Option::Tab = "";

  bool ret = true;
  {
    AnalysisResultPtr ar(new AnalysisResult());
    Compiler::Parser::Reset();
    StatementListPtr tree = Compiler::Parser::ParseString(input, ar);
    std::ostringstream code;
    CodeGenerator cg(&code);
    tree->outputPHP(cg, ar);
    if (!SameCode(code.str(), output)) {
      printf("======================================\n"
             "[Compiler] %s:%d:\n"
             "======================================\n",
             file, line);
      printf("[%s]\nExpecting %d: [%s]\nGot %d: [%s]\n",
             input, (int)strlen(output), output,
             (int)code.str().length(), code.str().c_str());
      ret = false;
    }
  }

  Option::Tab = oldTab;
  return ret;
}
Exemplo n.º 2
0
bool TestParser::VerifyParser(const char *input, const char *output,
                              const char *file /* = "" */,
                              int line /* = 0 */) {
  ASSERT(input);
  ASSERT(output);

  AnalysisResultPtr ar(new AnalysisResult());
  StatementListPtr tree = Parser::parseString(input, ar);
  ostringstream code;
  CodeGenerator cg(&code);
  tree->outputPHP(cg, ar);
  if (code.str() != output) {
    printf("%s:%d\nParsing: [%s]\nExpecting %d: [%s]\nGot %d: [%s]\n",
           file, line, input, (int)strlen(output), output,
           (int)code.str().length(), code.str().c_str());
    return false;
  }
  return true;
}