~alexreg/mathtexdotnet/0.1

« back to all changes in this revision

Viewing changes to TexDotNet.Tests/TestExample.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.Generic;
3
 
using System.IO;
4
 
using System.Linq;
5
 
using System.Text;
6
 
using Microsoft.VisualStudio.TestTools.UnitTesting;
7
 
 
8
 
namespace TexDotNet.Tests
9
 
{
10
 
    using TokenStream = IEnumerable<TexToken>;
11
 
 
12
 
    public class TestExample
13
 
    {
14
 
        public TestExample(string text, TexToken[] expectedTokens)
15
 
        {
16
 
            this.Text = text;
17
 
            this.ExpectedTokens = expectedTokens;
18
 
        }
19
 
 
20
 
        public string Text
21
 
        {
22
 
            get;
23
 
            private set;
24
 
        }
25
 
 
26
 
        public TexToken[] Tokens
27
 
        {
28
 
            get;
29
 
            private set;
30
 
        }
31
 
 
32
 
        public TexToken[] ExpectedTokens
33
 
        {
34
 
            get;
35
 
            private set;
36
 
        }
37
 
 
38
 
        public void Initialise(TexLexer lexer)
39
 
        {
40
 
            using (var reader = new StringReader(this.Text))
41
 
                this.Tokens = lexer.Tokenise(reader).ToArray();
42
 
        }
43
 
 
44
 
        public void TestLexer()
45
 
        {
46
 
            CollectionAssert.AreEqual(this.ExpectedTokens, this.Tokens);
47
 
        }
48
 
    }
49
 
}