-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: 🍺 Support for
BreakStmt
(#174)
* 🐳 added support * 🐳 added support
- Loading branch information
1 parent
d6d1f4d
commit d8bbf0c
Showing
7 changed files
with
157 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package java | ||
|
||
import ( | ||
"github.com/shivasurya/code-pathfinder/sourcecode-parser/model" | ||
sitter "github.com/smacker/go-tree-sitter" | ||
) | ||
|
||
func ParseBreakStatement(node *sitter.Node, sourcecode []byte) *model.BreakStmt { | ||
breakStmt := &model.BreakStmt{} | ||
// get identifier if present child | ||
for i := 0; i < int(node.ChildCount()); i++ { | ||
if node.Child(i).Type() == "identifier" { | ||
breakStmt.Label = node.Child(i).Content(sourcecode) | ||
} | ||
} | ||
return breakStmt | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package java | ||
|
||
import ( | ||
"github.com/smacker/go-tree-sitter/java" | ||
"testing" | ||
|
||
"github.com/shivasurya/code-pathfinder/sourcecode-parser/model" | ||
sitter "github.com/smacker/go-tree-sitter" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseBreakStatement(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
expected *model.BreakStmt | ||
}{ | ||
{ | ||
name: "Simple break statement without label", | ||
input: "break;", | ||
expected: &model.BreakStmt{Label: ""}, | ||
}, | ||
{ | ||
name: "Break statement with label", | ||
input: "break myLabel;", | ||
expected: &model.BreakStmt{Label: "myLabel"}, | ||
}, | ||
} | ||
|
||
parser := sitter.NewParser() | ||
parser.SetLanguage(java.GetLanguage()) | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tree := parser.Parse(nil, []byte(tt.input)) | ||
node := tree.RootNode().Child(0) | ||
result := ParseBreakStatement(node, []byte(tt.input)) | ||
assert.Equal(t, tt.expected, result) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters