public void TestCanAccessNonExistentProperty() { var propertyAccessor = LightupHelpers.CreateSyntaxPropertyAccessor <SyntaxNode, object>(typeof(SyntaxNode), "NonExistentProperty"); Assert.NotNull(propertyAccessor); Assert.Null(propertyAccessor(SyntaxFactory.AccessorList())); Assert.Throws <NullReferenceException>(() => propertyAccessor(null)); var withPropertyAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor <SyntaxNode, object>(typeof(SyntaxNode), "NonExistentProperty"); Assert.NotNull(withPropertyAccessor); Assert.NotNull(withPropertyAccessor(SyntaxFactory.AccessorList(), null)); Assert.ThrowsAny <NotSupportedException>(() => withPropertyAccessor(SyntaxFactory.AccessorList(), new object())); Assert.Throws <NullReferenceException>(() => withPropertyAccessor(null, new object())); var separatedListPropertyAccessor = LightupHelpers.CreateSeparatedSyntaxListPropertyAccessor <SyntaxNode, SyntaxNode>(typeof(SyntaxNode), "NonExistentProperty"); Assert.NotNull(separatedListPropertyAccessor); Assert.NotNull(separatedListPropertyAccessor(SyntaxFactory.AccessorList())); Assert.Throws <NullReferenceException>(() => separatedListPropertyAccessor(null)); var separatedListWithPropertyAccessor = LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor <SyntaxNode, SyntaxNode>(typeof(SyntaxNode), "NonExistentProperty"); Assert.NotNull(separatedListWithPropertyAccessor); Assert.NotNull(separatedListWithPropertyAccessor(SyntaxFactory.AccessorList(), null)); Assert.ThrowsAny <NotSupportedException>(() => separatedListWithPropertyAccessor(SyntaxFactory.AccessorList(), new SeparatedSyntaxListWrapper <SyntaxNode> .AutoWrapSeparatedSyntaxList <LiteralExpressionSyntax>(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression))))); Assert.Throws <NullReferenceException>(() => separatedListWithPropertyAccessor(null, SeparatedSyntaxListWrapper <SyntaxNode> .UnsupportedEmpty)); }
public void TestCreateSeparatedSyntaxListWithPropertyAccessor() { // The call works for `SeparatedSyntaxList<T>`, not work for `SyntaxList<T>`. Assert.ThrowsAny <InvalidOperationException>(() => LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor <BlockSyntax, StatementSyntax>(typeof(BlockSyntax), nameof(BlockSyntax.Statements))); // The call *should* have been made with the first generic argument set to `BaseParameterListSyntax` // instead of `ParameterListSyntax`. Assert.ThrowsAny <InvalidOperationException>(() => LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor <ParameterListSyntax, ParameterSyntax>(typeof(BaseParameterListSyntax), nameof(BaseParameterListSyntax.Parameters))); }
public void TestCreateSeparatedSyntaxListWithPropertyAccessorValidateElementType() { // The call *should* have been made with the second generic argument set to `ParameterSyntax` // instead of `ArgumentSyntax`. Assert.ThrowsAny <InvalidOperationException>(() => LightupHelpers.CreateSeparatedSyntaxListWithPropertyAccessor <BaseParameterListSyntax, ArgumentSyntax>(typeof(BaseParameterListSyntax), nameof(BaseParameterListSyntax.Parameters))); }