Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rubysrc2cpg] Added wsOrNl* before and after parameters #3354

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ methodOnlyIdentifier
;

methodParameterPart
: LPAREN parameters? RPAREN
: LPAREN wsOrNl* parameters? wsOrNl* RPAREN
| parameters?
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,186 @@ class MethodDefinitionTests extends RubyParserAbstractTest {
| Separator
| end""".stripMargin
}

"have correct structure when a method parameter is defined using whitespace" in {
val code =
"""
|class SampleClass
| def sample_method( first_param:, second_param:)
| end
|end
|""".stripMargin

printAst(_.primary(), code) shouldBe
"""ClassDefinitionPrimary
| ClassDefinition
| class
| WsOrNl
| ClassOrModuleReference
| SampleClass
| Separators
| Separator
| WsOrNl
| BodyStatement
| CompoundStatement
| Statements
| ExpressionOrCommandStatement
| ExpressionExpressionOrCommand
| PrimaryExpression
| MethodDefinitionPrimary
| MethodDefinition
| def
| WsOrNl
| SimpleMethodNamePart
| DefinedMethodName
| MethodName
| MethodIdentifier
| sample_method
| MethodParameterPart
| (
| WsOrNl
| Parameters
| Parameter
| KeywordParameter
| first_param
| :
| ,
| WsOrNl
| Parameter
| KeywordParameter
| second_param
| :
| )
| Separator
| WsOrNl
| BodyStatement
| CompoundStatement
| end
| Separators
| Separator
| end""".stripMargin
}

"have correct structure when method parameters are defined using new line" in {
val code =
"""
|class SomeClass
| def initialize(
| name, age)
| end
|end
|""".stripMargin

printAst(_.primary(), code) shouldBe
"""ClassDefinitionPrimary
| ClassDefinition
| class
| WsOrNl
| ClassOrModuleReference
| SomeClass
| Separators
| Separator
| WsOrNl
| BodyStatement
| CompoundStatement
| Statements
| ExpressionOrCommandStatement
| ExpressionExpressionOrCommand
| PrimaryExpression
| MethodDefinitionPrimary
| MethodDefinition
| def
| WsOrNl
| SimpleMethodNamePart
| DefinedMethodName
| MethodName
| MethodIdentifier
| initialize
| MethodParameterPart
| (
| WsOrNl
| WsOrNl
| Parameters
| Parameter
| MandatoryParameter
| name
| ,
| WsOrNl
| Parameter
| MandatoryParameter
| age
| )
| Separator
| WsOrNl
| BodyStatement
| CompoundStatement
| end
| Separators
| Separator
| end""".stripMargin
}

"have correct structure when method parameters are defined using wsOrNL" in {
val code =
"""
|class SomeClass
| def initialize(
| name, age
| )
| end
|end
|""".stripMargin

printAst(_.primary(), code) shouldBe
"""ClassDefinitionPrimary
| ClassDefinition
| class
| WsOrNl
| ClassOrModuleReference
| SomeClass
| Separators
| Separator
| WsOrNl
| BodyStatement
| CompoundStatement
| Statements
| ExpressionOrCommandStatement
| ExpressionExpressionOrCommand
| PrimaryExpression
| MethodDefinitionPrimary
| MethodDefinition
| def
| WsOrNl
| SimpleMethodNamePart
| DefinedMethodName
| MethodName
| MethodIdentifier
| initialize
| MethodParameterPart
| (
| WsOrNl
| WsOrNl
| Parameters
| Parameter
| MandatoryParameter
| name
| ,
| WsOrNl
| Parameter
| MandatoryParameter
| age
| WsOrNl
| WsOrNl
| )
| Separator
| WsOrNl
| BodyStatement
| CompoundStatement
| end
| Separators
| Separator
| end""".stripMargin
}
}

}
Loading