-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* expose internal parser in pkg Signed-off-by: Joffref <mariusjoffre@gmail.com> * Resolve comments Signed-off-by: Joffref <mariusjoffre@gmail.com> --------- Signed-off-by: Joffref <mariusjoffre@gmail.com>
- Loading branch information
Showing
12 changed files
with
108 additions
and
37 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
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
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
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,12 @@ | ||
package parser | ||
|
||
import ( | ||
"github.com/Joffref/genz/internal/utils" | ||
"golang.org/x/tools/go/packages" | ||
) | ||
|
||
// LoadPackage is a helper to load a package | ||
// Note: patterns is a list of patterns to match packages (e.g . ; ./... ; github.com/Joffref/genz/...) | ||
func LoadPackage(patterns []string, buildTags ...string) *packages.Package { | ||
return utils.LoadPackage(patterns, buildTags) | ||
} |
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,13 @@ | ||
package parser | ||
|
||
import ( | ||
"github.com/Joffref/genz/internal/parser" | ||
"github.com/Joffref/genz/pkg/models" | ||
"golang.org/x/tools/go/packages" | ||
) | ||
|
||
// Parse returns a models.ParsedElement from the given *packages.Package and type name. | ||
// It's the main entry point for the different underlying parsers (struct, interface, etc). | ||
func Parse(pkg *packages.Package, typeName string) (models.ParsedElement, error) { | ||
return parser.Parse(pkg, typeName) | ||
} |
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,19 @@ | ||
package testutils | ||
|
||
import ( | ||
"github.com/Joffref/genz/internal/parser" | ||
"github.com/Joffref/genz/internal/testutils" | ||
"github.com/Joffref/genz/pkg/models" | ||
"testing" | ||
) | ||
|
||
// ParseElement parses the given code looking for type and returns the parsed element | ||
// If it fails, it fails the test | ||
func ParseElement(t *testing.T, code string, typeName string) models.ParsedElement { | ||
p := testutils.CreatePkgWithCode(t, code) | ||
element, err := parser.Parse(p, typeName) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
return element | ||
} |