/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/MemberReferenceExpressionTests.cs

http://github.com/icsharpcode/ILSpy · C# · 126 lines · 98 code · 11 blank · 17 comment · 0 complexity · 5a4745fd32824dae5e0721241eaaedd5 MD5 · raw file

  1. // Copyright (c) AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using NUnit.Framework;
  20. namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
  21. {
  22. [TestFixture]
  23. public class MemberReferenceExpressionTests
  24. {
  25. [Test]
  26. public void SimpleFieldReferenceExpressionTest()
  27. {
  28. ParseUtilCSharp.AssertExpression(
  29. "myTargetObject.myField",
  30. new IdentifierExpression("myTargetObject").Member("myField")
  31. );
  32. }
  33. [Test]
  34. public void ShortMaxValueTest()
  35. {
  36. ParseUtilCSharp.AssertExpression(
  37. "short.MaxValue",
  38. new PrimitiveType("short").Member("MaxValue")
  39. );
  40. }
  41. [Test]
  42. public void IdentShortMaxValueTest()
  43. {
  44. ParseUtilCSharp.AssertExpression(
  45. "@short.MaxValue",
  46. new IdentifierExpression("short").Member("MaxValue")
  47. );
  48. }
  49. [Test]
  50. public void GenericFieldReferenceExpressionTest()
  51. {
  52. ParseUtilCSharp.AssertExpression(
  53. "SomeClass<string>.myField",
  54. new IdentifierExpression("SomeClass") { TypeArguments = { new PrimitiveType("string") } }.Member("myField")
  55. );
  56. }
  57. [Test]
  58. public void FullNamespaceGenericFieldReferenceExpressionTest()
  59. {
  60. ParseUtilCSharp.AssertExpression(
  61. "Namespace.Subnamespace.SomeClass<string>.myField",
  62. new MemberReferenceExpression {
  63. Target = new IdentifierExpression("Namespace").Member("Subnamespace"),
  64. MemberName = "SomeClass",
  65. TypeArguments = { new PrimitiveType("string") }
  66. }.Member("myField")
  67. );
  68. }
  69. [Test]
  70. public void GlobalFullNamespaceGenericFieldReferenceExpressionTest()
  71. {
  72. var target = new MemberType {
  73. Target = new SimpleType("global"),
  74. IsDoubleColon = true,
  75. MemberName = "Namespace"
  76. }.Member("Subnamespace").Member ("SomeClass");
  77. target.AddChild (new PrimitiveType("string"), Roles.TypeArgument);
  78. ParseUtilCSharp.AssertExpression(
  79. "global::Namespace.Subnamespace.SomeClass<string>.myField",
  80. new MemberReferenceExpression {
  81. Target = target,
  82. MemberName = "myField"
  83. }
  84. );
  85. }
  86. [Test]
  87. public void NestedGenericFieldReferenceExpressionTest()
  88. {
  89. ParseUtilCSharp.AssertExpression(
  90. "MyType<string>.InnerClass<int>.myField",
  91. new MemberReferenceExpression {
  92. Target = new IdentifierExpression("MyType") { TypeArguments = { new PrimitiveType("string") } },
  93. MemberName = "InnerClass",
  94. TypeArguments = { new PrimitiveType("int") }
  95. }.Member("myField")
  96. );
  97. }
  98. [Test]
  99. public void AliasedNamespace()
  100. {
  101. ParseUtilCSharp.AssertExpression(
  102. "a::b.c",
  103. new MemberReferenceExpression {
  104. Target = new TypeReferenceExpression {
  105. Type = new MemberType {
  106. Target = new SimpleType("a"),
  107. IsDoubleColon = true,
  108. MemberName = "b"
  109. }
  110. },
  111. MemberName = "c"
  112. });
  113. }
  114. }
  115. }