~alexreg/mathtexdotnet/0.1

« back to all changes in this revision

Viewing changes to TexDotNet.Tests/LexerTests.cs

  • Committer: Alex Regueiro
  • Date: 2009-09-25 19:25:01 UTC
  • Revision ID: alexreg@gmail.com-20090925192501-lyu4daug4m0f6he7
Rewrote testing framework. Tests work on principle that if you parse an expression, write it back, and parse it again, the two expression trees should always be equivalent.
Fixed bug in TexComposer involving  brackets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
using System;
2
 
using System.Collections;
3
 
using System.Collections.Generic;
4
 
using System.Diagnostics;
5
 
using System.IO;
6
 
using System.Linq;
7
 
using System.Text;
8
 
using Microsoft.VisualStudio.TestTools.UnitTesting;
9
 
 
10
 
namespace TexDotNet.Tests
11
 
{
12
 
    using TokenStream = IEnumerable<TexToken>;
13
 
 
14
 
    [TestClass]
15
 
    public class LexerTests
16
 
    {
17
 
        private static TestExample[] examples;
18
 
 
19
 
        [ClassInitialize()]
20
 
        public static void ClassInitialize(TestContext testContext)
21
 
        {
22
 
            using (var examplesReader = new TestExamplesReader(SystemHelper.GetResourceStream("Examples.txt")))
23
 
                LexerTests.examples = examplesReader.ReadAllExamples().ToArray();
24
 
        }
25
 
 
26
 
        [ClassCleanup()]
27
 
        public static void ClassCleanup()
28
 
        {
29
 
        }
30
 
 
31
 
        private TexLexer lexer;
32
 
        
33
 
        public LexerTests()
34
 
        {
35
 
            lexer = new TexLexer();
36
 
        }
37
 
 
38
 
        public TestContext TestContext
39
 
        {
40
 
            get;
41
 
            set;
42
 
        }
43
 
 
44
 
        [TestInitialize()]
45
 
        public void TestInitialize()
46
 
        {
47
 
        }
48
 
 
49
 
        [TestCleanup()]
50
 
        public void TestCleanup()
51
 
        {
52
 
        }
53
 
 
54
 
        [TestMethod()]
55
 
        public void LexerExamplesTest()
56
 
        {
57
 
            foreach (var example in examples)
58
 
            {
59
 
                example.Initialise(lexer);
60
 
 
61
 
                Trace.WriteLine("Token string:");
62
 
                Trace.WriteLine(example.Text);
63
 
                Trace.WriteLine("Lexed token stream:");
64
 
                Trace.WriteLine(example.Tokens.ToTokenString());
65
 
                Trace.WriteLine("Expected token stream:");
66
 
                Trace.WriteLine(example.ExpectedTokens.ToTokenString());
67
 
                Trace.WriteLine(null);
68
 
 
69
 
                //example.TestLexer();
70
 
            }
71
 
        }
72
 
    }
73
 
}