Documentation
¶
Overview ¶
Package dotnetast provides shared C# AST traversal utilities for .NET test framework parsers.
Index ¶
- Constants
- func ExtractStringContent(node *sitter.Node, source []byte) string
- func FindAttributeArgumentList(attr *sitter.Node) *sitter.Node
- func GetAttributeLists(node *sitter.Node) []*sitter.Node
- func GetAttributeName(attribute *sitter.Node, source []byte) string
- func GetAttributes(attributeLists []*sitter.Node) []*sitter.Node
- func GetClassName(node *sitter.Node, source []byte) string
- func GetDeclarationList(node *sitter.Node) *sitter.Node
- func GetMethodName(node *sitter.Node, source []byte) string
- func HasAttribute(attributeLists []*sitter.Node, source []byte, attributeName string) bool
- func IsCSharpTestFileName(filename string) bool
- func ParseAssignmentExpression(argNode *sitter.Node, source []byte) (string, string)
Constants ¶
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 ¶
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 ¶
FindAttributeArgumentList finds the attribute_argument_list child of an attribute node. Used by xUnit, NUnit, and other .NET framework parsers.
func GetAttributeLists ¶
GetAttributeLists returns all attribute_list nodes preceding a declaration.
func GetAttributeName ¶
GetAttributeName extracts the attribute name (e.g., "Fact" from [Fact] or "Theory" from [Theory]). Handles both simple identifiers and qualified names.
func GetAttributes ¶
GetAttributes extracts all attribute nodes from attribute_list nodes.
func GetClassName ¶
GetClassName extracts the class name from a class_declaration node.
func GetDeclarationList ¶
GetDeclarationList returns the body (declaration_list) from a class_declaration.
func GetMethodName ¶
GetMethodName extracts the method name from a method_declaration node.
func HasAttribute ¶
HasAttribute checks if the attribute lists contain a specific attribute.
func IsCSharpTestFileName ¶
IsCSharpTestFileName checks if a filename follows C# test file naming conventions. Matches: *Test.cs, *Tests.cs, Test*.cs, *Spec.cs, *Specs.cs
func ParseAssignmentExpression ¶
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.