//! > Test empty traits and impls.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
trait Foo<T>;
impl FooImpl<S> of Foo<S> {}
//! > top_level_kind
ModuleItemList
//! > ignored_kinds
FunctionWithBody
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: ModuleItemList
├── child #0 (kind: ItemTrait)
│ ├── attributes (kind: AttributeList) []
│ ├── visibility (kind: VisibilityDefault) []
│ ├── trait_kw (kind: TokenTrait): 'trait'
│ ├── name (kind: TokenIdentifier): 'Foo'
│ ├── generic_params (kind: WrappedGenericParamList)
│ │ ├── langle (kind: TokenLT): '<'
│ │ ├── generic_params (kind: GenericParamList)
│ │ │ └── item #0 (kind: GenericParamType)
│ │ │ └── name (kind: TokenIdentifier): 'T'
│ │ └── rangle (kind: TokenGT): '>'
│ └── body (kind: TokenSemicolon): ';'
└── child #1 (kind: ItemImpl)
├── attributes (kind: AttributeList) []
├── visibility (kind: VisibilityDefault) []
├── impl_kw (kind: TokenImpl): 'impl'
├── name (kind: TokenIdentifier): 'FooImpl'
├── generic_params (kind: WrappedGenericParamList)
│ ├── langle (kind: TokenLT): '<'
│ ├── generic_params (kind: GenericParamList)
│ │ └── item #0 (kind: GenericParamType)
│ │ └── name (kind: TokenIdentifier): 'S'
│ └── rangle (kind: TokenGT): '>'
├── of_kw (kind: TokenOf): 'of'
├── trait_path (kind: ExprPath)
│ └── item #0 (kind: PathSegmentWithGenericArgs)
│ ├── ident (kind: TokenIdentifier): 'Foo'
│ ├── separator (kind: OptionTerminalColonColonEmpty) []
│ └── generic_args (kind: GenericArgs)
│ ├── langle (kind: TokenLT): '<'
│ ├── generic_args (kind: GenericArgList)
│ │ └── item #0 (kind: GenericArgUnnamed)
│ │ └── value (kind: GenericArgValueExpr)
│ │ └── expr (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'S'
│ └── rangle (kind: TokenGT): '>'
└── body (kind: ImplBody)
├── lbrace (kind: TokenLBrace): '{'
├── items (kind: ImplItemList) []
└── rbrace (kind: TokenRBrace): '}'
//! > ==========================================================================
//! > Test nonempty traits and impls.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
trait Foo<T> {
fn foo<S>(x: T, y: S);
}
#[cairofmt::skip]
impl FooImpl<W> of Foo::<u8> {
fn foo<W>(x: u8, y: W) {
}
}
//! > top_level_kind
ModuleItemList
//! > ignored_kinds
FunctionDeclaration
FunctionWithBody
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: ModuleItemList
├── child #0 (kind: ItemTrait)
│ ├── attributes (kind: AttributeList) []
│ ├── visibility (kind: VisibilityDefault) []
│ ├── trait_kw (kind: TokenTrait): 'trait'
│ ├── name (kind: TokenIdentifier): 'Foo'
│ ├── generic_params (kind: WrappedGenericParamList)
│ │ ├── langle (kind: TokenLT): '<'
│ │ ├── generic_params (kind: GenericParamList)
│ │ │ └── item #0 (kind: GenericParamType)
│ │ │ └── name (kind: TokenIdentifier): 'T'
│ │ └── rangle (kind: TokenGT): '>'
│ └── body (kind: TraitBody)
│ ├── lbrace (kind: TokenLBrace): '{'
│ ├── items (kind: TraitItemList)
│ │ └── child #0 (kind: TraitItemFunction)
│ │ ├── attributes (kind: AttributeList) []
│ │ ├── declaration (kind: FunctionDeclaration) <ignored>
│ │ └── body (kind: TokenSemicolon): ';'
│ └── rbrace (kind: TokenRBrace): '}'
└── child #1 (kind: ItemImpl)
├── attributes (kind: AttributeList)
│ └── child #0 (kind: Attribute)
│ ├── hash (kind: TokenHash): '#'
│ ├── lbrack (kind: TokenLBrack): '['
│ ├── attr (kind: ExprPath)
│ │ ├── item #0 (kind: PathSegmentSimple)
│ │ │ └── ident (kind: TokenIdentifier): 'cairofmt'
│ │ ├── separator #0 (kind: TokenColonColon): '::'
│ │ └── item #1 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'skip'
│ ├── arguments (kind: OptionArgListParenthesizedEmpty) []
│ └── rbrack (kind: TokenRBrack): ']'
├── visibility (kind: VisibilityDefault) []
├── impl_kw (kind: TokenImpl): 'impl'
├── name (kind: TokenIdentifier): 'FooImpl'
├── generic_params (kind: WrappedGenericParamList)
│ ├── langle (kind: TokenLT): '<'
│ ├── generic_params (kind: GenericParamList)
│ │ └── item #0 (kind: GenericParamType)
│ │ └── name (kind: TokenIdentifier): 'W'
│ └── rangle (kind: TokenGT): '>'
├── of_kw (kind: TokenOf): 'of'
├── trait_path (kind: ExprPath)
│ └── item #0 (kind: PathSegmentWithGenericArgs)
│ ├── ident (kind: TokenIdentifier): 'Foo'
│ ├── separator (kind: TokenColonColon): '::'
│ └── generic_args (kind: GenericArgs)
│ ├── langle (kind: TokenLT): '<'
│ ├── generic_args (kind: GenericArgList)
│ │ └── item #0 (kind: GenericArgUnnamed)
│ │ └── value (kind: GenericArgValueExpr)
│ │ └── expr (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'u8'
│ └── rangle (kind: TokenGT): '>'
└── body (kind: ImplBody)
├── lbrace (kind: TokenLBrace): '{'
├── items (kind: ImplItemList)
│ └── child #0 (kind: FunctionWithBody) <ignored>
└── rbrace (kind: TokenRBrace): '}'
//! > ==========================================================================
//! > Test trait function with "accidental" body in a module - later items should still be in the module.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
mod x {
trait A {
fn foo() {}
}
struct Y {}
}
//! > top_level_kind
SyntaxFile
//! > ignored_kinds
FunctionDeclaration
ItemStruct
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: SyntaxFile
├── items (kind: ModuleItemList)
│ └── child #0 (kind: ItemModule)
│ ├── attributes (kind: AttributeList) []
│ ├── visibility (kind: VisibilityDefault) []
│ ├── module_kw (kind: TokenModule): 'mod'
│ ├── name (kind: TokenIdentifier): 'x'
│ └── body (kind: ModuleBody)
│ ├── lbrace (kind: TokenLBrace): '{'
│ ├── items (kind: ModuleItemList)
│ │ ├── child #0 (kind: ItemTrait)
│ │ │ ├── attributes (kind: AttributeList) []
│ │ │ ├── visibility (kind: VisibilityDefault) []
│ │ │ ├── trait_kw (kind: TokenTrait): 'trait'
│ │ │ ├── name (kind: TokenIdentifier): 'A'
│ │ │ ├── generic_params (kind: OptionWrappedGenericParamListEmpty) []
│ │ │ └── body (kind: TraitBody)
│ │ │ ├── lbrace (kind: TokenLBrace): '{'
│ │ │ ├── items (kind: TraitItemList)
│ │ │ │ └── child #0 (kind: TraitItemFunction)
│ │ │ │ ├── attributes (kind: AttributeList) []
│ │ │ │ ├── declaration (kind: FunctionDeclaration) <ignored>
│ │ │ │ └── body (kind: ExprBlock)
│ │ │ │ ├── lbrace (kind: TokenLBrace): '{'
│ │ │ │ ├── statements (kind: StatementList) []
│ │ │ │ └── rbrace (kind: TokenRBrace): '}'
│ │ │ └── rbrace (kind: TokenRBrace): '}'
│ │ └── child #1 (kind: ItemStruct) <ignored>
│ └── rbrace (kind: TokenRBrace): '}'
└── eof (kind: TokenEndOfFile).
//! > ==========================================================================
//! > Test type item in trait.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
trait MyTrait {
type MyType;
}
//! > top_level_kind
TraitBody
//! > ignored_kinds
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: TraitBody
├── lbrace (kind: TokenLBrace): '{'
├── items (kind: TraitItemList)
│ └── child #0 (kind: TraitItemType)
│ ├── attributes (kind: AttributeList) []
│ ├── type_kw (kind: TokenType): 'type'
│ ├── name (kind: TokenIdentifier): 'MyType'
│ ├── generic_params (kind: OptionWrappedGenericParamListEmpty) []
│ └── semicolon (kind: TokenSemicolon): ';'
└── rbrace (kind: TokenRBrace): '}'
//! > ==========================================================================
//! > Test type item in impl.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
impl MyImpl of MyTrait {
type MyType = u32;
}
//! > top_level_kind
ImplBody
//! > ignored_kinds
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: ImplBody
├── lbrace (kind: TokenLBrace): '{'
├── items (kind: ImplItemList)
│ └── child #0 (kind: ItemTypeAlias)
│ ├── attributes (kind: AttributeList) []
│ ├── visibility (kind: VisibilityDefault) []
│ ├── type_kw (kind: TokenType): 'type'
│ ├── name (kind: TokenIdentifier): 'MyType'
│ ├── generic_params (kind: OptionWrappedGenericParamListEmpty) []
│ ├── eq (kind: TokenEq): '='
│ ├── ty (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'u32'
│ └── semicolon (kind: TokenSemicolon): ';'
└── rbrace (kind: TokenRBrace): '}'
//! > ==========================================================================
//! > Test type item with generic parameters in trait.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
trait MyTrait {
type MyType<T>;
}
//! > top_level_kind
TraitBody
//! > ignored_kinds
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: TraitBody
├── lbrace (kind: TokenLBrace): '{'
├── items (kind: TraitItemList)
│ └── child #0 (kind: TraitItemType)
│ ├── attributes (kind: AttributeList) []
│ ├── type_kw (kind: TokenType): 'type'
│ ├── name (kind: TokenIdentifier): 'MyType'
│ ├── generic_params (kind: WrappedGenericParamList)
│ │ ├── langle (kind: TokenLT): '<'
│ │ ├── generic_params (kind: GenericParamList)
│ │ │ └── item #0 (kind: GenericParamType)
│ │ │ └── name (kind: TokenIdentifier): 'T'
│ │ └── rangle (kind: TokenGT): '>'
│ └── semicolon (kind: TokenSemicolon): ';'
└── rbrace (kind: TokenRBrace): '}'
//! > ==========================================================================
//! > Test type item with generic parameters in impl.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
impl MyImpl of MyTrait {
type MyType<T> = Array<T>;
}
//! > top_level_kind
ImplBody
//! > ignored_kinds
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: ImplBody
├── lbrace (kind: TokenLBrace): '{'
├── items (kind: ImplItemList)
│ └── child #0 (kind: ItemTypeAlias)
│ ├── attributes (kind: AttributeList) []
│ ├── visibility (kind: VisibilityDefault) []
│ ├── type_kw (kind: TokenType): 'type'
│ ├── name (kind: TokenIdentifier): 'MyType'
│ ├── generic_params (kind: WrappedGenericParamList)
│ │ ├── langle (kind: TokenLT): '<'
│ │ ├── generic_params (kind: GenericParamList)
│ │ │ └── item #0 (kind: GenericParamType)
│ │ │ └── name (kind: TokenIdentifier): 'T'
│ │ └── rangle (kind: TokenGT): '>'
│ ├── eq (kind: TokenEq): '='
│ ├── ty (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentWithGenericArgs)
│ │ ├── ident (kind: TokenIdentifier): 'Array'
│ │ ├── separator (kind: OptionTerminalColonColonEmpty) []
│ │ └── generic_args (kind: GenericArgs)
│ │ ├── langle (kind: TokenLT): '<'
│ │ ├── generic_args (kind: GenericArgList)
│ │ │ └── item #0 (kind: GenericArgUnnamed)
│ │ │ └── value (kind: GenericArgValueExpr)
│ │ │ └── expr (kind: ExprPath)
│ │ │ └── item #0 (kind: PathSegmentSimple)
│ │ │ └── ident (kind: TokenIdentifier): 'T'
│ │ └── rangle (kind: TokenGT): '>'
│ └── semicolon (kind: TokenSemicolon): ';'
└── rbrace (kind: TokenRBrace): '}'
//! > ==========================================================================
//! > Test const item in trait.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
trait MyTrait {
const MyConst: u32;
}
//! > top_level_kind
TraitBody
//! > ignored_kinds
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: TraitBody
├── lbrace (kind: TokenLBrace): '{'
├── items (kind: TraitItemList)
│ └── child #0 (kind: TraitItemConstant)
│ ├── attributes (kind: AttributeList) []
│ ├── const_kw (kind: TokenConst): 'const'
│ ├── name (kind: TokenIdentifier): 'MyConst'
│ ├── type_clause (kind: TypeClause)
│ │ ├── colon (kind: TokenColon): ':'
│ │ └── ty (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'u32'
│ └── semicolon (kind: TokenSemicolon): ';'
└── rbrace (kind: TokenRBrace): '}'
//! > ==========================================================================
//! > Test const item in impl.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
impl MyImpl of MyTrait {
const MyConst: u32 = 3;
}
//! > top_level_kind
ImplBody
//! > ignored_kinds
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: ImplBody
├── lbrace (kind: TokenLBrace): '{'
├── items (kind: ImplItemList)
│ └── child #0 (kind: ItemConstant)
│ ├── attributes (kind: AttributeList) []
│ ├── visibility (kind: VisibilityDefault) []
│ ├── const_kw (kind: TokenConst): 'const'
│ ├── name (kind: TokenIdentifier): 'MyConst'
│ ├── type_clause (kind: TypeClause)
│ │ ├── colon (kind: TokenColon): ':'
│ │ └── ty (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'u32'
│ ├── eq (kind: TokenEq): '='
│ ├── value (kind: TokenLiteralNumber): '3'
│ └── semicolon (kind: TokenSemicolon): ';'
└── rbrace (kind: TokenRBrace): '}'
//! > ==========================================================================
//! > Test impl item in trait.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
trait MyTrait {
impl MyImpl: OtherTrait;
}
//! > top_level_kind
TraitBody
//! > ignored_kinds
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: TraitBody
├── lbrace (kind: TokenLBrace): '{'
├── items (kind: TraitItemList)
│ └── child #0 (kind: TraitItemImpl)
│ ├── attributes (kind: AttributeList) []
│ ├── impl_kw (kind: TokenImpl): 'impl'
│ ├── name (kind: TokenIdentifier): 'MyImpl'
│ ├── colon (kind: TokenColon): ':'
│ ├── trait_path (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'OtherTrait'
│ └── semicolon (kind: TokenSemicolon): ';'
└── rbrace (kind: TokenRBrace): '}'
//! > ==========================================================================
//! > Test impl item in impl.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
impl MyImpl of MyTrait {
impl OtherImpl = AnotherImpl;
}
//! > top_level_kind
ImplBody
//! > ignored_kinds
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: ImplBody
├── lbrace (kind: TokenLBrace): '{'
├── items (kind: ImplItemList)
│ └── child #0 (kind: ItemImplAlias)
│ ├── attributes (kind: AttributeList) []
│ ├── visibility (kind: VisibilityDefault) []
│ ├── impl_kw (kind: TokenImpl): 'impl'
│ ├── name (kind: TokenIdentifier): 'OtherImpl'
│ ├── generic_params (kind: OptionWrappedGenericParamListEmpty) []
│ ├── eq (kind: TokenEq): '='
│ ├── impl_path (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'AnotherImpl'
│ └── semicolon (kind: TokenSemicolon): ';'
└── rbrace (kind: TokenRBrace): '}'