~a-schlapsi/nunit-3.0/linux-makefile

« back to all changes in this revision

Viewing changes to tools/src/GenSyntax/tests/GenSpecTests.cs

  • Committer: Charlie Poole
  • Date: 2009-07-17 06:38:34 UTC
  • Revision ID: charlie@nunit.com-20090717063834-frp0jzany1xtbno9
Add Gensyntax tool source code to this project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections.Generic;
 
3
using System.Text;
 
4
using NUnit.Framework;
 
5
 
 
6
namespace GenSyntax.Tests
 
7
{
 
8
    [TestFixture]
 
9
    public class GenSpecTests
 
10
    {
 
11
        [Test, ExpectedException(typeof(ArgumentException))]
 
12
        public void SpecWithoutColonThrowsException()
 
13
        {
 
14
            GenSpec spec = new GenSpec("Gen x.f()=>y");
 
15
        }
 
16
 
 
17
        [Test, ExpectedException(typeof(ArgumentException))]
 
18
        public void SpecWithoutArrowThrowsException()
 
19
        {
 
20
            GenSpec spec = new GenSpec("Gen: x.f()=y");
 
21
        }
 
22
 
 
23
        [Test, ExpectedException(typeof(ArgumentException))]
 
24
        public void SpecWithoutDotThrowsException()
 
25
        {
 
26
            GenSpec spec = new GenSpec("Gen: x=>y");
 
27
        }
 
28
 
 
29
        [Test]
 
30
        public void BasicSpec()
 
31
        {
 
32
            GenSpec spec = new GenSpec("Gen: x.f(string s)=>y.g(s)");
 
33
            Assert.That(spec.SpecType, Is.EqualTo("Gen:"));
 
34
            Assert.That(spec.LeftPart, Is.EqualTo("x.f(string s)"));
 
35
            Assert.That(spec.RightPart, Is.EqualTo("y.g(s)"));
 
36
            Assert.That(spec.ClassName, Is.EqualTo("x"));
 
37
            Assert.That(spec.MethodName, Is.EqualTo("f(string s)"));
 
38
            Assert.That(spec.Attributes, Is.EqualTo(null));
 
39
            Assert.False(spec.IsProperty);
 
40
            Assert.False(spec.IsGeneric);
 
41
        }
 
42
 
 
43
        [Test]
 
44
        public void SpecWithAttribute()
 
45
        {
 
46
            GenSpec spec = new GenSpec("Gen: [Obsolete]x.f(string s)=>y.g(s)");
 
47
            Assert.That(spec.SpecType, Is.EqualTo("Gen:"));
 
48
            Assert.That(spec.LeftPart, Is.EqualTo("[Obsolete]x.f(string s)"));
 
49
            Assert.That(spec.RightPart, Is.EqualTo("y.g(s)"));
 
50
            Assert.That(spec.ClassName, Is.EqualTo("x"));
 
51
            Assert.That(spec.MethodName, Is.EqualTo("f(string s)"));
 
52
            Assert.That(spec.Attributes, Is.EqualTo("[Obsolete]"));
 
53
            Assert.False(spec.IsProperty);
 
54
            Assert.False(spec.IsGeneric);
 
55
        }
 
56
 
 
57
        [Test]
 
58
        public void SpecWithAttribute_ArgumentContainingDot()
 
59
        {
 
60
            GenSpec spec = new GenSpec("Gen: [Obsolete(\"Use A.f()\")]x.f(string s)=>y.g(s)");
 
61
            Assert.That(spec.SpecType, Is.EqualTo("Gen:"));
 
62
            Assert.That(spec.LeftPart, Is.EqualTo("[Obsolete(\"Use A.f()\")]x.f(string s)"));
 
63
            Assert.That(spec.RightPart, Is.EqualTo("y.g(s)"));
 
64
            Assert.That(spec.ClassName, Is.EqualTo("x"));
 
65
            Assert.That(spec.MethodName, Is.EqualTo("f(string s)"));
 
66
            Assert.That(spec.Attributes, Is.EqualTo("[Obsolete(\"Use A.f()\")]"));
 
67
            Assert.False(spec.IsProperty);
 
68
            Assert.False(spec.IsGeneric);
 
69
        }
 
70
 
 
71
        [Test]
 
72
        public void SpecDefinesProperty()
 
73
        {
 
74
            GenSpec spec = new GenSpec("Gen: Is.Null=>new NullConstraint()");
 
75
            Assert.That(spec.SpecType, Is.EqualTo("Gen:"));
 
76
            Assert.That(spec.LeftPart, Is.EqualTo("Is.Null"));
 
77
            Assert.That(spec.RightPart, Is.EqualTo("new NullConstraint()"));
 
78
            Assert.That(spec.ClassName, Is.EqualTo("Is"));
 
79
            Assert.That(spec.MethodName, Is.EqualTo("Null"));
 
80
            Assert.That(spec.Attributes, Is.EqualTo(null));
 
81
            Assert.True(spec.IsProperty);
 
82
            Assert.False(spec.IsGeneric);
 
83
        }
 
84
 
 
85
        [Test]
 
86
        public void SpecIsGeneric()
 
87
        {
 
88
            GenSpec spec = new GenSpec("Gen: Is.TypeOf<T>()=>new ExactTypeConstraint<T>()");
 
89
            Assert.That(spec.SpecType, Is.EqualTo("Gen:"));
 
90
            Assert.That(spec.LeftPart, Is.EqualTo("Is.TypeOf<T>()"));
 
91
            Assert.That(spec.RightPart, Is.EqualTo("new ExactTypeConstraint<T>()"));
 
92
            Assert.That(spec.ClassName, Is.EqualTo("Is"));
 
93
            Assert.That(spec.MethodName, Is.EqualTo("TypeOf<T>()"));
 
94
            Assert.That(spec.Attributes, Is.EqualTo(null));
 
95
            Assert.False(spec.IsProperty);
 
96
            Assert.True(spec.IsGeneric);
 
97
        }
 
98
    }
 
99
}