dotnetast

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package dotnetast provides shared C# AST traversal utilities for .NET test framework parsers.

Index

Constants

View Source
const (
	NodeClassDeclaration      = "class_declaration"
	NodeMethodDeclaration     = "method_declaration"
	NodeAttributeList         = "attribute_list"
	NodeAttribute             = "attribute"
	NodeAttributeArgumentList = "attribute_argument_list"
	NodeAttributeArgument     = "attribute_argument"
	NodeIdentifier            = "identifier"
	NodeDeclarationList       = "declaration_list"
	NodeStringLiteral         = "string_literal"
	NodeVerbatimStringLiteral = "verbatim_string_literal"
	NodeStringLiteralContent  = "string_literal_content"
	NodeInterpolatedString    = "interpolated_string_expression"
	NodeNamespaceDeclaration  = "namespace_declaration"
	NodeFileScopedNamespace   = "file_scoped_namespace_declaration"
	NodeUsingDirective        = "using_directive"
	NodeQualifiedName         = "qualified_name"
	NodeModifier              = "modifier"
	NodeGenericName           = "generic_name"
	NodeAssignmentExpression  = "assignment_expression"
)

C# AST node types.

Variables

This section is empty.

Functions

func ExtractStringContent

func ExtractStringContent(node *sitter.Node, source []byte) string

ExtractStringContent extracts string content from various string literal node types. Supports regular string literals ("..."), verbatim strings (@"..."), and interpolated strings ($"..."). This is exported for reuse by xUnit, NUnit, MSTest, and other .NET framework parsers.

func FindAttributeArgumentList

func FindAttributeArgumentList(attr *sitter.Node) *sitter.Node

FindAttributeArgumentList finds the attribute_argument_list child of an attribute node. Used by xUnit, NUnit, and other .NET framework parsers.

func GetAttributeArgument

func GetAttributeArgument(attribute *sitter.Node, source []byte) string

GetAttributeArgument extracts the first string argument from an attribute. For [InlineData("test")], returns "test".

func GetAttributeLists

func GetAttributeLists(node *sitter.Node) []*sitter.Node

GetAttributeLists returns all attribute_list nodes preceding a declaration.

func GetAttributeName

func GetAttributeName(attribute *sitter.Node, source []byte) string

GetAttributeName extracts the attribute name (e.g., "Fact" from [Fact] or "Theory" from [Theory]). Handles both simple identifiers and qualified names.

func GetAttributes

func GetAttributes(attributeLists []*sitter.Node) []*sitter.Node

GetAttributes extracts all attribute nodes from attribute_list nodes.

func GetClassName

func GetClassName(node *sitter.Node, source []byte) string

GetClassName extracts the class name from a class_declaration node.

func GetDeclarationList

func GetDeclarationList(node *sitter.Node) *sitter.Node

GetDeclarationList returns the body (declaration_list) from a class_declaration.

func GetMethodName

func GetMethodName(node *sitter.Node, source []byte) string

GetMethodName extracts the method name from a method_declaration node.

func HasAttribute

func HasAttribute(attributeLists []*sitter.Node, source []byte, attributeName string) bool

HasAttribute checks if the attribute lists contain a specific attribute.

func IsCSharpTestFileName

func IsCSharpTestFileName(filename string) bool

IsCSharpTestFileName checks if a filename follows C# test file naming conventions. Matches: *Test.cs, *Tests.cs, Test*.cs, *Spec.cs, *Specs.cs

func IsPublicMethod

func IsPublicMethod(node *sitter.Node, source []byte) bool

IsPublicMethod checks if a method has the public modifier.

func ParseAssignmentExpression

func ParseAssignmentExpression(argNode *sitter.Node, source []byte) (string, string)

ParseAssignmentExpression extracts name and value from an assignment_expression node. For "Skip = \"reason\"", returns ("Skip", "reason"). Used by xUnit (Skip, DisplayName), NUnit (Description), and other .NET framework parsers.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL