-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
add support for time.Time
#25
add support for time.Time
#25
Conversation
Thanks for sending @michaellzc - I'd be happy to merge this. I can offer a few options:
I'll let you decide which one you want to go for depending on how much time you want to spend here. |
😛 I need // an exported func from autogold
func TimePtr(t time.Time) *time.Time {
return &t
}
// render as
autogold.TimePtr(time.Date(...))
it's not elegant, but we can avoid breaking backward compatibility unless we have to. |
@michaellzc I'm not a fan of that |
nice, let's do the |
d12b5d9
to
60af2cf
Compare
60af2cf
to
e44ce5a
Compare
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## main #25 +/- ##
==========================================
+ Coverage 74.36% 75.38% +1.02%
==========================================
Files 6 7 +1
Lines 745 780 +35
==========================================
+ Hits 554 588 +34
- Misses 144 145 +1
Partials 47 47
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@michaellzc not sure if you'd be up for it (fine if not) but maybe you could remove Lines 151 to 167 in 5de3f44
No worries if not, just let me know what you decide & I'll merge either way. |
AST: &ast.TypeAssertExpr{ | ||
X: &ast.CallExpr{ | ||
Fun: &ast.SelectorExpr{ | ||
X: ast.NewIdent("valast"), | ||
Sel: ast.NewIdent("Addr"), | ||
}, | ||
Args: []ast.Expr{elem.AST}, | ||
AST: &ast.CallExpr{ | ||
Fun: &ast.SelectorExpr{ | ||
X: ast.NewIdent("valast"), | ||
Sel: ast.NewIdent("Ptr"), | ||
}, | ||
Type: ptrType.AST, | ||
Args: []ast.Expr{elem.AST}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
AST: &ast.TypeAssertExpr{ | ||
X: &ast.CallExpr{ | ||
Fun: &ast.SelectorExpr{ | ||
X: ast.NewIdent("valast"), | ||
Sel: ast.NewIdent("Addr"), | ||
}, | ||
Args: []ast.Expr{elem.AST}, | ||
AST: &ast.CallExpr{ | ||
Fun: &ast.SelectorExpr{ | ||
X: ast.NewIdent("valast"), | ||
Sel: ast.NewIdent("Ptr"), | ||
}, | ||
Type: ptrType.AST, | ||
Args: []ast.Expr{elem.AST}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
refactor from Trying to understand what is going in |
possible solution for future reference: // It doesn't work for all cases yet
func InterfacePtr[V any, I any](v *V, pointerToType *I) *I {
sliceType := reflect.SliceOf(reflect.TypeOf(pointerToType).Elem())
slice := reflect.MakeSlice(sliceType, 1, 1)
if v != nil {
slice.Index(0).Set(reflect.ValueOf(v))
}
return slice.Index(0).Addr().Interface().(*I)
} I may find some existing problems with
// input
v := test.Bazer(test.NewBaz())
&v
// output
valast.AddrInterface(test.Bazer{&test.Baz{
Bam: (1.34 + 0i),
zeta: &test.foo{bar: "hello"},
}},
(*test.Bazer)(nil)).(*test.Bazer) I don't think you can do |
related #11
TODO
*time.Time
I am not sure what is the best way to render
*time.Time
:✅ generic (
this is not supported given the current target Go version is 1.15 in)go.mod
❌ inline anonymous fn
thoughts?
Test plan
all tests passed
Tested this change with workspace in https://github.com/sourcegraph/controller, and it seems to work just fine. It was able to automatically wrap
*time.Time
toPtr(time.Date())
and valast pkg was imported properly in_test.go
file as well.