// htmlTagMatcherTest.cc  P. Conrad for CISC220, 06J
// check HTML input for matching tags
// this program does test driven development of HTMLTagMatcher_C class

#include "runTests.h"
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;

// Now also do #include <string> and #include <sstream>
// This allows us to write to a string (C++ style string) as if it were 
// a file.  That way, we can test our print functions

#include <string>
using std::string;

#include <sstream>
using std::istringstream;
using std::ostringstream;

#include "HTMLTagMatcher.h"

void printHeader(const char * const file, int line)
{
  cout << "\n=== Tests from " << file << " at line " << line << "===" << endl;
}

int main(void)
{

  RunTests_C test;

  { 
    // enter inner scope so we can reuse variable names 
    // and also so that the destructor gets invoked 
    // at the end of the block

    printHeader(__FILE__,__LINE__);

    string theInput("<html>\n" 
		    "</html>");

    istringstream iss(theInput);
    ostringstream oss;

    HTMLTagMatcher_C m(iss,oss);

    m.match();
    test.assertEquals(oss.str(), "ok");

  }

  { 
    // enter inner scope so we can reuse variable names 
    // and also so that the destructor gets invoked 
    // at the end of the block

    printHeader(__FILE__,__LINE__);

    string theInput("<html>\n" 
		    "<p>\n"
		    "</html>\n");

    istringstream iss(theInput);
    ostringstream oss;

    HTMLTagMatcher_C m(iss,oss);

    m.match();
    test.assertEquals(oss.str(), "Closing tag </html> on line: 3 char: 1 doesn't match open tag <p> line: 2 char: 1");

  }

  test.print();
  test.finish();

}









