2
using System.Collections.Generic;
6
namespace GenSyntax.Tests
9
public class GenSpecTests
11
[Test, ExpectedException(typeof(ArgumentException))]
12
public void SpecWithoutColonThrowsException()
14
GenSpec spec = new GenSpec("Gen x.f()=>y");
17
[Test, ExpectedException(typeof(ArgumentException))]
18
public void SpecWithoutArrowThrowsException()
20
GenSpec spec = new GenSpec("Gen: x.f()=y");
23
[Test, ExpectedException(typeof(ArgumentException))]
24
public void SpecWithoutDotThrowsException()
26
GenSpec spec = new GenSpec("Gen: x=>y");
30
public void BasicSpec()
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);
44
public void SpecWithAttribute()
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);
58
public void SpecWithAttribute_ArgumentContainingDot()
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);
72
public void SpecDefinesProperty()
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);
86
public void SpecIsGeneric()
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);