using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using Axiom.Utils;
using Axiom.Interpreter;
using System.IO;

namespace AxiomUnitTestProject
{
  [TestClass]
  public class ParserTests
  {
    [TestMethod]
    public void ParserShouldParseAll()
    {
      List<String> codeLines = TestData.CodeLines();
      foreach(String expression in codeLines)
      {
        BinaryWriter binaryWriter=new BinaryWriter(new MemoryStream());
        SymbolTable symbolTable = new SymbolTable();
        BinaryReader binaryReader = null;
        binaryReader = new BinaryReader(Utility.StreamFromString(expression));
        Scanner scanner = new Scanner(binaryReader, binaryWriter, symbolTable);
        scanner.Debug=false;
        Console.WriteLine("Expression:\""+expression+"\"");
        Assert.IsTrue(scanner.Analyze());
        binaryWriter.BaseStream.Seek(0, SeekOrigin.Begin);
        BinaryReader parserReader = new BinaryReader(binaryWriter.BaseStream);
        BinaryWriter parserWriter = new BinaryWriter(new MemoryStream());
        Parser parser = new Parser(parserReader,parserWriter,symbolTable);
        parser.Debug=true;
        parser.Parse();
        Assert.IsFalse(parser.IsInError,parser.LastMessage);
      }
    }
  }
}