BindingExpressionGrammarTests_Errors.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Avalonia.Data.Core;
  2. using Xunit;
  3. namespace Avalonia.Markup.UnitTests.Parsers
  4. {
  5. public partial class BindingExpressionGrammarTests
  6. {
  7. [Fact]
  8. public void Identifier_Cannot_Start_With_Digit()
  9. {
  10. Assert.Throws<ExpressionParseException>(
  11. () => Parse("1Foo"));
  12. }
  13. [Fact]
  14. public void Identifier_Cannot_Start_With_Symbol()
  15. {
  16. Assert.Throws<ExpressionParseException>(
  17. () => Parse("Foo.%Bar"));
  18. }
  19. [Fact]
  20. public void Identifier_Cannot_Start_With_QuestionMark()
  21. {
  22. Assert.Throws<ExpressionParseException>(
  23. () => Parse("?Foo"));
  24. }
  25. [Fact]
  26. public void Identifier_Cannot_Start_With_NullConditional()
  27. {
  28. Assert.Throws<ExpressionParseException>(
  29. () => Parse("?.Foo"));
  30. }
  31. [Fact]
  32. public void Expression_Cannot_End_With_Period()
  33. {
  34. Assert.Throws<ExpressionParseException>(
  35. () => Parse("Foo.Bar."));
  36. }
  37. [Fact]
  38. public void Expression_Cannot_End_With_QuestionMark()
  39. {
  40. Assert.Throws<ExpressionParseException>(
  41. () => Parse("Foo.Bar?"));
  42. }
  43. [Fact]
  44. public void Expression_Cannot_End_With_Null_Conditional()
  45. {
  46. Assert.Throws<ExpressionParseException>(
  47. () => Parse("Foo.Bar?."));
  48. }
  49. [Fact]
  50. public void Expression_Cannot_Start_With_Period_Then_Token()
  51. {
  52. Assert.Throws<ExpressionParseException>(
  53. () => Parse(".Bar"));
  54. }
  55. [Fact]
  56. public void Expression_Cannot_Have_Empty_Indexer()
  57. {
  58. Assert.Throws<ExpressionParseException>(
  59. () => Parse("Foo.Bar[]"));
  60. }
  61. [Fact]
  62. public void Expression_Cannot_Have_Extra_Comma_At_Start_Of_Indexer()
  63. {
  64. Assert.Throws<ExpressionParseException>(
  65. () => Parse("Foo.Bar[,3,4]"));
  66. }
  67. [Fact]
  68. public void Expression_Cannot_Have_Extra_Comma_In_Indexer()
  69. {
  70. Assert.Throws<ExpressionParseException>(
  71. () => Parse("Foo.Bar[3,,4]"));
  72. }
  73. [Fact]
  74. public void Expression_Cannot_Have_Extra_Comma_At_End_Of_Indexer()
  75. {
  76. Assert.Throws<ExpressionParseException>(
  77. () => Parse("Foo.Bar[3,4,]"));
  78. }
  79. [Fact]
  80. public void Expression_Cannot_Have_Digit_After_Indexer()
  81. {
  82. Assert.Throws<ExpressionParseException>(
  83. () => Parse("Foo.Bar[3,4]5"));
  84. }
  85. [Fact]
  86. public void Expression_Cannot_Have_Letter_After_Indexer()
  87. {
  88. Assert.Throws<ExpressionParseException>(
  89. () => Parse("Foo.Bar[3,4]A"));
  90. }
  91. }
  92. }