示例#1
0
void mustache_spec_parse_test(yaml_document_t * document, yaml_node_t * node)
{
  if( node->type != YAML_MAPPING_NODE ) {
    return;
  }
  
  MustacheSpecTest * test = new MustacheSpecTest;
  
  yaml_node_pair_t * pair;
  for( pair = node->data.mapping.pairs.start; pair < node->data.mapping.pairs.top; pair++ ) {
    yaml_node_t * keyNode = yaml_document_get_node(document, pair->key);
    yaml_node_t * valueNode = yaml_document_get_node(document, pair->value);
    char * keyValue = reinterpret_cast<char *>(keyNode->data.scalar.value);
    
    if( valueNode->type == YAML_SCALAR_NODE ) {
      char * valueValue = reinterpret_cast<char *>(valueNode->data.scalar.value);
      if( strcmp(keyValue, "name") == 0 ) {
        test->name.assign(valueValue);
      } else if( strcmp(keyValue, "desc") == 0 ) {
        test->desc.assign(valueValue);
      } else if( strcmp(keyValue, "template") == 0 ) {
        test->tmpl.assign(valueValue);
      } else if( strcmp(keyValue, "expected") == 0 ) {
        test->expected.assign(valueValue);
      }
    } else if( valueNode->type == YAML_MAPPING_NODE ) {
      if( strcmp(keyValue, "data") == 0 ) {
        mustache_spec_parse_data(document, valueNode, &test->data);
      } else if( strcmp(keyValue, "partials") == 0 ) {
        mustache_spec_parse_partials(document, valueNode, &test->partials);
      }
    }
  }
  
  mustache::Mustache mustache;
  mustache::Compiler compiler;
  mustache::VM vm;
  
  // Tokenize
  mustache::Node root;
  mustache.tokenize(&test->tmpl, &root);
  
  // Compile
  mustache::Compiler::vectorToBuffer(compiler.compile(&root, &test->partials), &test->compiled, &test->compiled_length);
  
  // Execute the test
  for( int i = 0; i < execNum; i++ ) {
    test->output.clear();
    mustache.render(&root, &test->data, &test->partials, &test->output);
  }
  
  // Execute the test in VM mode
  for( int i = 0; i < execNum; i++ ) {
    test->compiled_output.clear();
    vm.execute(test->compiled, test->compiled_length, &test->data, &test->compiled_output);
  }
  
  // Output result
  test->print();
  tests.push_back(test);
}
示例#2
0
void mustache_spec_parse_test(yaml_document_t * document, yaml_node_t * node)
{
  if( node->type != YAML_MAPPING_NODE ) {
    return;
  }
  
  MustacheSpecTest * test = new MustacheSpecTest;
  
  yaml_node_pair_t * pair;
  for( pair = node->data.mapping.pairs.start; pair < node->data.mapping.pairs.top; pair++ ) {
    yaml_node_t * keyNode = yaml_document_get_node(document, pair->key);
    yaml_node_t * valueNode = yaml_document_get_node(document, pair->value);
    char * keyValue = reinterpret_cast<char *>(keyNode->data.scalar.value);
    
    if( valueNode->type == YAML_SCALAR_NODE ) {
      char * valueValue = reinterpret_cast<char *>(valueNode->data.scalar.value);
      if( strcmp(keyValue, "name") == 0 ) {
        test->name.assign(valueValue);
      } else if( strcmp(keyValue, "desc") == 0 ) {
        test->desc.assign(valueValue);
      } else if( strcmp(keyValue, "template") == 0 ) {
        test->tmpl.assign(valueValue);
      } else if( strcmp(keyValue, "expected") == 0 ) {
        test->expected.assign(valueValue);
      }
    } else if( valueNode->type == YAML_MAPPING_NODE ) {
      if( strcmp(keyValue, "data") == 0 ) {
        mustache_spec_parse_data(document, valueNode, &test->data);
      } else if( strcmp(keyValue, "partials") == 0 ) {
        mustache_spec_parse_partials(document, valueNode, &test->partials);
      }
    }
  }
  
  mustache::Mustache mustache;
  bool isLambdaSuite = 0 == strcmp(currentSuite, "~lambdas.yml");
  
  // Load lambdas?
  if( isLambdaSuite ) {
    load_lambdas_into_test_data(&test->data, test->name);
  }

  // This test isn't supported yet
  if (test->name == "Implicit Iterator - Array") {
    return;
  }

  // Tokenize
  mustache::Node root;
  mustache.tokenize(&test->tmpl, &root);
  
  // Execute the test
  for( int i = 0; i < execNum; i++ ) {
    test->output.clear();
    mustache.render(&root, &test->data, &test->partials, &test->output);
  }
  
  // Output result
  test->print();
  tests.push_back(test);
}