-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
builtin: add oct built-in function #2835
Changes from all commits
a5a6b32
d7ef1ce
3165971
2fd3d99
2dee81c
1e300f8
34181b8
26a42b5
2c49555
5d1c77a
627bdfc
bf4e5ea
35cb8f7
7f70545
30fbc1d
d59a42b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1009,3 +1009,48 @@ func (s *testEvaluatorSuite) TestMakeSet(c *C) { | |
c.Assert(r, testutil.DatumEquals, types.NewDatum(t.ret)) | ||
} | ||
} | ||
|
||
func (s *testEvaluatorSuite) TestOct(c *C) { | ||
defer testleak.AfterTest(c)() | ||
octCases := []struct { | ||
origin interface{} | ||
ret string | ||
}{ | ||
{"-2.7", "1777777777777777777776"}, | ||
{-1.5, "1777777777777777777777"}, | ||
{-1, "1777777777777777777777"}, | ||
{"0", "0"}, | ||
{"1", "1"}, | ||
{"8", "10"}, | ||
{"12", "14"}, | ||
{"20", "24"}, | ||
{"100", "144"}, | ||
{"1024", "2000"}, | ||
{"2048", "4000"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add cases for different origin types like integer and float. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, add some negative numbers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a string that is larger than max uint64. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
{1.0, "1"}, | ||
{9.5, "11"}, | ||
{13, "15"}, | ||
{1025, "2001"}, | ||
{"8a8", "10"}, | ||
{"abc", "0"}, | ||
//overflow uint64 | ||
{"9999999999999999999999999", "1777777777777777777777"}, | ||
{"-9999999999999999999999999", "1777777777777777777777"}, | ||
} | ||
fc := funcs[ast.Oct] | ||
for _, test := range octCases { | ||
in := types.NewDatum(test.origin) | ||
f, _ := fc.getFunction(datumsToConstants([]types.Datum{in}), s.ctx) | ||
r, err := f.eval(nil) | ||
c.Assert(err, IsNil) | ||
res, err := r.ToString() | ||
c.Assert(err, IsNil) | ||
c.Assert(res, Equals, test.ret) | ||
} | ||
// test NULL input for sha | ||
var argNull types.Datum | ||
f, _ := fc.getFunction(datumsToConstants([]types.Datum{argNull}), s.ctx) | ||
r, err := f.eval(nil) | ||
c.Assert(err, IsNil) | ||
c.Assert(r.IsNull(), IsTrue) | ||
} |
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.
The error is discarded.