repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
jung-kurt/gofpdf | template_impl.go | ID | func (t *FpdfTpl) ID() string {
return fmt.Sprintf("%x", sha1.Sum(t.Bytes()))
} | go | func (t *FpdfTpl) ID() string {
return fmt.Sprintf("%x", sha1.Sum(t.Bytes()))
} | [
"func",
"(",
"t",
"*",
"FpdfTpl",
")",
"ID",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sha1",
".",
"Sum",
"(",
"t",
".",
"Bytes",
"(",
")",
")",
")",
"\n",
"}"
] | // ID returns the global template identifier | [
"ID",
"returns",
"the",
"global",
"template",
"identifier"
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template_impl.go#L67-L69 | train |
jung-kurt/gofpdf | template_impl.go | Size | func (t *FpdfTpl) Size() (corner PointType, size SizeType) {
return t.corner, t.size
} | go | func (t *FpdfTpl) Size() (corner PointType, size SizeType) {
return t.corner, t.size
} | [
"func",
"(",
"t",
"*",
"FpdfTpl",
")",
"Size",
"(",
")",
"(",
"corner",
"PointType",
",",
"size",
"SizeType",
")",
"{",
"return",
"t",
".",
"corner",
",",
"t",
".",
"size",
"\n",
"}"
] | // Size gives the bounding dimensions of this template | [
"Size",
"gives",
"the",
"bounding",
"dimensions",
"of",
"this",
"template"
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template_impl.go#L72-L74 | train |
jung-kurt/gofpdf | template_impl.go | FromPage | func (t *FpdfTpl) FromPage(page int) (Template, error) {
// pages start at 1
if page == 0 {
return nil, errors.New("Pages start at 1 No template will have a page 0")
}
if page > t.NumPages() {
return nil, fmt.Errorf("The template does not have a page %d", page)
}
// if it is already pointing to the correct page
// there is no need to create a new template
if t.page == page {
return t, nil
}
t2 := *t
t2.page = page
return &t2, nil
} | go | func (t *FpdfTpl) FromPage(page int) (Template, error) {
// pages start at 1
if page == 0 {
return nil, errors.New("Pages start at 1 No template will have a page 0")
}
if page > t.NumPages() {
return nil, fmt.Errorf("The template does not have a page %d", page)
}
// if it is already pointing to the correct page
// there is no need to create a new template
if t.page == page {
return t, nil
}
t2 := *t
t2.page = page
return &t2, nil
} | [
"func",
"(",
"t",
"*",
"FpdfTpl",
")",
"FromPage",
"(",
"page",
"int",
")",
"(",
"Template",
",",
"error",
")",
"{",
"// pages start at 1",
"if",
"page",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"page",
">",
"t",
".",
"NumPages",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"page",
")",
"\n",
"}",
"\n",
"// if it is already pointing to the correct page",
"// there is no need to create a new template",
"if",
"t",
".",
"page",
"==",
"page",
"{",
"return",
"t",
",",
"nil",
"\n",
"}",
"\n\n",
"t2",
":=",
"*",
"t",
"\n",
"t2",
".",
"page",
"=",
"page",
"\n",
"return",
"&",
"t2",
",",
"nil",
"\n",
"}"
] | // FromPage creates a new template from a specific Page | [
"FromPage",
"creates",
"a",
"new",
"template",
"from",
"a",
"specific",
"Page"
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template_impl.go#L82-L100 | train |
jung-kurt/gofpdf | template_impl.go | FromPages | func (t *FpdfTpl) FromPages() []Template {
p := make([]Template, t.NumPages())
for x := 1; x <= t.NumPages(); x++ {
// the only error is when accessing a
// non existing template... that can't happen
// here
p[x-1], _ = t.FromPage(x)
}
return p
} | go | func (t *FpdfTpl) FromPages() []Template {
p := make([]Template, t.NumPages())
for x := 1; x <= t.NumPages(); x++ {
// the only error is when accessing a
// non existing template... that can't happen
// here
p[x-1], _ = t.FromPage(x)
}
return p
} | [
"func",
"(",
"t",
"*",
"FpdfTpl",
")",
"FromPages",
"(",
")",
"[",
"]",
"Template",
"{",
"p",
":=",
"make",
"(",
"[",
"]",
"Template",
",",
"t",
".",
"NumPages",
"(",
")",
")",
"\n",
"for",
"x",
":=",
"1",
";",
"x",
"<=",
"t",
".",
"NumPages",
"(",
")",
";",
"x",
"++",
"{",
"// the only error is when accessing a",
"// non existing template... that can't happen",
"// here",
"p",
"[",
"x",
"-",
"1",
"]",
",",
"_",
"=",
"t",
".",
"FromPage",
"(",
"x",
")",
"\n",
"}",
"\n\n",
"return",
"p",
"\n",
"}"
] | // FromPages creates a template slice with all the pages within a template. | [
"FromPages",
"creates",
"a",
"template",
"slice",
"with",
"all",
"the",
"pages",
"within",
"a",
"template",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template_impl.go#L103-L113 | train |
jung-kurt/gofpdf | template_impl.go | Serialize | func (t *FpdfTpl) Serialize() ([]byte, error) {
b := new(bytes.Buffer)
enc := gob.NewEncoder(b)
err := enc.Encode(t)
return b.Bytes(), err
} | go | func (t *FpdfTpl) Serialize() ([]byte, error) {
b := new(bytes.Buffer)
enc := gob.NewEncoder(b)
err := enc.Encode(t)
return b.Bytes(), err
} | [
"func",
"(",
"t",
"*",
"FpdfTpl",
")",
"Serialize",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"enc",
":=",
"gob",
".",
"NewEncoder",
"(",
"b",
")",
"\n",
"err",
":=",
"enc",
".",
"Encode",
"(",
"t",
")",
"\n\n",
"return",
"b",
".",
"Bytes",
"(",
")",
",",
"err",
"\n",
"}"
] | // Serialize turns a template into a byte string for later deserialization | [
"Serialize",
"turns",
"a",
"template",
"into",
"a",
"byte",
"string",
"for",
"later",
"deserialization"
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template_impl.go#L133-L139 | train |
jung-kurt/gofpdf | template_impl.go | DeserializeTemplate | func DeserializeTemplate(b []byte) (Template, error) {
tpl := new(FpdfTpl)
dec := gob.NewDecoder(bytes.NewBuffer(b))
err := dec.Decode(tpl)
return tpl, err
} | go | func DeserializeTemplate(b []byte) (Template, error) {
tpl := new(FpdfTpl)
dec := gob.NewDecoder(bytes.NewBuffer(b))
err := dec.Decode(tpl)
return tpl, err
} | [
"func",
"DeserializeTemplate",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"Template",
",",
"error",
")",
"{",
"tpl",
":=",
"new",
"(",
"FpdfTpl",
")",
"\n",
"dec",
":=",
"gob",
".",
"NewDecoder",
"(",
"bytes",
".",
"NewBuffer",
"(",
"b",
")",
")",
"\n",
"err",
":=",
"dec",
".",
"Decode",
"(",
"tpl",
")",
"\n",
"return",
"tpl",
",",
"err",
"\n",
"}"
] | // DeserializeTemplate creaties a template from a previously serialized
// template | [
"DeserializeTemplate",
"creaties",
"a",
"template",
"from",
"a",
"previously",
"serialized",
"template"
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template_impl.go#L143-L148 | train |
jung-kurt/gofpdf | template_impl.go | childrenImages | func (t *FpdfTpl) childrenImages() map[string]*ImageInfoType {
childrenImgs := make(map[string]*ImageInfoType)
for x := 0; x < len(t.templates); x++ {
imgs := t.templates[x].Images()
for key, val := range imgs {
name := sprintf("t%s-%s", t.templates[x].ID(), key)
childrenImgs[name] = val
}
}
return childrenImgs
} | go | func (t *FpdfTpl) childrenImages() map[string]*ImageInfoType {
childrenImgs := make(map[string]*ImageInfoType)
for x := 0; x < len(t.templates); x++ {
imgs := t.templates[x].Images()
for key, val := range imgs {
name := sprintf("t%s-%s", t.templates[x].ID(), key)
childrenImgs[name] = val
}
}
return childrenImgs
} | [
"func",
"(",
"t",
"*",
"FpdfTpl",
")",
"childrenImages",
"(",
")",
"map",
"[",
"string",
"]",
"*",
"ImageInfoType",
"{",
"childrenImgs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ImageInfoType",
")",
"\n\n",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"len",
"(",
"t",
".",
"templates",
")",
";",
"x",
"++",
"{",
"imgs",
":=",
"t",
".",
"templates",
"[",
"x",
"]",
".",
"Images",
"(",
")",
"\n",
"for",
"key",
",",
"val",
":=",
"range",
"imgs",
"{",
"name",
":=",
"sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"templates",
"[",
"x",
"]",
".",
"ID",
"(",
")",
",",
"key",
")",
"\n",
"childrenImgs",
"[",
"name",
"]",
"=",
"val",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"childrenImgs",
"\n",
"}"
] | // childrenImages returns the next layer of children images, it doesn't dig into
// children of children. Applies template namespace to keys to ensure
// no collisions. See UseTemplateScaled | [
"childrenImages",
"returns",
"the",
"next",
"layer",
"of",
"children",
"images",
"it",
"doesn",
"t",
"dig",
"into",
"children",
"of",
"children",
".",
"Applies",
"template",
"namespace",
"to",
"keys",
"to",
"ensure",
"no",
"collisions",
".",
"See",
"UseTemplateScaled"
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template_impl.go#L153-L165 | train |
jung-kurt/gofpdf | template_impl.go | childrensTemplates | func (t *FpdfTpl) childrensTemplates() []Template {
childrenTmpls := make([]Template, 0)
for x := 0; x < len(t.templates); x++ {
tmpls := t.templates[x].Templates()
childrenTmpls = append(childrenTmpls, tmpls...)
}
return childrenTmpls
} | go | func (t *FpdfTpl) childrensTemplates() []Template {
childrenTmpls := make([]Template, 0)
for x := 0; x < len(t.templates); x++ {
tmpls := t.templates[x].Templates()
childrenTmpls = append(childrenTmpls, tmpls...)
}
return childrenTmpls
} | [
"func",
"(",
"t",
"*",
"FpdfTpl",
")",
"childrensTemplates",
"(",
")",
"[",
"]",
"Template",
"{",
"childrenTmpls",
":=",
"make",
"(",
"[",
"]",
"Template",
",",
"0",
")",
"\n\n",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"len",
"(",
"t",
".",
"templates",
")",
";",
"x",
"++",
"{",
"tmpls",
":=",
"t",
".",
"templates",
"[",
"x",
"]",
".",
"Templates",
"(",
")",
"\n",
"childrenTmpls",
"=",
"append",
"(",
"childrenTmpls",
",",
"tmpls",
"...",
")",
"\n",
"}",
"\n\n",
"return",
"childrenTmpls",
"\n",
"}"
] | // childrensTemplates returns the next layer of children templates, it doesn't dig into
// children of children. | [
"childrensTemplates",
"returns",
"the",
"next",
"layer",
"of",
"children",
"templates",
"it",
"doesn",
"t",
"dig",
"into",
"children",
"of",
"children",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template_impl.go#L169-L178 | train |
jung-kurt/gofpdf | template_impl.go | GobEncode | func (t *FpdfTpl) GobEncode() ([]byte, error) {
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
childrensTemplates := t.childrensTemplates()
firstClassTemplates := make([]Template, 0)
found_continue:
for x := 0; x < len(t.templates); x++ {
for y := 0; y < len(childrensTemplates); y++ {
if childrensTemplates[y].ID() == t.templates[x].ID() {
continue found_continue
}
}
firstClassTemplates = append(firstClassTemplates, t.templates[x])
}
err := encoder.Encode(firstClassTemplates)
childrenImgs := t.childrenImages()
firstClassImgs := make(map[string]*ImageInfoType)
for key, img := range t.images {
if _, ok := childrenImgs[key]; !ok {
firstClassImgs[key] = img
}
}
if err == nil {
err = encoder.Encode(firstClassImgs)
}
if err == nil {
err = encoder.Encode(t.corner)
}
if err == nil {
err = encoder.Encode(t.size)
}
if err == nil {
err = encoder.Encode(t.bytes)
}
if err == nil {
err = encoder.Encode(t.page)
}
return w.Bytes(), err
} | go | func (t *FpdfTpl) GobEncode() ([]byte, error) {
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
childrensTemplates := t.childrensTemplates()
firstClassTemplates := make([]Template, 0)
found_continue:
for x := 0; x < len(t.templates); x++ {
for y := 0; y < len(childrensTemplates); y++ {
if childrensTemplates[y].ID() == t.templates[x].ID() {
continue found_continue
}
}
firstClassTemplates = append(firstClassTemplates, t.templates[x])
}
err := encoder.Encode(firstClassTemplates)
childrenImgs := t.childrenImages()
firstClassImgs := make(map[string]*ImageInfoType)
for key, img := range t.images {
if _, ok := childrenImgs[key]; !ok {
firstClassImgs[key] = img
}
}
if err == nil {
err = encoder.Encode(firstClassImgs)
}
if err == nil {
err = encoder.Encode(t.corner)
}
if err == nil {
err = encoder.Encode(t.size)
}
if err == nil {
err = encoder.Encode(t.bytes)
}
if err == nil {
err = encoder.Encode(t.page)
}
return w.Bytes(), err
} | [
"func",
"(",
"t",
"*",
"FpdfTpl",
")",
"GobEncode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"w",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"encoder",
":=",
"gob",
".",
"NewEncoder",
"(",
"w",
")",
"\n\n",
"childrensTemplates",
":=",
"t",
".",
"childrensTemplates",
"(",
")",
"\n",
"firstClassTemplates",
":=",
"make",
"(",
"[",
"]",
"Template",
",",
"0",
")",
"\n\n",
"found_continue",
":",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"len",
"(",
"t",
".",
"templates",
")",
";",
"x",
"++",
"{",
"for",
"y",
":=",
"0",
";",
"y",
"<",
"len",
"(",
"childrensTemplates",
")",
";",
"y",
"++",
"{",
"if",
"childrensTemplates",
"[",
"y",
"]",
".",
"ID",
"(",
")",
"==",
"t",
".",
"templates",
"[",
"x",
"]",
".",
"ID",
"(",
")",
"{",
"continue",
"found_continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"firstClassTemplates",
"=",
"append",
"(",
"firstClassTemplates",
",",
"t",
".",
"templates",
"[",
"x",
"]",
")",
"\n",
"}",
"\n",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"firstClassTemplates",
")",
"\n\n",
"childrenImgs",
":=",
"t",
".",
"childrenImages",
"(",
")",
"\n",
"firstClassImgs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ImageInfoType",
")",
"\n\n",
"for",
"key",
",",
"img",
":=",
"range",
"t",
".",
"images",
"{",
"if",
"_",
",",
"ok",
":=",
"childrenImgs",
"[",
"key",
"]",
";",
"!",
"ok",
"{",
"firstClassImgs",
"[",
"key",
"]",
"=",
"img",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"encoder",
".",
"Encode",
"(",
"firstClassImgs",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"encoder",
".",
"Encode",
"(",
"t",
".",
"corner",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"encoder",
".",
"Encode",
"(",
"t",
".",
"size",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"encoder",
".",
"Encode",
"(",
"t",
".",
"bytes",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"encoder",
".",
"Encode",
"(",
"t",
".",
"page",
")",
"\n",
"}",
"\n\n",
"return",
"w",
".",
"Bytes",
"(",
")",
",",
"err",
"\n",
"}"
] | // GobEncode encodes the receiving template into a byte buffer. Use GobDecode
// to decode the byte buffer back to a template. | [
"GobEncode",
"encodes",
"the",
"receiving",
"template",
"into",
"a",
"byte",
"buffer",
".",
"Use",
"GobDecode",
"to",
"decode",
"the",
"byte",
"buffer",
"back",
"to",
"a",
"template",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template_impl.go#L182-L227 | train |
jung-kurt/gofpdf | template_impl.go | GobDecode | func (t *FpdfTpl) GobDecode(buf []byte) error {
r := bytes.NewBuffer(buf)
decoder := gob.NewDecoder(r)
firstClassTemplates := make([]*FpdfTpl, 0)
err := decoder.Decode(&firstClassTemplates)
t.templates = make([]Template, len(firstClassTemplates))
for x := 0; x < len(t.templates); x++ {
t.templates[x] = Template(firstClassTemplates[x])
}
firstClassImages := t.childrenImages()
t.templates = append(t.childrensTemplates(), t.templates...)
t.images = make(map[string]*ImageInfoType)
if err == nil {
err = decoder.Decode(&t.images)
}
for k, v := range firstClassImages {
t.images[k] = v
}
if err == nil {
err = decoder.Decode(&t.corner)
}
if err == nil {
err = decoder.Decode(&t.size)
}
if err == nil {
err = decoder.Decode(&t.bytes)
}
if err == nil {
err = decoder.Decode(&t.page)
}
return err
} | go | func (t *FpdfTpl) GobDecode(buf []byte) error {
r := bytes.NewBuffer(buf)
decoder := gob.NewDecoder(r)
firstClassTemplates := make([]*FpdfTpl, 0)
err := decoder.Decode(&firstClassTemplates)
t.templates = make([]Template, len(firstClassTemplates))
for x := 0; x < len(t.templates); x++ {
t.templates[x] = Template(firstClassTemplates[x])
}
firstClassImages := t.childrenImages()
t.templates = append(t.childrensTemplates(), t.templates...)
t.images = make(map[string]*ImageInfoType)
if err == nil {
err = decoder.Decode(&t.images)
}
for k, v := range firstClassImages {
t.images[k] = v
}
if err == nil {
err = decoder.Decode(&t.corner)
}
if err == nil {
err = decoder.Decode(&t.size)
}
if err == nil {
err = decoder.Decode(&t.bytes)
}
if err == nil {
err = decoder.Decode(&t.page)
}
return err
} | [
"func",
"(",
"t",
"*",
"FpdfTpl",
")",
"GobDecode",
"(",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"r",
":=",
"bytes",
".",
"NewBuffer",
"(",
"buf",
")",
"\n",
"decoder",
":=",
"gob",
".",
"NewDecoder",
"(",
"r",
")",
"\n\n",
"firstClassTemplates",
":=",
"make",
"(",
"[",
"]",
"*",
"FpdfTpl",
",",
"0",
")",
"\n",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"firstClassTemplates",
")",
"\n",
"t",
".",
"templates",
"=",
"make",
"(",
"[",
"]",
"Template",
",",
"len",
"(",
"firstClassTemplates",
")",
")",
"\n\n",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"len",
"(",
"t",
".",
"templates",
")",
";",
"x",
"++",
"{",
"t",
".",
"templates",
"[",
"x",
"]",
"=",
"Template",
"(",
"firstClassTemplates",
"[",
"x",
"]",
")",
"\n",
"}",
"\n\n",
"firstClassImages",
":=",
"t",
".",
"childrenImages",
"(",
")",
"\n\n",
"t",
".",
"templates",
"=",
"append",
"(",
"t",
".",
"childrensTemplates",
"(",
")",
",",
"t",
".",
"templates",
"...",
")",
"\n\n",
"t",
".",
"images",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ImageInfoType",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"decoder",
".",
"Decode",
"(",
"&",
"t",
".",
"images",
")",
"\n",
"}",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"firstClassImages",
"{",
"t",
".",
"images",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"decoder",
".",
"Decode",
"(",
"&",
"t",
".",
"corner",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"decoder",
".",
"Decode",
"(",
"&",
"t",
".",
"size",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"decoder",
".",
"Decode",
"(",
"&",
"t",
".",
"bytes",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"decoder",
".",
"Decode",
"(",
"&",
"t",
".",
"page",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // GobDecode decodes the specified byte buffer into the receiving template. | [
"GobDecode",
"decodes",
"the",
"specified",
"byte",
"buffer",
"into",
"the",
"receiving",
"template",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template_impl.go#L230-L269 | train |
jung-kurt/gofpdf | internal/example/example.go | setRoot | func setRoot() {
wdStr, err := os.Getwd()
if err == nil {
gofpdfDir = ""
list := strings.Split(filepath.ToSlash(wdStr), "/")
for j := len(list) - 1; j >= 0 && list[j] != "gofpdf"; j-- {
gofpdfDir = filepath.Join(gofpdfDir, "..")
}
} else {
panic(err)
}
} | go | func setRoot() {
wdStr, err := os.Getwd()
if err == nil {
gofpdfDir = ""
list := strings.Split(filepath.ToSlash(wdStr), "/")
for j := len(list) - 1; j >= 0 && list[j] != "gofpdf"; j-- {
gofpdfDir = filepath.Join(gofpdfDir, "..")
}
} else {
panic(err)
}
} | [
"func",
"setRoot",
"(",
")",
"{",
"wdStr",
",",
"err",
":=",
"os",
".",
"Getwd",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"gofpdfDir",
"=",
"\"",
"\"",
"\n",
"list",
":=",
"strings",
".",
"Split",
"(",
"filepath",
".",
"ToSlash",
"(",
"wdStr",
")",
",",
"\"",
"\"",
")",
"\n",
"for",
"j",
":=",
"len",
"(",
"list",
")",
"-",
"1",
";",
"j",
">=",
"0",
"&&",
"list",
"[",
"j",
"]",
"!=",
"\"",
"\"",
";",
"j",
"--",
"{",
"gofpdfDir",
"=",
"filepath",
".",
"Join",
"(",
"gofpdfDir",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // setRoot assigns the relative path to the gofpdfDir directory based on current working
// directory | [
"setRoot",
"assigns",
"the",
"relative",
"path",
"to",
"the",
"gofpdfDir",
"directory",
"based",
"on",
"current",
"working",
"directory"
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/internal/example/example.go#L41-L52 | train |
jung-kurt/gofpdf | compare.go | CompareBytes | func CompareBytes(sl1, sl2 []byte, printDiff bool) (err error) {
var posStart, posEnd, len1, len2, length int
var diffs bool
len1 = len(sl1)
len2 = len(sl2)
length = len1
if length > len2 {
length = len2
}
for posStart < length-1 {
posEnd = posStart + 16
if posEnd > length {
posEnd = length
}
if !checkBytes(posStart, sl1[posStart:posEnd], sl2[posStart:posEnd], printDiff) {
diffs = true
}
posStart = posEnd
}
if diffs {
err = fmt.Errorf("documents are different")
}
return
} | go | func CompareBytes(sl1, sl2 []byte, printDiff bool) (err error) {
var posStart, posEnd, len1, len2, length int
var diffs bool
len1 = len(sl1)
len2 = len(sl2)
length = len1
if length > len2 {
length = len2
}
for posStart < length-1 {
posEnd = posStart + 16
if posEnd > length {
posEnd = length
}
if !checkBytes(posStart, sl1[posStart:posEnd], sl2[posStart:posEnd], printDiff) {
diffs = true
}
posStart = posEnd
}
if diffs {
err = fmt.Errorf("documents are different")
}
return
} | [
"func",
"CompareBytes",
"(",
"sl1",
",",
"sl2",
"[",
"]",
"byte",
",",
"printDiff",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"var",
"posStart",
",",
"posEnd",
",",
"len1",
",",
"len2",
",",
"length",
"int",
"\n",
"var",
"diffs",
"bool",
"\n\n",
"len1",
"=",
"len",
"(",
"sl1",
")",
"\n",
"len2",
"=",
"len",
"(",
"sl2",
")",
"\n",
"length",
"=",
"len1",
"\n",
"if",
"length",
">",
"len2",
"{",
"length",
"=",
"len2",
"\n",
"}",
"\n",
"for",
"posStart",
"<",
"length",
"-",
"1",
"{",
"posEnd",
"=",
"posStart",
"+",
"16",
"\n",
"if",
"posEnd",
">",
"length",
"{",
"posEnd",
"=",
"length",
"\n",
"}",
"\n",
"if",
"!",
"checkBytes",
"(",
"posStart",
",",
"sl1",
"[",
"posStart",
":",
"posEnd",
"]",
",",
"sl2",
"[",
"posStart",
":",
"posEnd",
"]",
",",
"printDiff",
")",
"{",
"diffs",
"=",
"true",
"\n",
"}",
"\n",
"posStart",
"=",
"posEnd",
"\n",
"}",
"\n",
"if",
"diffs",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // CompareBytes compares the bytes referred to by sl1 with those referred to by
// sl2. Nil is returned if the buffers are equal, otherwise an error. | [
"CompareBytes",
"compares",
"the",
"bytes",
"referred",
"to",
"by",
"sl1",
"with",
"those",
"referred",
"to",
"by",
"sl2",
".",
"Nil",
"is",
"returned",
"if",
"the",
"buffers",
"are",
"equal",
"otherwise",
"an",
"error",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/compare.go#L89-L113 | train |
jung-kurt/gofpdf | compare.go | ComparePDFs | func ComparePDFs(rdr1, rdr2 io.Reader, printDiff bool) (err error) {
var b1, b2 *bytes.Buffer
_, err = b1.ReadFrom(rdr1)
if err == nil {
_, err = b2.ReadFrom(rdr2)
if err == nil {
err = CompareBytes(b1.Bytes(), b2.Bytes(), printDiff)
}
}
return
} | go | func ComparePDFs(rdr1, rdr2 io.Reader, printDiff bool) (err error) {
var b1, b2 *bytes.Buffer
_, err = b1.ReadFrom(rdr1)
if err == nil {
_, err = b2.ReadFrom(rdr2)
if err == nil {
err = CompareBytes(b1.Bytes(), b2.Bytes(), printDiff)
}
}
return
} | [
"func",
"ComparePDFs",
"(",
"rdr1",
",",
"rdr2",
"io",
".",
"Reader",
",",
"printDiff",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"var",
"b1",
",",
"b2",
"*",
"bytes",
".",
"Buffer",
"\n",
"_",
",",
"err",
"=",
"b1",
".",
"ReadFrom",
"(",
"rdr1",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"_",
",",
"err",
"=",
"b2",
".",
"ReadFrom",
"(",
"rdr2",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"CompareBytes",
"(",
"b1",
".",
"Bytes",
"(",
")",
",",
"b2",
".",
"Bytes",
"(",
")",
",",
"printDiff",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // ComparePDFs reads and compares the full contents of the two specified
// readers byte-for-byte. Nil is returned if the buffers are equal, otherwise
// an error. | [
"ComparePDFs",
"reads",
"and",
"compares",
"the",
"full",
"contents",
"of",
"the",
"two",
"specified",
"readers",
"byte",
"-",
"for",
"-",
"byte",
".",
"Nil",
"is",
"returned",
"if",
"the",
"buffers",
"are",
"equal",
"otherwise",
"an",
"error",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/compare.go#L118-L128 | train |
jung-kurt/gofpdf | compare.go | ComparePDFFiles | func ComparePDFFiles(file1Str, file2Str string, printDiff bool) (err error) {
var sl1, sl2 []byte
sl1, err = ioutil.ReadFile(file1Str)
if err == nil {
sl2, err = ioutil.ReadFile(file2Str)
if err == nil {
err = CompareBytes(sl1, sl2, printDiff)
} else {
// Second file is missing; treat this as success
err = nil
}
}
return
} | go | func ComparePDFFiles(file1Str, file2Str string, printDiff bool) (err error) {
var sl1, sl2 []byte
sl1, err = ioutil.ReadFile(file1Str)
if err == nil {
sl2, err = ioutil.ReadFile(file2Str)
if err == nil {
err = CompareBytes(sl1, sl2, printDiff)
} else {
// Second file is missing; treat this as success
err = nil
}
}
return
} | [
"func",
"ComparePDFFiles",
"(",
"file1Str",
",",
"file2Str",
"string",
",",
"printDiff",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"var",
"sl1",
",",
"sl2",
"[",
"]",
"byte",
"\n",
"sl1",
",",
"err",
"=",
"ioutil",
".",
"ReadFile",
"(",
"file1Str",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"sl2",
",",
"err",
"=",
"ioutil",
".",
"ReadFile",
"(",
"file2Str",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"CompareBytes",
"(",
"sl1",
",",
"sl2",
",",
"printDiff",
")",
"\n",
"}",
"else",
"{",
"// Second file is missing; treat this as success",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // ComparePDFFiles reads and compares the full contents of the two specified
// files byte-for-byte. Nil is returned if the file contents are equal, or if
// the second file is missing, otherwise an error. | [
"ComparePDFFiles",
"reads",
"and",
"compares",
"the",
"full",
"contents",
"of",
"the",
"two",
"specified",
"files",
"byte",
"-",
"for",
"-",
"byte",
".",
"Nil",
"is",
"returned",
"if",
"the",
"file",
"contents",
"are",
"equal",
"or",
"if",
"the",
"second",
"file",
"is",
"missing",
"otherwise",
"an",
"error",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/compare.go#L133-L146 | train |
jung-kurt/gofpdf | def.go | GobEncode | func (info *ImageInfoType) GobEncode() (buf []byte, err error) {
fields := []interface{}{info.data, info.smask, info.n, info.w, info.h, info.cs,
info.pal, info.bpc, info.f, info.dp, info.trns, info.scale, info.dpi}
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
for j := 0; j < len(fields) && err == nil; j++ {
err = encoder.Encode(fields[j])
}
if err == nil {
buf = w.Bytes()
}
return
} | go | func (info *ImageInfoType) GobEncode() (buf []byte, err error) {
fields := []interface{}{info.data, info.smask, info.n, info.w, info.h, info.cs,
info.pal, info.bpc, info.f, info.dp, info.trns, info.scale, info.dpi}
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
for j := 0; j < len(fields) && err == nil; j++ {
err = encoder.Encode(fields[j])
}
if err == nil {
buf = w.Bytes()
}
return
} | [
"func",
"(",
"info",
"*",
"ImageInfoType",
")",
"GobEncode",
"(",
")",
"(",
"buf",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"fields",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"info",
".",
"data",
",",
"info",
".",
"smask",
",",
"info",
".",
"n",
",",
"info",
".",
"w",
",",
"info",
".",
"h",
",",
"info",
".",
"cs",
",",
"info",
".",
"pal",
",",
"info",
".",
"bpc",
",",
"info",
".",
"f",
",",
"info",
".",
"dp",
",",
"info",
".",
"trns",
",",
"info",
".",
"scale",
",",
"info",
".",
"dpi",
"}",
"\n",
"w",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"encoder",
":=",
"gob",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"len",
"(",
"fields",
")",
"&&",
"err",
"==",
"nil",
";",
"j",
"++",
"{",
"err",
"=",
"encoder",
".",
"Encode",
"(",
"fields",
"[",
"j",
"]",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"buf",
"=",
"w",
".",
"Bytes",
"(",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // GobEncode encodes the receiving image to a byte slice. | [
"GobEncode",
"encodes",
"the",
"receiving",
"image",
"to",
"a",
"byte",
"slice",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/def.go#L190-L202 | train |
jung-kurt/gofpdf | def.go | PointToUnitConvert | func (f *Fpdf) PointToUnitConvert(pt float64) (u float64) {
return pt / f.k
} | go | func (f *Fpdf) PointToUnitConvert(pt float64) (u float64) {
return pt / f.k
} | [
"func",
"(",
"f",
"*",
"Fpdf",
")",
"PointToUnitConvert",
"(",
"pt",
"float64",
")",
"(",
"u",
"float64",
")",
"{",
"return",
"pt",
"/",
"f",
".",
"k",
"\n",
"}"
] | // PointToUnitConvert is an alias for PointConvert. | [
"PointToUnitConvert",
"is",
"an",
"alias",
"for",
"PointConvert",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/def.go#L228-L230 | train |
jung-kurt/gofpdf | def.go | Extent | func (info *ImageInfoType) Extent() (wd, ht float64) {
return info.Width(), info.Height()
} | go | func (info *ImageInfoType) Extent() (wd, ht float64) {
return info.Width(), info.Height()
} | [
"func",
"(",
"info",
"*",
"ImageInfoType",
")",
"Extent",
"(",
")",
"(",
"wd",
",",
"ht",
"float64",
")",
"{",
"return",
"info",
".",
"Width",
"(",
")",
",",
"info",
".",
"Height",
"(",
")",
"\n",
"}"
] | // Extent returns the width and height of the image in the units of the Fpdf
// object. | [
"Extent",
"returns",
"the",
"width",
"and",
"height",
"of",
"the",
"image",
"in",
"the",
"units",
"of",
"the",
"Fpdf",
"object",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/def.go#L242-L244 | train |
jung-kurt/gofpdf | def.go | Width | func (info *ImageInfoType) Width() float64 {
return info.w / (info.scale * info.dpi / 72)
} | go | func (info *ImageInfoType) Width() float64 {
return info.w / (info.scale * info.dpi / 72)
} | [
"func",
"(",
"info",
"*",
"ImageInfoType",
")",
"Width",
"(",
")",
"float64",
"{",
"return",
"info",
".",
"w",
"/",
"(",
"info",
".",
"scale",
"*",
"info",
".",
"dpi",
"/",
"72",
")",
"\n",
"}"
] | // Width returns the width of the image in the units of the Fpdf object. | [
"Width",
"returns",
"the",
"width",
"of",
"the",
"image",
"in",
"the",
"units",
"of",
"the",
"Fpdf",
"object",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/def.go#L247-L249 | train |
jung-kurt/gofpdf | def.go | Height | func (info *ImageInfoType) Height() float64 {
return info.h / (info.scale * info.dpi / 72)
} | go | func (info *ImageInfoType) Height() float64 {
return info.h / (info.scale * info.dpi / 72)
} | [
"func",
"(",
"info",
"*",
"ImageInfoType",
")",
"Height",
"(",
")",
"float64",
"{",
"return",
"info",
".",
"h",
"/",
"(",
"info",
".",
"scale",
"*",
"info",
".",
"dpi",
"/",
"72",
")",
"\n",
"}"
] | // Height returns the height of the image in the units of the Fpdf object. | [
"Height",
"returns",
"the",
"height",
"of",
"the",
"image",
"in",
"the",
"units",
"of",
"the",
"Fpdf",
"object",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/def.go#L252-L254 | train |
jung-kurt/gofpdf | def.go | generateFontID | func generateFontID(fdt fontDefType) (string, error) {
// file can be different if generated in different instance
fdt.File = ""
b, err := json.Marshal(&fdt)
return fmt.Sprintf("%x", sha1.Sum(b)), err
} | go | func generateFontID(fdt fontDefType) (string, error) {
// file can be different if generated in different instance
fdt.File = ""
b, err := json.Marshal(&fdt)
return fmt.Sprintf("%x", sha1.Sum(b)), err
} | [
"func",
"generateFontID",
"(",
"fdt",
"fontDefType",
")",
"(",
"string",
",",
"error",
")",
"{",
"// file can be different if generated in different instance",
"fdt",
".",
"File",
"=",
"\"",
"\"",
"\n",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"&",
"fdt",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sha1",
".",
"Sum",
"(",
"b",
")",
")",
",",
"err",
"\n",
"}"
] | // generateFontID generates a font Id from the font definition | [
"generateFontID",
"generates",
"a",
"font",
"Id",
"from",
"the",
"font",
"definition"
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/def.go#L703-L708 | train |
jung-kurt/gofpdf | ttfparser.go | TtfParse | func TtfParse(fileStr string) (TtfRec TtfType, err error) {
var t ttfParser
t.f, err = os.Open(fileStr)
if err != nil {
return
}
version, err := t.ReadStr(4)
if err != nil {
return
}
if version == "OTTO" {
err = fmt.Errorf("fonts based on PostScript outlines are not supported")
return
}
if version != "\x00\x01\x00\x00" {
err = fmt.Errorf("unrecognized file format")
return
}
numTables := int(t.ReadUShort())
t.Skip(3 * 2) // searchRange, entrySelector, rangeShift
t.tables = make(map[string]uint32)
var tag string
for j := 0; j < numTables; j++ {
tag, err = t.ReadStr(4)
if err != nil {
return
}
t.Skip(4) // checkSum
offset := t.ReadULong()
t.Skip(4) // length
t.tables[tag] = offset
}
err = t.ParseComponents()
if err != nil {
return
}
t.f.Close()
TtfRec = t.rec
return
} | go | func TtfParse(fileStr string) (TtfRec TtfType, err error) {
var t ttfParser
t.f, err = os.Open(fileStr)
if err != nil {
return
}
version, err := t.ReadStr(4)
if err != nil {
return
}
if version == "OTTO" {
err = fmt.Errorf("fonts based on PostScript outlines are not supported")
return
}
if version != "\x00\x01\x00\x00" {
err = fmt.Errorf("unrecognized file format")
return
}
numTables := int(t.ReadUShort())
t.Skip(3 * 2) // searchRange, entrySelector, rangeShift
t.tables = make(map[string]uint32)
var tag string
for j := 0; j < numTables; j++ {
tag, err = t.ReadStr(4)
if err != nil {
return
}
t.Skip(4) // checkSum
offset := t.ReadULong()
t.Skip(4) // length
t.tables[tag] = offset
}
err = t.ParseComponents()
if err != nil {
return
}
t.f.Close()
TtfRec = t.rec
return
} | [
"func",
"TtfParse",
"(",
"fileStr",
"string",
")",
"(",
"TtfRec",
"TtfType",
",",
"err",
"error",
")",
"{",
"var",
"t",
"ttfParser",
"\n",
"t",
".",
"f",
",",
"err",
"=",
"os",
".",
"Open",
"(",
"fileStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"version",
",",
"err",
":=",
"t",
".",
"ReadStr",
"(",
"4",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"version",
"==",
"\"",
"\"",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"version",
"!=",
"\"",
"\\x00",
"\\x01",
"\\x00",
"\\x00",
"\"",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"numTables",
":=",
"int",
"(",
"t",
".",
"ReadUShort",
"(",
")",
")",
"\n",
"t",
".",
"Skip",
"(",
"3",
"*",
"2",
")",
"// searchRange, entrySelector, rangeShift",
"\n",
"t",
".",
"tables",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"uint32",
")",
"\n",
"var",
"tag",
"string",
"\n",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"numTables",
";",
"j",
"++",
"{",
"tag",
",",
"err",
"=",
"t",
".",
"ReadStr",
"(",
"4",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"t",
".",
"Skip",
"(",
"4",
")",
"// checkSum",
"\n",
"offset",
":=",
"t",
".",
"ReadULong",
"(",
")",
"\n",
"t",
".",
"Skip",
"(",
"4",
")",
"// length",
"\n",
"t",
".",
"tables",
"[",
"tag",
"]",
"=",
"offset",
"\n",
"}",
"\n",
"err",
"=",
"t",
".",
"ParseComponents",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"t",
".",
"f",
".",
"Close",
"(",
")",
"\n",
"TtfRec",
"=",
"t",
".",
"rec",
"\n",
"return",
"\n",
"}"
] | // TtfParse extracts various metrics from a TrueType font file. | [
"TtfParse",
"extracts",
"various",
"metrics",
"from",
"a",
"TrueType",
"font",
"file",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/ttfparser.go#L60-L99 | train |
jung-kurt/gofpdf | label.go | niceNum | func niceNum(val float64, round bool) float64 {
var nf float64
exp := int(math.Floor(math.Log10(val)))
f := val / math.Pow10(exp)
if round {
switch {
case f < 1.5:
nf = 1
case f < 3.0:
nf = 2
case f < 7.0:
nf = 5
default:
nf = 10
}
} else {
switch {
case f <= 1:
nf = 1
case f <= 2.0:
nf = 2
case f <= 5.0:
nf = 5
default:
nf = 10
}
}
return nf * math.Pow10(exp)
} | go | func niceNum(val float64, round bool) float64 {
var nf float64
exp := int(math.Floor(math.Log10(val)))
f := val / math.Pow10(exp)
if round {
switch {
case f < 1.5:
nf = 1
case f < 3.0:
nf = 2
case f < 7.0:
nf = 5
default:
nf = 10
}
} else {
switch {
case f <= 1:
nf = 1
case f <= 2.0:
nf = 2
case f <= 5.0:
nf = 5
default:
nf = 10
}
}
return nf * math.Pow10(exp)
} | [
"func",
"niceNum",
"(",
"val",
"float64",
",",
"round",
"bool",
")",
"float64",
"{",
"var",
"nf",
"float64",
"\n\n",
"exp",
":=",
"int",
"(",
"math",
".",
"Floor",
"(",
"math",
".",
"Log10",
"(",
"val",
")",
")",
")",
"\n",
"f",
":=",
"val",
"/",
"math",
".",
"Pow10",
"(",
"exp",
")",
"\n",
"if",
"round",
"{",
"switch",
"{",
"case",
"f",
"<",
"1.5",
":",
"nf",
"=",
"1",
"\n",
"case",
"f",
"<",
"3.0",
":",
"nf",
"=",
"2",
"\n",
"case",
"f",
"<",
"7.0",
":",
"nf",
"=",
"5",
"\n",
"default",
":",
"nf",
"=",
"10",
"\n",
"}",
"\n",
"}",
"else",
"{",
"switch",
"{",
"case",
"f",
"<=",
"1",
":",
"nf",
"=",
"1",
"\n",
"case",
"f",
"<=",
"2.0",
":",
"nf",
"=",
"2",
"\n",
"case",
"f",
"<=",
"5.0",
":",
"nf",
"=",
"5",
"\n",
"default",
":",
"nf",
"=",
"10",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nf",
"*",
"math",
".",
"Pow10",
"(",
"exp",
")",
"\n",
"}"
] | // niceNum returns a "nice" number approximately equal to x. The number is
// rounded if round is true, converted to its ceiling otherwise. | [
"niceNum",
"returns",
"a",
"nice",
"number",
"approximately",
"equal",
"to",
"x",
".",
"The",
"number",
"is",
"rounded",
"if",
"round",
"is",
"true",
"converted",
"to",
"its",
"ceiling",
"otherwise",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/label.go#L30-L59 | train |
jung-kurt/gofpdf | label.go | TickmarkPrecision | func TickmarkPrecision(div float64) int {
return int(math.Max(-math.Floor(math.Log10(div)), 0))
} | go | func TickmarkPrecision(div float64) int {
return int(math.Max(-math.Floor(math.Log10(div)), 0))
} | [
"func",
"TickmarkPrecision",
"(",
"div",
"float64",
")",
"int",
"{",
"return",
"int",
"(",
"math",
".",
"Max",
"(",
"-",
"math",
".",
"Floor",
"(",
"math",
".",
"Log10",
"(",
"div",
")",
")",
",",
"0",
")",
")",
"\n",
"}"
] | // TickmarkPrecision returns an appropriate precision value for label
// formatting. | [
"TickmarkPrecision",
"returns",
"an",
"appropriate",
"precision",
"value",
"for",
"label",
"formatting",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/label.go#L63-L65 | train |
jung-kurt/gofpdf | label.go | Tickmarks | func Tickmarks(min, max float64) (list []float64, precision int) {
if max > min {
spread := niceNum(max-min, false)
d := niceNum((spread / 4), true)
graphMin := math.Floor(min/d) * d
graphMax := math.Ceil(max/d) * d
precision = TickmarkPrecision(d)
for x := graphMin; x < graphMax+0.5*d; x += d {
list = append(list, x)
}
}
return
} | go | func Tickmarks(min, max float64) (list []float64, precision int) {
if max > min {
spread := niceNum(max-min, false)
d := niceNum((spread / 4), true)
graphMin := math.Floor(min/d) * d
graphMax := math.Ceil(max/d) * d
precision = TickmarkPrecision(d)
for x := graphMin; x < graphMax+0.5*d; x += d {
list = append(list, x)
}
}
return
} | [
"func",
"Tickmarks",
"(",
"min",
",",
"max",
"float64",
")",
"(",
"list",
"[",
"]",
"float64",
",",
"precision",
"int",
")",
"{",
"if",
"max",
">",
"min",
"{",
"spread",
":=",
"niceNum",
"(",
"max",
"-",
"min",
",",
"false",
")",
"\n",
"d",
":=",
"niceNum",
"(",
"(",
"spread",
"/",
"4",
")",
",",
"true",
")",
"\n",
"graphMin",
":=",
"math",
".",
"Floor",
"(",
"min",
"/",
"d",
")",
"*",
"d",
"\n",
"graphMax",
":=",
"math",
".",
"Ceil",
"(",
"max",
"/",
"d",
")",
"*",
"d",
"\n",
"precision",
"=",
"TickmarkPrecision",
"(",
"d",
")",
"\n",
"for",
"x",
":=",
"graphMin",
";",
"x",
"<",
"graphMax",
"+",
"0.5",
"*",
"d",
";",
"x",
"+=",
"d",
"{",
"list",
"=",
"append",
"(",
"list",
",",
"x",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Tickmarks returns a slice of tickmarks appropriate for a chart axis and an
// appropriate precision for formatting purposes. The values min and max will
// be contained within the tickmark range. | [
"Tickmarks",
"returns",
"a",
"slice",
"of",
"tickmarks",
"appropriate",
"for",
"a",
"chart",
"axis",
"and",
"an",
"appropriate",
"precision",
"for",
"formatting",
"purposes",
".",
"The",
"values",
"min",
"and",
"max",
"will",
"be",
"contained",
"within",
"the",
"tickmark",
"range",
"."
] | 8b09ffb30d9a8716107d250631b3c580aa54ba04 | https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/label.go#L70-L82 | train |
golang/mock | sample/concurrent/mock/concurrent_mock.go | NewMockMath | func NewMockMath(ctrl *gomock.Controller) *MockMath {
mock := &MockMath{ctrl: ctrl}
mock.recorder = &MockMathMockRecorder{mock}
return mock
} | go | func NewMockMath(ctrl *gomock.Controller) *MockMath {
mock := &MockMath{ctrl: ctrl}
mock.recorder = &MockMathMockRecorder{mock}
return mock
} | [
"func",
"NewMockMath",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockMath",
"{",
"mock",
":=",
"&",
"MockMath",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockMathMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockMath creates a new mock instance | [
"NewMockMath",
"creates",
"a",
"new",
"mock",
"instance"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/concurrent/mock/concurrent_mock.go#L24-L28 | train |
golang/mock | sample/concurrent/mock/concurrent_mock.go | Sum | func (m *MockMath) Sum(arg0, arg1 int) int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Sum", arg0, arg1)
ret0, _ := ret[0].(int)
return ret0
} | go | func (m *MockMath) Sum(arg0, arg1 int) int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Sum", arg0, arg1)
ret0, _ := ret[0].(int)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMath",
")",
"Sum",
"(",
"arg0",
",",
"arg1",
"int",
")",
"int",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"int",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Sum mocks base method | [
"Sum",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/concurrent/mock/concurrent_mock.go#L36-L41 | train |
golang/mock | sample/concurrent/mock/concurrent_mock.go | Sum | func (mr *MockMathMockRecorder) Sum(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sum", reflect.TypeOf((*MockMath)(nil).Sum), arg0, arg1)
} | go | func (mr *MockMathMockRecorder) Sum(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sum", reflect.TypeOf((*MockMath)(nil).Sum), arg0, arg1)
} | [
"func",
"(",
"mr",
"*",
"MockMathMockRecorder",
")",
"Sum",
"(",
"arg0",
",",
"arg1",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockMath",
")",
"(",
"nil",
")",
".",
"Sum",
")",
",",
"arg0",
",",
"arg1",
")",
"\n",
"}"
] | // Sum indicates an expected call of Sum | [
"Sum",
"indicates",
"an",
"expected",
"call",
"of",
"Sum"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/concurrent/mock/concurrent_mock.go#L44-L47 | train |
golang/mock | mockgen/reflect.go | run | func run(program string) (*model.Package, error) {
f, err := ioutil.TempFile("", "")
if err != nil {
return nil, err
}
filename := f.Name()
defer os.Remove(filename)
if err := f.Close(); err != nil {
return nil, err
}
// Run the program.
cmd := exec.Command(program, "-output", filename)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return nil, err
}
f, err = os.Open(filename)
if err != nil {
return nil, err
}
// Process output.
var pkg model.Package
if err := gob.NewDecoder(f).Decode(&pkg); err != nil {
return nil, err
}
if err := f.Close(); err != nil {
return nil, err
}
return &pkg, nil
} | go | func run(program string) (*model.Package, error) {
f, err := ioutil.TempFile("", "")
if err != nil {
return nil, err
}
filename := f.Name()
defer os.Remove(filename)
if err := f.Close(); err != nil {
return nil, err
}
// Run the program.
cmd := exec.Command(program, "-output", filename)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return nil, err
}
f, err = os.Open(filename)
if err != nil {
return nil, err
}
// Process output.
var pkg model.Package
if err := gob.NewDecoder(f).Decode(&pkg); err != nil {
return nil, err
}
if err := f.Close(); err != nil {
return nil, err
}
return &pkg, nil
} | [
"func",
"run",
"(",
"program",
"string",
")",
"(",
"*",
"model",
".",
"Package",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"filename",
":=",
"f",
".",
"Name",
"(",
")",
"\n",
"defer",
"os",
".",
"Remove",
"(",
"filename",
")",
"\n",
"if",
"err",
":=",
"f",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Run the program.",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"program",
",",
"\"",
"\"",
",",
"filename",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"f",
",",
"err",
"=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Process output.",
"var",
"pkg",
"model",
".",
"Package",
"\n",
"if",
"err",
":=",
"gob",
".",
"NewDecoder",
"(",
"f",
")",
".",
"Decode",
"(",
"&",
"pkg",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"f",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"pkg",
",",
"nil",
"\n",
"}"
] | // run the given program and parse the output as a model.Package. | [
"run",
"the",
"given",
"program",
"and",
"parse",
"the",
"output",
"as",
"a",
"model",
".",
"Package",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/reflect.go#L54-L90 | train |
golang/mock | mockgen/reflect.go | runInDir | func runInDir(program []byte, dir string) (*model.Package, error) {
// We use TempDir instead of TempFile so we can control the filename.
tmpDir, err := ioutil.TempDir(dir, "gomock_reflect_")
if err != nil {
return nil, err
}
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
log.Printf("failed to remove temp directory: %s", err)
}
}()
const progSource = "prog.go"
var progBinary = "prog.bin"
if runtime.GOOS == "windows" {
// Windows won't execute a program unless it has a ".exe" suffix.
progBinary += ".exe"
}
if err := ioutil.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil {
return nil, err
}
cmdArgs := []string{}
cmdArgs = append(cmdArgs, "build")
if *buildFlags != "" {
cmdArgs = append(cmdArgs, *buildFlags)
}
cmdArgs = append(cmdArgs, "-o", progBinary, progSource)
// Build the program.
cmd := exec.Command("go", cmdArgs...)
cmd.Dir = tmpDir
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return nil, err
}
return run(filepath.Join(tmpDir, progBinary))
} | go | func runInDir(program []byte, dir string) (*model.Package, error) {
// We use TempDir instead of TempFile so we can control the filename.
tmpDir, err := ioutil.TempDir(dir, "gomock_reflect_")
if err != nil {
return nil, err
}
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
log.Printf("failed to remove temp directory: %s", err)
}
}()
const progSource = "prog.go"
var progBinary = "prog.bin"
if runtime.GOOS == "windows" {
// Windows won't execute a program unless it has a ".exe" suffix.
progBinary += ".exe"
}
if err := ioutil.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil {
return nil, err
}
cmdArgs := []string{}
cmdArgs = append(cmdArgs, "build")
if *buildFlags != "" {
cmdArgs = append(cmdArgs, *buildFlags)
}
cmdArgs = append(cmdArgs, "-o", progBinary, progSource)
// Build the program.
cmd := exec.Command("go", cmdArgs...)
cmd.Dir = tmpDir
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return nil, err
}
return run(filepath.Join(tmpDir, progBinary))
} | [
"func",
"runInDir",
"(",
"program",
"[",
"]",
"byte",
",",
"dir",
"string",
")",
"(",
"*",
"model",
".",
"Package",
",",
"error",
")",
"{",
"// We use TempDir instead of TempFile so we can control the filename.",
"tmpDir",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"dir",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
":=",
"os",
".",
"RemoveAll",
"(",
"tmpDir",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"const",
"progSource",
"=",
"\"",
"\"",
"\n",
"var",
"progBinary",
"=",
"\"",
"\"",
"\n",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"// Windows won't execute a program unless it has a \".exe\" suffix.",
"progBinary",
"+=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"filepath",
".",
"Join",
"(",
"tmpDir",
",",
"progSource",
")",
",",
"program",
",",
"0600",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cmdArgs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"cmdArgs",
"=",
"append",
"(",
"cmdArgs",
",",
"\"",
"\"",
")",
"\n",
"if",
"*",
"buildFlags",
"!=",
"\"",
"\"",
"{",
"cmdArgs",
"=",
"append",
"(",
"cmdArgs",
",",
"*",
"buildFlags",
")",
"\n",
"}",
"\n",
"cmdArgs",
"=",
"append",
"(",
"cmdArgs",
",",
"\"",
"\"",
",",
"progBinary",
",",
"progSource",
")",
"\n\n",
"// Build the program.",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"cmdArgs",
"...",
")",
"\n",
"cmd",
".",
"Dir",
"=",
"tmpDir",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"run",
"(",
"filepath",
".",
"Join",
"(",
"tmpDir",
",",
"progBinary",
")",
")",
"\n",
"}"
] | // runInDir writes the given program into the given dir, runs it there, and
// parses the output as a model.Package. | [
"runInDir",
"writes",
"the",
"given",
"program",
"into",
"the",
"given",
"dir",
"runs",
"it",
"there",
"and",
"parses",
"the",
"output",
"as",
"a",
"model",
".",
"Package",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/reflect.go#L94-L132 | train |
golang/mock | sample/user.go | Remember | func Remember(index Index, keys []string, values []interface{}) {
for i, k := range keys {
index.Put(k, values[i])
}
err := index.NillableRet()
if err != nil {
log.Fatalf("Woah! %v", err)
}
if len(keys) > 0 && keys[0] == "a" {
index.Ellip("%d", 0, 1, 1, 2, 3)
index.Ellip("%d", 1, 3, 6, 10, 15)
index.EllipOnly("arg")
}
} | go | func Remember(index Index, keys []string, values []interface{}) {
for i, k := range keys {
index.Put(k, values[i])
}
err := index.NillableRet()
if err != nil {
log.Fatalf("Woah! %v", err)
}
if len(keys) > 0 && keys[0] == "a" {
index.Ellip("%d", 0, 1, 1, 2, 3)
index.Ellip("%d", 1, 3, 6, 10, 15)
index.EllipOnly("arg")
}
} | [
"func",
"Remember",
"(",
"index",
"Index",
",",
"keys",
"[",
"]",
"string",
",",
"values",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"for",
"i",
",",
"k",
":=",
"range",
"keys",
"{",
"index",
".",
"Put",
"(",
"k",
",",
"values",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"err",
":=",
"index",
".",
"NillableRet",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"keys",
")",
">",
"0",
"&&",
"keys",
"[",
"0",
"]",
"==",
"\"",
"\"",
"{",
"index",
".",
"Ellip",
"(",
"\"",
"\"",
",",
"0",
",",
"1",
",",
"1",
",",
"2",
",",
"3",
")",
"\n",
"index",
".",
"Ellip",
"(",
"\"",
"\"",
",",
"1",
",",
"3",
",",
"6",
",",
"10",
",",
"15",
")",
"\n",
"index",
".",
"EllipOnly",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // A function that we will test that uses the above interface.
// It takes a list of keys and values, and puts them in the index. | [
"A",
"function",
"that",
"we",
"will",
"test",
"that",
"uses",
"the",
"above",
"interface",
".",
"It",
"takes",
"a",
"list",
"of",
"keys",
"and",
"values",
"and",
"puts",
"them",
"in",
"the",
"index",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/user.go#L95-L108 | train |
golang/mock | gomock/call.go | MinTimes | func (c *Call) MinTimes(n int) *Call {
c.minCalls = n
if c.maxCalls == 1 {
c.maxCalls = 1e8
}
return c
} | go | func (c *Call) MinTimes(n int) *Call {
c.minCalls = n
if c.maxCalls == 1 {
c.maxCalls = 1e8
}
return c
} | [
"func",
"(",
"c",
"*",
"Call",
")",
"MinTimes",
"(",
"n",
"int",
")",
"*",
"Call",
"{",
"c",
".",
"minCalls",
"=",
"n",
"\n",
"if",
"c",
".",
"maxCalls",
"==",
"1",
"{",
"c",
".",
"maxCalls",
"=",
"1e8",
"\n",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // MinTimes requires the call to occur at least n times. If AnyTimes or MaxTimes have not been called, MinTimes also
// sets the maximum number of calls to infinity. | [
"MinTimes",
"requires",
"the",
"call",
"to",
"occur",
"at",
"least",
"n",
"times",
".",
"If",
"AnyTimes",
"or",
"MaxTimes",
"have",
"not",
"been",
"called",
"MinTimes",
"also",
"sets",
"the",
"maximum",
"number",
"of",
"calls",
"to",
"infinity",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/call.go#L87-L93 | train |
golang/mock | gomock/call.go | MaxTimes | func (c *Call) MaxTimes(n int) *Call {
c.maxCalls = n
if c.minCalls == 1 {
c.minCalls = 0
}
return c
} | go | func (c *Call) MaxTimes(n int) *Call {
c.maxCalls = n
if c.minCalls == 1 {
c.minCalls = 0
}
return c
} | [
"func",
"(",
"c",
"*",
"Call",
")",
"MaxTimes",
"(",
"n",
"int",
")",
"*",
"Call",
"{",
"c",
".",
"maxCalls",
"=",
"n",
"\n",
"if",
"c",
".",
"minCalls",
"==",
"1",
"{",
"c",
".",
"minCalls",
"=",
"0",
"\n",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // MaxTimes limits the number of calls to n times. If AnyTimes or MinTimes have not been called, MaxTimes also
// sets the minimum number of calls to 0. | [
"MaxTimes",
"limits",
"the",
"number",
"of",
"calls",
"to",
"n",
"times",
".",
"If",
"AnyTimes",
"or",
"MinTimes",
"have",
"not",
"been",
"called",
"MaxTimes",
"also",
"sets",
"the",
"minimum",
"number",
"of",
"calls",
"to",
"0",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/call.go#L97-L103 | train |
golang/mock | gomock/call.go | Return | func (c *Call) Return(rets ...interface{}) *Call {
c.t.Helper()
mt := c.methodType
if len(rets) != mt.NumOut() {
c.t.Fatalf("wrong number of arguments to Return for %T.%v: got %d, want %d [%s]",
c.receiver, c.method, len(rets), mt.NumOut(), c.origin)
}
for i, ret := range rets {
if got, want := reflect.TypeOf(ret), mt.Out(i); got == want {
// Identical types; nothing to do.
} else if got == nil {
// Nil needs special handling.
switch want.Kind() {
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
// ok
default:
c.t.Fatalf("argument %d to Return for %T.%v is nil, but %v is not nillable [%s]",
i, c.receiver, c.method, want, c.origin)
}
} else if got.AssignableTo(want) {
// Assignable type relation. Make the assignment now so that the generated code
// can return the values with a type assertion.
v := reflect.New(want).Elem()
v.Set(reflect.ValueOf(ret))
rets[i] = v.Interface()
} else {
c.t.Fatalf("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s]",
i, c.receiver, c.method, got, want, c.origin)
}
}
c.addAction(func([]interface{}) []interface{} {
return rets
})
return c
} | go | func (c *Call) Return(rets ...interface{}) *Call {
c.t.Helper()
mt := c.methodType
if len(rets) != mt.NumOut() {
c.t.Fatalf("wrong number of arguments to Return for %T.%v: got %d, want %d [%s]",
c.receiver, c.method, len(rets), mt.NumOut(), c.origin)
}
for i, ret := range rets {
if got, want := reflect.TypeOf(ret), mt.Out(i); got == want {
// Identical types; nothing to do.
} else if got == nil {
// Nil needs special handling.
switch want.Kind() {
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
// ok
default:
c.t.Fatalf("argument %d to Return for %T.%v is nil, but %v is not nillable [%s]",
i, c.receiver, c.method, want, c.origin)
}
} else if got.AssignableTo(want) {
// Assignable type relation. Make the assignment now so that the generated code
// can return the values with a type assertion.
v := reflect.New(want).Elem()
v.Set(reflect.ValueOf(ret))
rets[i] = v.Interface()
} else {
c.t.Fatalf("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s]",
i, c.receiver, c.method, got, want, c.origin)
}
}
c.addAction(func([]interface{}) []interface{} {
return rets
})
return c
} | [
"func",
"(",
"c",
"*",
"Call",
")",
"Return",
"(",
"rets",
"...",
"interface",
"{",
"}",
")",
"*",
"Call",
"{",
"c",
".",
"t",
".",
"Helper",
"(",
")",
"\n\n",
"mt",
":=",
"c",
".",
"methodType",
"\n",
"if",
"len",
"(",
"rets",
")",
"!=",
"mt",
".",
"NumOut",
"(",
")",
"{",
"c",
".",
"t",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"c",
".",
"receiver",
",",
"c",
".",
"method",
",",
"len",
"(",
"rets",
")",
",",
"mt",
".",
"NumOut",
"(",
")",
",",
"c",
".",
"origin",
")",
"\n",
"}",
"\n",
"for",
"i",
",",
"ret",
":=",
"range",
"rets",
"{",
"if",
"got",
",",
"want",
":=",
"reflect",
".",
"TypeOf",
"(",
"ret",
")",
",",
"mt",
".",
"Out",
"(",
"i",
")",
";",
"got",
"==",
"want",
"{",
"// Identical types; nothing to do.",
"}",
"else",
"if",
"got",
"==",
"nil",
"{",
"// Nil needs special handling.",
"switch",
"want",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Chan",
",",
"reflect",
".",
"Func",
",",
"reflect",
".",
"Interface",
",",
"reflect",
".",
"Map",
",",
"reflect",
".",
"Ptr",
",",
"reflect",
".",
"Slice",
":",
"// ok",
"default",
":",
"c",
".",
"t",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"i",
",",
"c",
".",
"receiver",
",",
"c",
".",
"method",
",",
"want",
",",
"c",
".",
"origin",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"got",
".",
"AssignableTo",
"(",
"want",
")",
"{",
"// Assignable type relation. Make the assignment now so that the generated code",
"// can return the values with a type assertion.",
"v",
":=",
"reflect",
".",
"New",
"(",
"want",
")",
".",
"Elem",
"(",
")",
"\n",
"v",
".",
"Set",
"(",
"reflect",
".",
"ValueOf",
"(",
"ret",
")",
")",
"\n",
"rets",
"[",
"i",
"]",
"=",
"v",
".",
"Interface",
"(",
")",
"\n",
"}",
"else",
"{",
"c",
".",
"t",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"i",
",",
"c",
".",
"receiver",
",",
"c",
".",
"method",
",",
"got",
",",
"want",
",",
"c",
".",
"origin",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
".",
"addAction",
"(",
"func",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"return",
"rets",
"\n",
"}",
")",
"\n\n",
"return",
"c",
"\n",
"}"
] | // Return declares the values to be returned by the mocked function call. | [
"Return",
"declares",
"the",
"values",
"to",
"be",
"returned",
"by",
"the",
"mocked",
"function",
"call",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/call.go#L159-L196 | train |
golang/mock | gomock/call.go | Times | func (c *Call) Times(n int) *Call {
c.minCalls, c.maxCalls = n, n
return c
} | go | func (c *Call) Times(n int) *Call {
c.minCalls, c.maxCalls = n, n
return c
} | [
"func",
"(",
"c",
"*",
"Call",
")",
"Times",
"(",
"n",
"int",
")",
"*",
"Call",
"{",
"c",
".",
"minCalls",
",",
"c",
".",
"maxCalls",
"=",
"n",
",",
"n",
"\n",
"return",
"c",
"\n",
"}"
] | // Times declares the exact number of times a function call is expected to be executed. | [
"Times",
"declares",
"the",
"exact",
"number",
"of",
"times",
"a",
"function",
"call",
"is",
"expected",
"to",
"be",
"executed",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/call.go#L199-L202 | train |
golang/mock | gomock/call.go | SetArg | func (c *Call) SetArg(n int, value interface{}) *Call {
c.t.Helper()
mt := c.methodType
// TODO: This will break on variadic methods.
// We will need to check those at invocation time.
if n < 0 || n >= mt.NumIn() {
c.t.Fatalf("SetArg(%d, ...) called for a method with %d args [%s]",
n, mt.NumIn(), c.origin)
}
// Permit setting argument through an interface.
// In the interface case, we don't (nay, can't) check the type here.
at := mt.In(n)
switch at.Kind() {
case reflect.Ptr:
dt := at.Elem()
if vt := reflect.TypeOf(value); !vt.AssignableTo(dt) {
c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]",
n, vt, dt, c.origin)
}
case reflect.Interface:
// nothing to do
case reflect.Slice:
// nothing to do
default:
c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice type %v [%s]",
n, at, c.origin)
}
c.addAction(func(args []interface{}) []interface{} {
v := reflect.ValueOf(value)
switch reflect.TypeOf(args[n]).Kind() {
case reflect.Slice:
setSlice(args[n], v)
default:
reflect.ValueOf(args[n]).Elem().Set(v)
}
return nil
})
return c
} | go | func (c *Call) SetArg(n int, value interface{}) *Call {
c.t.Helper()
mt := c.methodType
// TODO: This will break on variadic methods.
// We will need to check those at invocation time.
if n < 0 || n >= mt.NumIn() {
c.t.Fatalf("SetArg(%d, ...) called for a method with %d args [%s]",
n, mt.NumIn(), c.origin)
}
// Permit setting argument through an interface.
// In the interface case, we don't (nay, can't) check the type here.
at := mt.In(n)
switch at.Kind() {
case reflect.Ptr:
dt := at.Elem()
if vt := reflect.TypeOf(value); !vt.AssignableTo(dt) {
c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]",
n, vt, dt, c.origin)
}
case reflect.Interface:
// nothing to do
case reflect.Slice:
// nothing to do
default:
c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice type %v [%s]",
n, at, c.origin)
}
c.addAction(func(args []interface{}) []interface{} {
v := reflect.ValueOf(value)
switch reflect.TypeOf(args[n]).Kind() {
case reflect.Slice:
setSlice(args[n], v)
default:
reflect.ValueOf(args[n]).Elem().Set(v)
}
return nil
})
return c
} | [
"func",
"(",
"c",
"*",
"Call",
")",
"SetArg",
"(",
"n",
"int",
",",
"value",
"interface",
"{",
"}",
")",
"*",
"Call",
"{",
"c",
".",
"t",
".",
"Helper",
"(",
")",
"\n\n",
"mt",
":=",
"c",
".",
"methodType",
"\n",
"// TODO: This will break on variadic methods.",
"// We will need to check those at invocation time.",
"if",
"n",
"<",
"0",
"||",
"n",
">=",
"mt",
".",
"NumIn",
"(",
")",
"{",
"c",
".",
"t",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"n",
",",
"mt",
".",
"NumIn",
"(",
")",
",",
"c",
".",
"origin",
")",
"\n",
"}",
"\n",
"// Permit setting argument through an interface.",
"// In the interface case, we don't (nay, can't) check the type here.",
"at",
":=",
"mt",
".",
"In",
"(",
"n",
")",
"\n",
"switch",
"at",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Ptr",
":",
"dt",
":=",
"at",
".",
"Elem",
"(",
")",
"\n",
"if",
"vt",
":=",
"reflect",
".",
"TypeOf",
"(",
"value",
")",
";",
"!",
"vt",
".",
"AssignableTo",
"(",
"dt",
")",
"{",
"c",
".",
"t",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"n",
",",
"vt",
",",
"dt",
",",
"c",
".",
"origin",
")",
"\n",
"}",
"\n",
"case",
"reflect",
".",
"Interface",
":",
"// nothing to do",
"case",
"reflect",
".",
"Slice",
":",
"// nothing to do",
"default",
":",
"c",
".",
"t",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"n",
",",
"at",
",",
"c",
".",
"origin",
")",
"\n",
"}",
"\n\n",
"c",
".",
"addAction",
"(",
"func",
"(",
"args",
"[",
"]",
"interface",
"{",
"}",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
"\n",
"switch",
"reflect",
".",
"TypeOf",
"(",
"args",
"[",
"n",
"]",
")",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Slice",
":",
"setSlice",
"(",
"args",
"[",
"n",
"]",
",",
"v",
")",
"\n",
"default",
":",
"reflect",
".",
"ValueOf",
"(",
"args",
"[",
"n",
"]",
")",
".",
"Elem",
"(",
")",
".",
"Set",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // SetArg declares an action that will set the nth argument's value,
// indirected through a pointer. Or, in the case of a slice, SetArg
// will copy value's elements into the nth argument. | [
"SetArg",
"declares",
"an",
"action",
"that",
"will",
"set",
"the",
"nth",
"argument",
"s",
"value",
"indirected",
"through",
"a",
"pointer",
".",
"Or",
"in",
"the",
"case",
"of",
"a",
"slice",
"SetArg",
"will",
"copy",
"value",
"s",
"elements",
"into",
"the",
"nth",
"argument",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/call.go#L207-L247 | train |
golang/mock | gomock/call.go | isPreReq | func (c *Call) isPreReq(other *Call) bool {
for _, preReq := range c.preReqs {
if other == preReq || preReq.isPreReq(other) {
return true
}
}
return false
} | go | func (c *Call) isPreReq(other *Call) bool {
for _, preReq := range c.preReqs {
if other == preReq || preReq.isPreReq(other) {
return true
}
}
return false
} | [
"func",
"(",
"c",
"*",
"Call",
")",
"isPreReq",
"(",
"other",
"*",
"Call",
")",
"bool",
"{",
"for",
"_",
",",
"preReq",
":=",
"range",
"c",
".",
"preReqs",
"{",
"if",
"other",
"==",
"preReq",
"||",
"preReq",
".",
"isPreReq",
"(",
"other",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // isPreReq returns true if other is a direct or indirect prerequisite to c. | [
"isPreReq",
"returns",
"true",
"if",
"other",
"is",
"a",
"direct",
"or",
"indirect",
"prerequisite",
"to",
"c",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/call.go#L250-L257 | train |
golang/mock | gomock/call.go | After | func (c *Call) After(preReq *Call) *Call {
c.t.Helper()
if c == preReq {
c.t.Fatalf("A call isn't allowed to be its own prerequisite")
}
if preReq.isPreReq(c) {
c.t.Fatalf("Loop in call order: %v is a prerequisite to %v (possibly indirectly).", c, preReq)
}
c.preReqs = append(c.preReqs, preReq)
return c
} | go | func (c *Call) After(preReq *Call) *Call {
c.t.Helper()
if c == preReq {
c.t.Fatalf("A call isn't allowed to be its own prerequisite")
}
if preReq.isPreReq(c) {
c.t.Fatalf("Loop in call order: %v is a prerequisite to %v (possibly indirectly).", c, preReq)
}
c.preReqs = append(c.preReqs, preReq)
return c
} | [
"func",
"(",
"c",
"*",
"Call",
")",
"After",
"(",
"preReq",
"*",
"Call",
")",
"*",
"Call",
"{",
"c",
".",
"t",
".",
"Helper",
"(",
")",
"\n\n",
"if",
"c",
"==",
"preReq",
"{",
"c",
".",
"t",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"preReq",
".",
"isPreReq",
"(",
"c",
")",
"{",
"c",
".",
"t",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"c",
",",
"preReq",
")",
"\n",
"}",
"\n\n",
"c",
".",
"preReqs",
"=",
"append",
"(",
"c",
".",
"preReqs",
",",
"preReq",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // After declares that the call may only match after preReq has been exhausted. | [
"After",
"declares",
"that",
"the",
"call",
"may",
"only",
"match",
"after",
"preReq",
"has",
"been",
"exhausted",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/call.go#L260-L272 | train |
golang/mock | gomock/call.go | dropPrereqs | func (c *Call) dropPrereqs() (preReqs []*Call) {
preReqs = c.preReqs
c.preReqs = nil
return
} | go | func (c *Call) dropPrereqs() (preReqs []*Call) {
preReqs = c.preReqs
c.preReqs = nil
return
} | [
"func",
"(",
"c",
"*",
"Call",
")",
"dropPrereqs",
"(",
")",
"(",
"preReqs",
"[",
"]",
"*",
"Call",
")",
"{",
"preReqs",
"=",
"c",
".",
"preReqs",
"\n",
"c",
".",
"preReqs",
"=",
"nil",
"\n",
"return",
"\n",
"}"
] | // dropPrereqs tells the expected Call to not re-check prerequisite calls any
// longer, and to return its current set. | [
"dropPrereqs",
"tells",
"the",
"expected",
"Call",
"to",
"not",
"re",
"-",
"check",
"prerequisite",
"calls",
"any",
"longer",
"and",
"to",
"return",
"its",
"current",
"set",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/call.go#L393-L397 | train |
golang/mock | gomock/call.go | InOrder | func InOrder(calls ...*Call) {
for i := 1; i < len(calls); i++ {
calls[i].After(calls[i-1])
}
} | go | func InOrder(calls ...*Call) {
for i := 1; i < len(calls); i++ {
calls[i].After(calls[i-1])
}
} | [
"func",
"InOrder",
"(",
"calls",
"...",
"*",
"Call",
")",
"{",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"calls",
")",
";",
"i",
"++",
"{",
"calls",
"[",
"i",
"]",
".",
"After",
"(",
"calls",
"[",
"i",
"-",
"1",
"]",
")",
"\n",
"}",
"\n",
"}"
] | // InOrder declares that the given calls should occur in order. | [
"InOrder",
"declares",
"that",
"the",
"given",
"calls",
"should",
"occur",
"in",
"order",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/call.go#L405-L409 | train |
golang/mock | mockgen/mockgen.go | sanitize | func sanitize(s string) string {
t := ""
for _, r := range s {
if t == "" {
if unicode.IsLetter(r) || r == '_' {
t += string(r)
continue
}
} else {
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' {
t += string(r)
continue
}
}
t += "_"
}
if t == "_" {
t = "x"
}
return t
} | go | func sanitize(s string) string {
t := ""
for _, r := range s {
if t == "" {
if unicode.IsLetter(r) || r == '_' {
t += string(r)
continue
}
} else {
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' {
t += string(r)
continue
}
}
t += "_"
}
if t == "_" {
t = "x"
}
return t
} | [
"func",
"sanitize",
"(",
"s",
"string",
")",
"string",
"{",
"t",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"if",
"t",
"==",
"\"",
"\"",
"{",
"if",
"unicode",
".",
"IsLetter",
"(",
"r",
")",
"||",
"r",
"==",
"'_'",
"{",
"t",
"+=",
"string",
"(",
"r",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"unicode",
".",
"IsLetter",
"(",
"r",
")",
"||",
"unicode",
".",
"IsDigit",
"(",
"r",
")",
"||",
"r",
"==",
"'_'",
"{",
"t",
"+=",
"string",
"(",
"r",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"t",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"t",
"==",
"\"",
"\"",
"{",
"t",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"t",
"\n",
"}"
] | // sanitize cleans up a string to make a suitable package name. | [
"sanitize",
"cleans",
"up",
"a",
"string",
"to",
"make",
"a",
"suitable",
"package",
"name",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/mockgen.go#L215-L235 | train |
golang/mock | mockgen/mockgen.go | mockName | func (g *generator) mockName(typeName string) string {
if mockName, ok := g.mockNames[typeName]; ok {
return mockName
}
return "Mock" + typeName
} | go | func (g *generator) mockName(typeName string) string {
if mockName, ok := g.mockNames[typeName]; ok {
return mockName
}
return "Mock" + typeName
} | [
"func",
"(",
"g",
"*",
"generator",
")",
"mockName",
"(",
"typeName",
"string",
")",
"string",
"{",
"if",
"mockName",
",",
"ok",
":=",
"g",
".",
"mockNames",
"[",
"typeName",
"]",
";",
"ok",
"{",
"return",
"mockName",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
"+",
"typeName",
"\n",
"}"
] | // The name of the mock type to use for the given interface identifier. | [
"The",
"name",
"of",
"the",
"mock",
"type",
"to",
"use",
"for",
"the",
"given",
"interface",
"identifier",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/mockgen.go#L330-L336 | train |
golang/mock | mockgen/mockgen.go | GenerateMockMethod | func (g *generator) GenerateMockMethod(mockType string, m *model.Method, pkgOverride string) error {
argNames := g.getArgNames(m)
argTypes := g.getArgTypes(m, pkgOverride)
argString := makeArgString(argNames, argTypes)
rets := make([]string, len(m.Out))
for i, p := range m.Out {
rets[i] = p.Type.String(g.packageMap, pkgOverride)
}
retString := strings.Join(rets, ", ")
if len(rets) > 1 {
retString = "(" + retString + ")"
}
if retString != "" {
retString = " " + retString
}
ia := newIdentifierAllocator(argNames)
idRecv := ia.allocateIdentifier("m")
g.p("// %v mocks base method", m.Name)
g.p("func (%v *%v) %v(%v)%v {", idRecv, mockType, m.Name, argString, retString)
g.in()
g.p("%s.ctrl.T.Helper()", idRecv)
var callArgs string
if m.Variadic == nil {
if len(argNames) > 0 {
callArgs = ", " + strings.Join(argNames, ", ")
}
} else {
// Non-trivial. The generated code must build a []interface{},
// but the variadic argument may be any type.
idVarArgs := ia.allocateIdentifier("varargs")
idVArg := ia.allocateIdentifier("a")
g.p("%s := []interface{}{%s}", idVarArgs, strings.Join(argNames[:len(argNames)-1], ", "))
g.p("for _, %s := range %s {", idVArg, argNames[len(argNames)-1])
g.in()
g.p("%s = append(%s, %s)", idVarArgs, idVarArgs, idVArg)
g.out()
g.p("}")
callArgs = ", " + idVarArgs + "..."
}
if len(m.Out) == 0 {
g.p(`%v.ctrl.Call(%v, %q%v)`, idRecv, idRecv, m.Name, callArgs)
} else {
idRet := ia.allocateIdentifier("ret")
g.p(`%v := %v.ctrl.Call(%v, %q%v)`, idRet, idRecv, idRecv, m.Name, callArgs)
// Go does not allow "naked" type assertions on nil values, so we use the two-value form here.
// The value of that is either (x.(T), true) or (Z, false), where Z is the zero value for T.
// Happily, this coincides with the semantics we want here.
retNames := make([]string, len(rets))
for i, t := range rets {
retNames[i] = ia.allocateIdentifier(fmt.Sprintf("ret%d", i))
g.p("%s, _ := %s[%d].(%s)", retNames[i], idRet, i, t)
}
g.p("return " + strings.Join(retNames, ", "))
}
g.out()
g.p("}")
return nil
} | go | func (g *generator) GenerateMockMethod(mockType string, m *model.Method, pkgOverride string) error {
argNames := g.getArgNames(m)
argTypes := g.getArgTypes(m, pkgOverride)
argString := makeArgString(argNames, argTypes)
rets := make([]string, len(m.Out))
for i, p := range m.Out {
rets[i] = p.Type.String(g.packageMap, pkgOverride)
}
retString := strings.Join(rets, ", ")
if len(rets) > 1 {
retString = "(" + retString + ")"
}
if retString != "" {
retString = " " + retString
}
ia := newIdentifierAllocator(argNames)
idRecv := ia.allocateIdentifier("m")
g.p("// %v mocks base method", m.Name)
g.p("func (%v *%v) %v(%v)%v {", idRecv, mockType, m.Name, argString, retString)
g.in()
g.p("%s.ctrl.T.Helper()", idRecv)
var callArgs string
if m.Variadic == nil {
if len(argNames) > 0 {
callArgs = ", " + strings.Join(argNames, ", ")
}
} else {
// Non-trivial. The generated code must build a []interface{},
// but the variadic argument may be any type.
idVarArgs := ia.allocateIdentifier("varargs")
idVArg := ia.allocateIdentifier("a")
g.p("%s := []interface{}{%s}", idVarArgs, strings.Join(argNames[:len(argNames)-1], ", "))
g.p("for _, %s := range %s {", idVArg, argNames[len(argNames)-1])
g.in()
g.p("%s = append(%s, %s)", idVarArgs, idVarArgs, idVArg)
g.out()
g.p("}")
callArgs = ", " + idVarArgs + "..."
}
if len(m.Out) == 0 {
g.p(`%v.ctrl.Call(%v, %q%v)`, idRecv, idRecv, m.Name, callArgs)
} else {
idRet := ia.allocateIdentifier("ret")
g.p(`%v := %v.ctrl.Call(%v, %q%v)`, idRet, idRecv, idRecv, m.Name, callArgs)
// Go does not allow "naked" type assertions on nil values, so we use the two-value form here.
// The value of that is either (x.(T), true) or (Z, false), where Z is the zero value for T.
// Happily, this coincides with the semantics we want here.
retNames := make([]string, len(rets))
for i, t := range rets {
retNames[i] = ia.allocateIdentifier(fmt.Sprintf("ret%d", i))
g.p("%s, _ := %s[%d].(%s)", retNames[i], idRet, i, t)
}
g.p("return " + strings.Join(retNames, ", "))
}
g.out()
g.p("}")
return nil
} | [
"func",
"(",
"g",
"*",
"generator",
")",
"GenerateMockMethod",
"(",
"mockType",
"string",
",",
"m",
"*",
"model",
".",
"Method",
",",
"pkgOverride",
"string",
")",
"error",
"{",
"argNames",
":=",
"g",
".",
"getArgNames",
"(",
"m",
")",
"\n",
"argTypes",
":=",
"g",
".",
"getArgTypes",
"(",
"m",
",",
"pkgOverride",
")",
"\n",
"argString",
":=",
"makeArgString",
"(",
"argNames",
",",
"argTypes",
")",
"\n\n",
"rets",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"m",
".",
"Out",
")",
")",
"\n",
"for",
"i",
",",
"p",
":=",
"range",
"m",
".",
"Out",
"{",
"rets",
"[",
"i",
"]",
"=",
"p",
".",
"Type",
".",
"String",
"(",
"g",
".",
"packageMap",
",",
"pkgOverride",
")",
"\n",
"}",
"\n",
"retString",
":=",
"strings",
".",
"Join",
"(",
"rets",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"rets",
")",
">",
"1",
"{",
"retString",
"=",
"\"",
"\"",
"+",
"retString",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"retString",
"!=",
"\"",
"\"",
"{",
"retString",
"=",
"\"",
"\"",
"+",
"retString",
"\n",
"}",
"\n\n",
"ia",
":=",
"newIdentifierAllocator",
"(",
"argNames",
")",
"\n",
"idRecv",
":=",
"ia",
".",
"allocateIdentifier",
"(",
"\"",
"\"",
")",
"\n\n",
"g",
".",
"p",
"(",
"\"",
"\"",
",",
"m",
".",
"Name",
")",
"\n",
"g",
".",
"p",
"(",
"\"",
"\"",
",",
"idRecv",
",",
"mockType",
",",
"m",
".",
"Name",
",",
"argString",
",",
"retString",
")",
"\n",
"g",
".",
"in",
"(",
")",
"\n",
"g",
".",
"p",
"(",
"\"",
"\"",
",",
"idRecv",
")",
"\n\n",
"var",
"callArgs",
"string",
"\n",
"if",
"m",
".",
"Variadic",
"==",
"nil",
"{",
"if",
"len",
"(",
"argNames",
")",
">",
"0",
"{",
"callArgs",
"=",
"\"",
"\"",
"+",
"strings",
".",
"Join",
"(",
"argNames",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// Non-trivial. The generated code must build a []interface{},",
"// but the variadic argument may be any type.",
"idVarArgs",
":=",
"ia",
".",
"allocateIdentifier",
"(",
"\"",
"\"",
")",
"\n",
"idVArg",
":=",
"ia",
".",
"allocateIdentifier",
"(",
"\"",
"\"",
")",
"\n",
"g",
".",
"p",
"(",
"\"",
"\"",
",",
"idVarArgs",
",",
"strings",
".",
"Join",
"(",
"argNames",
"[",
":",
"len",
"(",
"argNames",
")",
"-",
"1",
"]",
",",
"\"",
"\"",
")",
")",
"\n",
"g",
".",
"p",
"(",
"\"",
"\"",
",",
"idVArg",
",",
"argNames",
"[",
"len",
"(",
"argNames",
")",
"-",
"1",
"]",
")",
"\n",
"g",
".",
"in",
"(",
")",
"\n",
"g",
".",
"p",
"(",
"\"",
"\"",
",",
"idVarArgs",
",",
"idVarArgs",
",",
"idVArg",
")",
"\n",
"g",
".",
"out",
"(",
")",
"\n",
"g",
".",
"p",
"(",
"\"",
"\"",
")",
"\n",
"callArgs",
"=",
"\"",
"\"",
"+",
"idVarArgs",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"len",
"(",
"m",
".",
"Out",
")",
"==",
"0",
"{",
"g",
".",
"p",
"(",
"`%v.ctrl.Call(%v, %q%v)`",
",",
"idRecv",
",",
"idRecv",
",",
"m",
".",
"Name",
",",
"callArgs",
")",
"\n",
"}",
"else",
"{",
"idRet",
":=",
"ia",
".",
"allocateIdentifier",
"(",
"\"",
"\"",
")",
"\n",
"g",
".",
"p",
"(",
"`%v := %v.ctrl.Call(%v, %q%v)`",
",",
"idRet",
",",
"idRecv",
",",
"idRecv",
",",
"m",
".",
"Name",
",",
"callArgs",
")",
"\n\n",
"// Go does not allow \"naked\" type assertions on nil values, so we use the two-value form here.",
"// The value of that is either (x.(T), true) or (Z, false), where Z is the zero value for T.",
"// Happily, this coincides with the semantics we want here.",
"retNames",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"rets",
")",
")",
"\n",
"for",
"i",
",",
"t",
":=",
"range",
"rets",
"{",
"retNames",
"[",
"i",
"]",
"=",
"ia",
".",
"allocateIdentifier",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
")",
")",
"\n",
"g",
".",
"p",
"(",
"\"",
"\"",
",",
"retNames",
"[",
"i",
"]",
",",
"idRet",
",",
"i",
",",
"t",
")",
"\n",
"}",
"\n",
"g",
".",
"p",
"(",
"\"",
"\"",
"+",
"strings",
".",
"Join",
"(",
"retNames",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"g",
".",
"out",
"(",
")",
"\n",
"g",
".",
"p",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // GenerateMockMethod generates a mock method implementation.
// If non-empty, pkgOverride is the package in which unqualified types reside. | [
"GenerateMockMethod",
"generates",
"a",
"mock",
"method",
"implementation",
".",
"If",
"non",
"-",
"empty",
"pkgOverride",
"is",
"the",
"package",
"in",
"which",
"unqualified",
"types",
"reside",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/mockgen.go#L411-L474 | train |
golang/mock | mockgen/mockgen.go | Output | func (g *generator) Output() []byte {
src, err := format.Source(g.buf.Bytes())
if err != nil {
log.Fatalf("Failed to format generated source code: %s\n%s", err, g.buf.String())
}
return src
} | go | func (g *generator) Output() []byte {
src, err := format.Source(g.buf.Bytes())
if err != nil {
log.Fatalf("Failed to format generated source code: %s\n%s", err, g.buf.String())
}
return src
} | [
"func",
"(",
"g",
"*",
"generator",
")",
"Output",
"(",
")",
"[",
"]",
"byte",
"{",
"src",
",",
"err",
":=",
"format",
".",
"Source",
"(",
"g",
".",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
",",
"g",
".",
"buf",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"src",
"\n",
"}"
] | // Output returns the generator's output, formatted in the standard Go style. | [
"Output",
"returns",
"the",
"generator",
"s",
"output",
"formatted",
"in",
"the",
"standard",
"Go",
"style",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/mockgen.go#L582-L588 | train |
golang/mock | gomock/callset.go | Add | func (cs callSet) Add(call *Call) {
key := callSetKey{call.receiver, call.method}
m := cs.expected
if call.exhausted() {
m = cs.exhausted
}
m[key] = append(m[key], call)
} | go | func (cs callSet) Add(call *Call) {
key := callSetKey{call.receiver, call.method}
m := cs.expected
if call.exhausted() {
m = cs.exhausted
}
m[key] = append(m[key], call)
} | [
"func",
"(",
"cs",
"callSet",
")",
"Add",
"(",
"call",
"*",
"Call",
")",
"{",
"key",
":=",
"callSetKey",
"{",
"call",
".",
"receiver",
",",
"call",
".",
"method",
"}",
"\n",
"m",
":=",
"cs",
".",
"expected",
"\n",
"if",
"call",
".",
"exhausted",
"(",
")",
"{",
"m",
"=",
"cs",
".",
"exhausted",
"\n",
"}",
"\n",
"m",
"[",
"key",
"]",
"=",
"append",
"(",
"m",
"[",
"key",
"]",
",",
"call",
")",
"\n",
"}"
] | // Add adds a new expected call. | [
"Add",
"adds",
"a",
"new",
"expected",
"call",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/callset.go#L42-L49 | train |
golang/mock | gomock/callset.go | Remove | func (cs callSet) Remove(call *Call) {
key := callSetKey{call.receiver, call.method}
calls := cs.expected[key]
for i, c := range calls {
if c == call {
// maintain order for remaining calls
cs.expected[key] = append(calls[:i], calls[i+1:]...)
cs.exhausted[key] = append(cs.exhausted[key], call)
break
}
}
} | go | func (cs callSet) Remove(call *Call) {
key := callSetKey{call.receiver, call.method}
calls := cs.expected[key]
for i, c := range calls {
if c == call {
// maintain order for remaining calls
cs.expected[key] = append(calls[:i], calls[i+1:]...)
cs.exhausted[key] = append(cs.exhausted[key], call)
break
}
}
} | [
"func",
"(",
"cs",
"callSet",
")",
"Remove",
"(",
"call",
"*",
"Call",
")",
"{",
"key",
":=",
"callSetKey",
"{",
"call",
".",
"receiver",
",",
"call",
".",
"method",
"}",
"\n",
"calls",
":=",
"cs",
".",
"expected",
"[",
"key",
"]",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"calls",
"{",
"if",
"c",
"==",
"call",
"{",
"// maintain order for remaining calls",
"cs",
".",
"expected",
"[",
"key",
"]",
"=",
"append",
"(",
"calls",
"[",
":",
"i",
"]",
",",
"calls",
"[",
"i",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"cs",
".",
"exhausted",
"[",
"key",
"]",
"=",
"append",
"(",
"cs",
".",
"exhausted",
"[",
"key",
"]",
",",
"call",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Remove removes an expected call. | [
"Remove",
"removes",
"an",
"expected",
"call",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/callset.go#L52-L63 | train |
golang/mock | gomock/callset.go | FindMatch | func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) (*Call, error) {
key := callSetKey{receiver, method}
// Search through the expected calls.
expected := cs.expected[key]
var callsErrors bytes.Buffer
for _, call := range expected {
err := call.matches(args)
if err != nil {
fmt.Fprintf(&callsErrors, "\n%v", err)
} else {
return call, nil
}
}
// If we haven't found a match then search through the exhausted calls so we
// get useful error messages.
exhausted := cs.exhausted[key]
for _, call := range exhausted {
if err := call.matches(args); err != nil {
fmt.Fprintf(&callsErrors, "\n%v", err)
}
}
if len(expected)+len(exhausted) == 0 {
fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method)
}
return nil, fmt.Errorf(callsErrors.String())
} | go | func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) (*Call, error) {
key := callSetKey{receiver, method}
// Search through the expected calls.
expected := cs.expected[key]
var callsErrors bytes.Buffer
for _, call := range expected {
err := call.matches(args)
if err != nil {
fmt.Fprintf(&callsErrors, "\n%v", err)
} else {
return call, nil
}
}
// If we haven't found a match then search through the exhausted calls so we
// get useful error messages.
exhausted := cs.exhausted[key]
for _, call := range exhausted {
if err := call.matches(args); err != nil {
fmt.Fprintf(&callsErrors, "\n%v", err)
}
}
if len(expected)+len(exhausted) == 0 {
fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method)
}
return nil, fmt.Errorf(callsErrors.String())
} | [
"func",
"(",
"cs",
"callSet",
")",
"FindMatch",
"(",
"receiver",
"interface",
"{",
"}",
",",
"method",
"string",
",",
"args",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"*",
"Call",
",",
"error",
")",
"{",
"key",
":=",
"callSetKey",
"{",
"receiver",
",",
"method",
"}",
"\n\n",
"// Search through the expected calls.",
"expected",
":=",
"cs",
".",
"expected",
"[",
"key",
"]",
"\n",
"var",
"callsErrors",
"bytes",
".",
"Buffer",
"\n",
"for",
"_",
",",
"call",
":=",
"range",
"expected",
"{",
"err",
":=",
"call",
".",
"matches",
"(",
"args",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"callsErrors",
",",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"return",
"call",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"// If we haven't found a match then search through the exhausted calls so we",
"// get useful error messages.",
"exhausted",
":=",
"cs",
".",
"exhausted",
"[",
"key",
"]",
"\n",
"for",
"_",
",",
"call",
":=",
"range",
"exhausted",
"{",
"if",
"err",
":=",
"call",
".",
"matches",
"(",
"args",
")",
";",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"callsErrors",
",",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"expected",
")",
"+",
"len",
"(",
"exhausted",
")",
"==",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"callsErrors",
",",
"\"",
"\"",
",",
"method",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"callsErrors",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // FindMatch searches for a matching call. Returns error with explanation message if no call matched. | [
"FindMatch",
"searches",
"for",
"a",
"matching",
"call",
".",
"Returns",
"error",
"with",
"explanation",
"message",
"if",
"no",
"call",
"matched",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/callset.go#L66-L95 | train |
golang/mock | gomock/callset.go | Failures | func (cs callSet) Failures() []*Call {
failures := make([]*Call, 0, len(cs.expected))
for _, calls := range cs.expected {
for _, call := range calls {
if !call.satisfied() {
failures = append(failures, call)
}
}
}
return failures
} | go | func (cs callSet) Failures() []*Call {
failures := make([]*Call, 0, len(cs.expected))
for _, calls := range cs.expected {
for _, call := range calls {
if !call.satisfied() {
failures = append(failures, call)
}
}
}
return failures
} | [
"func",
"(",
"cs",
"callSet",
")",
"Failures",
"(",
")",
"[",
"]",
"*",
"Call",
"{",
"failures",
":=",
"make",
"(",
"[",
"]",
"*",
"Call",
",",
"0",
",",
"len",
"(",
"cs",
".",
"expected",
")",
")",
"\n",
"for",
"_",
",",
"calls",
":=",
"range",
"cs",
".",
"expected",
"{",
"for",
"_",
",",
"call",
":=",
"range",
"calls",
"{",
"if",
"!",
"call",
".",
"satisfied",
"(",
")",
"{",
"failures",
"=",
"append",
"(",
"failures",
",",
"call",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"failures",
"\n",
"}"
] | // Failures returns the calls that are not satisfied. | [
"Failures",
"returns",
"the",
"calls",
"that",
"are",
"not",
"satisfied",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/callset.go#L98-L108 | train |
golang/mock | sample/mock_user/mock_user.go | NewMockIndex | func NewMockIndex(ctrl *gomock.Controller) *MockIndex {
mock := &MockIndex{ctrl: ctrl}
mock.recorder = &MockIndexMockRecorder{mock}
return mock
} | go | func NewMockIndex(ctrl *gomock.Controller) *MockIndex {
mock := &MockIndex{ctrl: ctrl}
mock.recorder = &MockIndexMockRecorder{mock}
return mock
} | [
"func",
"NewMockIndex",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockIndex",
"{",
"mock",
":=",
"&",
"MockIndex",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockIndexMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockIndex creates a new mock instance | [
"NewMockIndex",
"creates",
"a",
"new",
"mock",
"instance"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L35-L39 | train |
golang/mock | sample/mock_user/mock_user.go | Anon | func (m *MockIndex) Anon(arg0 string) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Anon", arg0)
} | go | func (m *MockIndex) Anon(arg0 string) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Anon", arg0)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"Anon",
"(",
"arg0",
"string",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // Anon mocks base method | [
"Anon",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L47-L50 | train |
golang/mock | sample/mock_user/mock_user.go | Anon | func (mr *MockIndexMockRecorder) Anon(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Anon", reflect.TypeOf((*MockIndex)(nil).Anon), arg0)
} | go | func (mr *MockIndexMockRecorder) Anon(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Anon", reflect.TypeOf((*MockIndex)(nil).Anon), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockIndexMockRecorder",
")",
"Anon",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockIndex",
")",
"(",
"nil",
")",
".",
"Anon",
")",
",",
"arg0",
")",
"\n",
"}"
] | // Anon indicates an expected call of Anon | [
"Anon",
"indicates",
"an",
"expected",
"call",
"of",
"Anon"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L53-L56 | train |
golang/mock | sample/mock_user/mock_user.go | Chan | func (m *MockIndex) Chan(arg0 chan int, arg1 chan<- hash.Hash) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Chan", arg0, arg1)
} | go | func (m *MockIndex) Chan(arg0 chan int, arg1 chan<- hash.Hash) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Chan", arg0, arg1)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"Chan",
"(",
"arg0",
"chan",
"int",
",",
"arg1",
"chan",
"<-",
"hash",
".",
"Hash",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"}"
] | // Chan mocks base method | [
"Chan",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L59-L62 | train |
golang/mock | sample/mock_user/mock_user.go | ConcreteRet | func (m *MockIndex) ConcreteRet() chan<- bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ConcreteRet")
ret0, _ := ret[0].(chan<- bool)
return ret0
} | go | func (m *MockIndex) ConcreteRet() chan<- bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ConcreteRet")
ret0, _ := ret[0].(chan<- bool)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"ConcreteRet",
"(",
")",
"chan",
"<-",
"bool",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"chan",
"<-",
"bool",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // ConcreteRet mocks base method | [
"ConcreteRet",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L71-L76 | train |
golang/mock | sample/mock_user/mock_user.go | Ellip | func (mr *MockIndexMockRecorder) Ellip(arg0 interface{}, arg1 ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{arg0}, arg1...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ellip", reflect.TypeOf((*MockIndex)(nil).Ellip), varargs...)
} | go | func (mr *MockIndexMockRecorder) Ellip(arg0 interface{}, arg1 ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{arg0}, arg1...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ellip", reflect.TypeOf((*MockIndex)(nil).Ellip), varargs...)
} | [
"func",
"(",
"mr",
"*",
"MockIndexMockRecorder",
")",
"Ellip",
"(",
"arg0",
"interface",
"{",
"}",
",",
"arg1",
"...",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"varargs",
":=",
"append",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"arg0",
"}",
",",
"arg1",
"...",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockIndex",
")",
"(",
"nil",
")",
".",
"Ellip",
")",
",",
"varargs",
"...",
")",
"\n",
"}"
] | // Ellip indicates an expected call of Ellip | [
"Ellip",
"indicates",
"an",
"expected",
"call",
"of",
"Ellip"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L95-L99 | train |
golang/mock | sample/mock_user/mock_user.go | EllipOnly | func (m *MockIndex) EllipOnly(arg0 ...string) {
m.ctrl.T.Helper()
varargs := []interface{}{}
for _, a := range arg0 {
varargs = append(varargs, a)
}
m.ctrl.Call(m, "EllipOnly", varargs...)
} | go | func (m *MockIndex) EllipOnly(arg0 ...string) {
m.ctrl.T.Helper()
varargs := []interface{}{}
for _, a := range arg0 {
varargs = append(varargs, a)
}
m.ctrl.Call(m, "EllipOnly", varargs...)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"EllipOnly",
"(",
"arg0",
"...",
"string",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"varargs",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"arg0",
"{",
"varargs",
"=",
"append",
"(",
"varargs",
",",
"a",
")",
"\n",
"}",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"varargs",
"...",
")",
"\n",
"}"
] | // EllipOnly mocks base method | [
"EllipOnly",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L102-L109 | train |
golang/mock | sample/mock_user/mock_user.go | ForeignFour | func (m *MockIndex) ForeignFour(arg0 imp4.Imp4) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignFour", arg0)
} | go | func (m *MockIndex) ForeignFour(arg0 imp4.Imp4) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignFour", arg0)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"ForeignFour",
"(",
"arg0",
"imp4",
".",
"Imp4",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // ForeignFour mocks base method | [
"ForeignFour",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L118-L121 | train |
golang/mock | sample/mock_user/mock_user.go | ForeignOne | func (m *MockIndex) ForeignOne(arg0 imp1.Imp1) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignOne", arg0)
} | go | func (m *MockIndex) ForeignOne(arg0 imp1.Imp1) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignOne", arg0)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"ForeignOne",
"(",
"arg0",
"imp1",
".",
"Imp1",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // ForeignOne mocks base method | [
"ForeignOne",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L130-L133 | train |
golang/mock | sample/mock_user/mock_user.go | ForeignThree | func (m *MockIndex) ForeignThree(arg0 imp3.Imp3) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignThree", arg0)
} | go | func (m *MockIndex) ForeignThree(arg0 imp3.Imp3) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignThree", arg0)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"ForeignThree",
"(",
"arg0",
"imp3",
".",
"Imp3",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // ForeignThree mocks base method | [
"ForeignThree",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L142-L145 | train |
golang/mock | sample/mock_user/mock_user.go | ForeignTwo | func (m *MockIndex) ForeignTwo(arg0 imp2.Imp2) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignTwo", arg0)
} | go | func (m *MockIndex) ForeignTwo(arg0 imp2.Imp2) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ForeignTwo", arg0)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"ForeignTwo",
"(",
"arg0",
"imp2",
".",
"Imp2",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // ForeignTwo mocks base method | [
"ForeignTwo",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L154-L157 | train |
golang/mock | sample/mock_user/mock_user.go | Func | func (m *MockIndex) Func(arg0 func(http.Request) (int, bool)) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Func", arg0)
} | go | func (m *MockIndex) Func(arg0 func(http.Request) (int, bool)) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Func", arg0)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"Func",
"(",
"arg0",
"func",
"(",
"http",
".",
"Request",
")",
"(",
"int",
",",
"bool",
")",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // Func mocks base method | [
"Func",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L166-L169 | train |
golang/mock | sample/mock_user/mock_user.go | GetTwo | func (m *MockIndex) GetTwo(arg0, arg1 string) (interface{}, interface{}) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetTwo", arg0, arg1)
ret0, _ := ret[0].(interface{})
ret1, _ := ret[1].(interface{})
return ret0, ret1
} | go | func (m *MockIndex) GetTwo(arg0, arg1 string) (interface{}, interface{}) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetTwo", arg0, arg1)
ret0, _ := ret[0].(interface{})
ret1, _ := ret[1].(interface{})
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"GetTwo",
"(",
"arg0",
",",
"arg1",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"interface",
"{",
"}",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"interface",
"{",
"}",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"interface",
"{",
"}",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // GetTwo mocks base method | [
"GetTwo",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L192-L198 | train |
golang/mock | sample/mock_user/mock_user.go | Map | func (m *MockIndex) Map(arg0 map[int]hash.Hash) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Map", arg0)
} | go | func (m *MockIndex) Map(arg0 map[int]hash.Hash) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Map", arg0)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"Map",
"(",
"arg0",
"map",
"[",
"int",
"]",
"hash",
".",
"Hash",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // Map mocks base method | [
"Map",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L207-L210 | train |
golang/mock | sample/mock_user/mock_user.go | NillableRet | func (m *MockIndex) NillableRet() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NillableRet")
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockIndex) NillableRet() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NillableRet")
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"NillableRet",
"(",
")",
"error",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // NillableRet mocks base method | [
"NillableRet",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L219-L224 | train |
golang/mock | sample/mock_user/mock_user.go | Other | func (m *MockIndex) Other() hash.Hash {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Other")
ret0, _ := ret[0].(hash.Hash)
return ret0
} | go | func (m *MockIndex) Other() hash.Hash {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Other")
ret0, _ := ret[0].(hash.Hash)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"Other",
"(",
")",
"hash",
".",
"Hash",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"hash",
".",
"Hash",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Other mocks base method | [
"Other",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L233-L238 | train |
golang/mock | sample/mock_user/mock_user.go | Ptr | func (m *MockIndex) Ptr(arg0 *int) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Ptr", arg0)
} | go | func (m *MockIndex) Ptr(arg0 *int) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Ptr", arg0)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"Ptr",
"(",
"arg0",
"*",
"int",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // Ptr mocks base method | [
"Ptr",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L247-L250 | train |
golang/mock | sample/mock_user/mock_user.go | Slice | func (m *MockIndex) Slice(arg0 []int, arg1 []byte) [3]int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Slice", arg0, arg1)
ret0, _ := ret[0].([3]int)
return ret0
} | go | func (m *MockIndex) Slice(arg0 []int, arg1 []byte) [3]int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Slice", arg0, arg1)
ret0, _ := ret[0].([3]int)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"Slice",
"(",
"arg0",
"[",
"]",
"int",
",",
"arg1",
"[",
"]",
"byte",
")",
"[",
"3",
"]",
"int",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"[",
"3",
"]",
"int",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Slice mocks base method | [
"Slice",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L271-L276 | train |
golang/mock | sample/mock_user/mock_user.go | Struct | func (m *MockIndex) Struct(arg0 struct{}) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Struct", arg0)
} | go | func (m *MockIndex) Struct(arg0 struct{}) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Struct", arg0)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"Struct",
"(",
"arg0",
"struct",
"{",
"}",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // Struct mocks base method | [
"Struct",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L285-L288 | train |
golang/mock | sample/mock_user/mock_user.go | StructChan | func (m *MockIndex) StructChan(arg0 chan struct{}) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "StructChan", arg0)
} | go | func (m *MockIndex) StructChan(arg0 chan struct{}) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "StructChan", arg0)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"StructChan",
"(",
"arg0",
"chan",
"struct",
"{",
"}",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"}"
] | // StructChan mocks base method | [
"StructChan",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L297-L300 | train |
golang/mock | sample/mock_user/mock_user.go | Summary | func (m *MockIndex) Summary(arg0 *bytes.Buffer, arg1 io.Writer) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Summary", arg0, arg1)
} | go | func (m *MockIndex) Summary(arg0 *bytes.Buffer, arg1 io.Writer) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Summary", arg0, arg1)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"Summary",
"(",
"arg0",
"*",
"bytes",
".",
"Buffer",
",",
"arg1",
"io",
".",
"Writer",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"}"
] | // Summary mocks base method | [
"Summary",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L309-L312 | train |
golang/mock | sample/mock_user/mock_user.go | Templates | func (m *MockIndex) Templates(arg0 template.CSS, arg1 template0.FuncMap) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Templates", arg0, arg1)
} | go | func (m *MockIndex) Templates(arg0 template.CSS, arg1 template0.FuncMap) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Templates", arg0, arg1)
} | [
"func",
"(",
"m",
"*",
"MockIndex",
")",
"Templates",
"(",
"arg0",
"template",
".",
"CSS",
",",
"arg1",
"template0",
".",
"FuncMap",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"}"
] | // Templates mocks base method | [
"Templates",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L321-L324 | train |
golang/mock | sample/mock_user/mock_user.go | NewMockEmbed | func NewMockEmbed(ctrl *gomock.Controller) *MockEmbed {
mock := &MockEmbed{ctrl: ctrl}
mock.recorder = &MockEmbedMockRecorder{mock}
return mock
} | go | func NewMockEmbed(ctrl *gomock.Controller) *MockEmbed {
mock := &MockEmbed{ctrl: ctrl}
mock.recorder = &MockEmbedMockRecorder{mock}
return mock
} | [
"func",
"NewMockEmbed",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockEmbed",
"{",
"mock",
":=",
"&",
"MockEmbed",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockEmbedMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockEmbed creates a new mock instance | [
"NewMockEmbed",
"creates",
"a",
"new",
"mock",
"instance"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L344-L348 | train |
golang/mock | sample/mock_user/mock_user.go | ForeignEmbeddedMethod | func (m *MockEmbed) ForeignEmbeddedMethod() *bufio.Reader {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ForeignEmbeddedMethod")
ret0, _ := ret[0].(*bufio.Reader)
return ret0
} | go | func (m *MockEmbed) ForeignEmbeddedMethod() *bufio.Reader {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ForeignEmbeddedMethod")
ret0, _ := ret[0].(*bufio.Reader)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockEmbed",
")",
"ForeignEmbeddedMethod",
"(",
")",
"*",
"bufio",
".",
"Reader",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"bufio",
".",
"Reader",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // ForeignEmbeddedMethod mocks base method | [
"ForeignEmbeddedMethod",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L368-L373 | train |
golang/mock | sample/mock_user/mock_user.go | ForeignEmbeddedMethod | func (mr *MockEmbedMockRecorder) ForeignEmbeddedMethod() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ForeignEmbeddedMethod", reflect.TypeOf((*MockEmbed)(nil).ForeignEmbeddedMethod))
} | go | func (mr *MockEmbedMockRecorder) ForeignEmbeddedMethod() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ForeignEmbeddedMethod", reflect.TypeOf((*MockEmbed)(nil).ForeignEmbeddedMethod))
} | [
"func",
"(",
"mr",
"*",
"MockEmbedMockRecorder",
")",
"ForeignEmbeddedMethod",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockEmbed",
")",
"(",
"nil",
")",
".",
"ForeignEmbeddedMethod",
")",
")",
"\n",
"}"
] | // ForeignEmbeddedMethod indicates an expected call of ForeignEmbeddedMethod | [
"ForeignEmbeddedMethod",
"indicates",
"an",
"expected",
"call",
"of",
"ForeignEmbeddedMethod"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L376-L379 | train |
golang/mock | sample/mock_user/mock_user.go | ImplicitPackage | func (m *MockEmbed) ImplicitPackage(arg0 string, arg1 imp1.ImpT, arg2 []imp1.ImpT, arg3 *imp1.ImpT, arg4 chan imp1.ImpT) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ImplicitPackage", arg0, arg1, arg2, arg3, arg4)
} | go | func (m *MockEmbed) ImplicitPackage(arg0 string, arg1 imp1.ImpT, arg2 []imp1.ImpT, arg3 *imp1.ImpT, arg4 chan imp1.ImpT) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "ImplicitPackage", arg0, arg1, arg2, arg3, arg4)
} | [
"func",
"(",
"m",
"*",
"MockEmbed",
")",
"ImplicitPackage",
"(",
"arg0",
"string",
",",
"arg1",
"imp1",
".",
"ImpT",
",",
"arg2",
"[",
"]",
"imp1",
".",
"ImpT",
",",
"arg3",
"*",
"imp1",
".",
"ImpT",
",",
"arg4",
"chan",
"imp1",
".",
"ImpT",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
")",
"\n",
"}"
] | // ImplicitPackage mocks base method | [
"ImplicitPackage",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L382-L385 | train |
golang/mock | sample/mock_user/mock_user.go | ImplicitPackage | func (mr *MockEmbedMockRecorder) ImplicitPackage(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImplicitPackage", reflect.TypeOf((*MockEmbed)(nil).ImplicitPackage), arg0, arg1, arg2, arg3, arg4)
} | go | func (mr *MockEmbedMockRecorder) ImplicitPackage(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImplicitPackage", reflect.TypeOf((*MockEmbed)(nil).ImplicitPackage), arg0, arg1, arg2, arg3, arg4)
} | [
"func",
"(",
"mr",
"*",
"MockEmbedMockRecorder",
")",
"ImplicitPackage",
"(",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockEmbed",
")",
"(",
"nil",
")",
".",
"ImplicitPackage",
")",
",",
"arg0",
",",
"arg1",
",",
"arg2",
",",
"arg3",
",",
"arg4",
")",
"\n",
"}"
] | // ImplicitPackage indicates an expected call of ImplicitPackage | [
"ImplicitPackage",
"indicates",
"an",
"expected",
"call",
"of",
"ImplicitPackage"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L388-L391 | train |
golang/mock | sample/mock_user/mock_user.go | RegularMethod | func (m *MockEmbed) RegularMethod() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegularMethod")
} | go | func (m *MockEmbed) RegularMethod() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegularMethod")
} | [
"func",
"(",
"m",
"*",
"MockEmbed",
")",
"RegularMethod",
"(",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // RegularMethod mocks base method | [
"RegularMethod",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L394-L397 | train |
golang/mock | sample/mock_user/mock_user.go | NewMockEmbedded | func NewMockEmbedded(ctrl *gomock.Controller) *MockEmbedded {
mock := &MockEmbedded{ctrl: ctrl}
mock.recorder = &MockEmbeddedMockRecorder{mock}
return mock
} | go | func NewMockEmbedded(ctrl *gomock.Controller) *MockEmbedded {
mock := &MockEmbedded{ctrl: ctrl}
mock.recorder = &MockEmbeddedMockRecorder{mock}
return mock
} | [
"func",
"NewMockEmbedded",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockEmbedded",
"{",
"mock",
":=",
"&",
"MockEmbedded",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockEmbeddedMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockEmbedded creates a new mock instance | [
"NewMockEmbedded",
"creates",
"a",
"new",
"mock",
"instance"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L417-L421 | train |
golang/mock | sample/mock_user/mock_user.go | EmbeddedMethod | func (mr *MockEmbeddedMockRecorder) EmbeddedMethod() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedMethod", reflect.TypeOf((*MockEmbedded)(nil).EmbeddedMethod))
} | go | func (mr *MockEmbeddedMockRecorder) EmbeddedMethod() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedMethod", reflect.TypeOf((*MockEmbedded)(nil).EmbeddedMethod))
} | [
"func",
"(",
"mr",
"*",
"MockEmbeddedMockRecorder",
")",
"EmbeddedMethod",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockEmbedded",
")",
"(",
"nil",
")",
".",
"EmbeddedMethod",
")",
")",
"\n",
"}"
] | // EmbeddedMethod indicates an expected call of EmbeddedMethod | [
"EmbeddedMethod",
"indicates",
"an",
"expected",
"call",
"of",
"EmbeddedMethod"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/sample/mock_user/mock_user.go#L435-L438 | train |
golang/mock | gomock/internal/mock_gomock/mock_matcher.go | NewMockMatcher | func NewMockMatcher(ctrl *gomock.Controller) *MockMatcher {
mock := &MockMatcher{ctrl: ctrl}
mock.recorder = &MockMatcherMockRecorder{mock}
return mock
} | go | func NewMockMatcher(ctrl *gomock.Controller) *MockMatcher {
mock := &MockMatcher{ctrl: ctrl}
mock.recorder = &MockMatcherMockRecorder{mock}
return mock
} | [
"func",
"NewMockMatcher",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockMatcher",
"{",
"mock",
":=",
"&",
"MockMatcher",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockMatcherMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockMatcher creates a new mock instance | [
"NewMockMatcher",
"creates",
"a",
"new",
"mock",
"instance"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/internal/mock_gomock/mock_matcher.go#L24-L28 | train |
golang/mock | gomock/internal/mock_gomock/mock_matcher.go | Matches | func (m *MockMatcher) Matches(arg0 interface{}) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Matches", arg0)
ret0, _ := ret[0].(bool)
return ret0
} | go | func (m *MockMatcher) Matches(arg0 interface{}) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Matches", arg0)
ret0, _ := ret[0].(bool)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMatcher",
")",
"Matches",
"(",
"arg0",
"interface",
"{",
"}",
")",
"bool",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"bool",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Matches mocks base method | [
"Matches",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/internal/mock_gomock/mock_matcher.go#L36-L41 | train |
golang/mock | gomock/internal/mock_gomock/mock_matcher.go | Matches | func (mr *MockMatcherMockRecorder) Matches(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Matches", reflect.TypeOf((*MockMatcher)(nil).Matches), arg0)
} | go | func (mr *MockMatcherMockRecorder) Matches(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Matches", reflect.TypeOf((*MockMatcher)(nil).Matches), arg0)
} | [
"func",
"(",
"mr",
"*",
"MockMatcherMockRecorder",
")",
"Matches",
"(",
"arg0",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockMatcher",
")",
"(",
"nil",
")",
".",
"Matches",
")",
",",
"arg0",
")",
"\n",
"}"
] | // Matches indicates an expected call of Matches | [
"Matches",
"indicates",
"an",
"expected",
"call",
"of",
"Matches"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/internal/mock_gomock/mock_matcher.go#L44-L47 | train |
golang/mock | gomock/internal/mock_gomock/mock_matcher.go | String | func (m *MockMatcher) String() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "String")
ret0, _ := ret[0].(string)
return ret0
} | go | func (m *MockMatcher) String() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "String")
ret0, _ := ret[0].(string)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockMatcher",
")",
"String",
"(",
")",
"string",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"string",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // String mocks base method | [
"String",
"mocks",
"base",
"method"
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/internal/mock_gomock/mock_matcher.go#L50-L55 | train |
golang/mock | mockgen/parse.go | parseFile | func (p *fileParser) parseFile(importPath string, file *ast.File) (*model.Package, error) {
allImports, dotImports := importsOfFile(file)
// Don't stomp imports provided by -imports. Those should take precedence.
for pkg, path := range allImports {
if _, ok := p.imports[pkg]; !ok {
p.imports[pkg] = path
}
}
// Add imports from auxiliary files, which might be needed for embedded interfaces.
// Don't stomp any other imports.
for _, f := range p.auxFiles {
auxImports, _ := importsOfFile(f)
for pkg, path := range auxImports {
if _, ok := p.imports[pkg]; !ok {
p.imports[pkg] = path
}
}
}
var is []*model.Interface
for ni := range iterInterfaces(file) {
i, err := p.parseInterface(ni.name.String(), importPath, ni.it)
if err != nil {
return nil, err
}
is = append(is, i)
}
return &model.Package{
Name: file.Name.String(),
Interfaces: is,
DotImports: dotImports,
}, nil
} | go | func (p *fileParser) parseFile(importPath string, file *ast.File) (*model.Package, error) {
allImports, dotImports := importsOfFile(file)
// Don't stomp imports provided by -imports. Those should take precedence.
for pkg, path := range allImports {
if _, ok := p.imports[pkg]; !ok {
p.imports[pkg] = path
}
}
// Add imports from auxiliary files, which might be needed for embedded interfaces.
// Don't stomp any other imports.
for _, f := range p.auxFiles {
auxImports, _ := importsOfFile(f)
for pkg, path := range auxImports {
if _, ok := p.imports[pkg]; !ok {
p.imports[pkg] = path
}
}
}
var is []*model.Interface
for ni := range iterInterfaces(file) {
i, err := p.parseInterface(ni.name.String(), importPath, ni.it)
if err != nil {
return nil, err
}
is = append(is, i)
}
return &model.Package{
Name: file.Name.String(),
Interfaces: is,
DotImports: dotImports,
}, nil
} | [
"func",
"(",
"p",
"*",
"fileParser",
")",
"parseFile",
"(",
"importPath",
"string",
",",
"file",
"*",
"ast",
".",
"File",
")",
"(",
"*",
"model",
".",
"Package",
",",
"error",
")",
"{",
"allImports",
",",
"dotImports",
":=",
"importsOfFile",
"(",
"file",
")",
"\n",
"// Don't stomp imports provided by -imports. Those should take precedence.",
"for",
"pkg",
",",
"path",
":=",
"range",
"allImports",
"{",
"if",
"_",
",",
"ok",
":=",
"p",
".",
"imports",
"[",
"pkg",
"]",
";",
"!",
"ok",
"{",
"p",
".",
"imports",
"[",
"pkg",
"]",
"=",
"path",
"\n",
"}",
"\n",
"}",
"\n",
"// Add imports from auxiliary files, which might be needed for embedded interfaces.",
"// Don't stomp any other imports.",
"for",
"_",
",",
"f",
":=",
"range",
"p",
".",
"auxFiles",
"{",
"auxImports",
",",
"_",
":=",
"importsOfFile",
"(",
"f",
")",
"\n",
"for",
"pkg",
",",
"path",
":=",
"range",
"auxImports",
"{",
"if",
"_",
",",
"ok",
":=",
"p",
".",
"imports",
"[",
"pkg",
"]",
";",
"!",
"ok",
"{",
"p",
".",
"imports",
"[",
"pkg",
"]",
"=",
"path",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"is",
"[",
"]",
"*",
"model",
".",
"Interface",
"\n",
"for",
"ni",
":=",
"range",
"iterInterfaces",
"(",
"file",
")",
"{",
"i",
",",
"err",
":=",
"p",
".",
"parseInterface",
"(",
"ni",
".",
"name",
".",
"String",
"(",
")",
",",
"importPath",
",",
"ni",
".",
"it",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"is",
"=",
"append",
"(",
"is",
",",
"i",
")",
"\n",
"}",
"\n",
"return",
"&",
"model",
".",
"Package",
"{",
"Name",
":",
"file",
".",
"Name",
".",
"String",
"(",
")",
",",
"Interfaces",
":",
"is",
",",
"DotImports",
":",
"dotImports",
",",
"}",
",",
"nil",
"\n",
"}"
] | // parseFile loads all file imports and auxiliary files import into the
// fileParser, parses all file interfaces and returns package model. | [
"parseFile",
"loads",
"all",
"file",
"imports",
"and",
"auxiliary",
"files",
"import",
"into",
"the",
"fileParser",
"parses",
"all",
"file",
"interfaces",
"and",
"returns",
"package",
"model",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/parse.go#L161-L193 | train |
golang/mock | mockgen/parse.go | parsePackage | func (p *fileParser) parsePackage(path string) error {
var pkgs map[string]*ast.Package
if imp, err := build.Import(path, p.srcDir, build.FindOnly); err != nil {
return err
} else if pkgs, err = parser.ParseDir(p.fileSet, imp.Dir, nil, 0); err != nil {
return err
}
for _, pkg := range pkgs {
file := ast.MergePackageFiles(pkg, ast.FilterFuncDuplicates|ast.FilterUnassociatedComments|ast.FilterImportDuplicates)
if _, ok := p.importedInterfaces[path]; !ok {
p.importedInterfaces[path] = make(map[string]*ast.InterfaceType)
}
for ni := range iterInterfaces(file) {
p.importedInterfaces[path][ni.name.Name] = ni.it
}
imports, _ := importsOfFile(file)
for pkgName, pkgPath := range imports {
if _, ok := p.imports[pkgName]; !ok {
p.imports[pkgName] = pkgPath
}
}
}
return nil
} | go | func (p *fileParser) parsePackage(path string) error {
var pkgs map[string]*ast.Package
if imp, err := build.Import(path, p.srcDir, build.FindOnly); err != nil {
return err
} else if pkgs, err = parser.ParseDir(p.fileSet, imp.Dir, nil, 0); err != nil {
return err
}
for _, pkg := range pkgs {
file := ast.MergePackageFiles(pkg, ast.FilterFuncDuplicates|ast.FilterUnassociatedComments|ast.FilterImportDuplicates)
if _, ok := p.importedInterfaces[path]; !ok {
p.importedInterfaces[path] = make(map[string]*ast.InterfaceType)
}
for ni := range iterInterfaces(file) {
p.importedInterfaces[path][ni.name.Name] = ni.it
}
imports, _ := importsOfFile(file)
for pkgName, pkgPath := range imports {
if _, ok := p.imports[pkgName]; !ok {
p.imports[pkgName] = pkgPath
}
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"fileParser",
")",
"parsePackage",
"(",
"path",
"string",
")",
"error",
"{",
"var",
"pkgs",
"map",
"[",
"string",
"]",
"*",
"ast",
".",
"Package",
"\n",
"if",
"imp",
",",
"err",
":=",
"build",
".",
"Import",
"(",
"path",
",",
"p",
".",
"srcDir",
",",
"build",
".",
"FindOnly",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"else",
"if",
"pkgs",
",",
"err",
"=",
"parser",
".",
"ParseDir",
"(",
"p",
".",
"fileSet",
",",
"imp",
".",
"Dir",
",",
"nil",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"pkg",
":=",
"range",
"pkgs",
"{",
"file",
":=",
"ast",
".",
"MergePackageFiles",
"(",
"pkg",
",",
"ast",
".",
"FilterFuncDuplicates",
"|",
"ast",
".",
"FilterUnassociatedComments",
"|",
"ast",
".",
"FilterImportDuplicates",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"p",
".",
"importedInterfaces",
"[",
"path",
"]",
";",
"!",
"ok",
"{",
"p",
".",
"importedInterfaces",
"[",
"path",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ast",
".",
"InterfaceType",
")",
"\n",
"}",
"\n",
"for",
"ni",
":=",
"range",
"iterInterfaces",
"(",
"file",
")",
"{",
"p",
".",
"importedInterfaces",
"[",
"path",
"]",
"[",
"ni",
".",
"name",
".",
"Name",
"]",
"=",
"ni",
".",
"it",
"\n",
"}",
"\n",
"imports",
",",
"_",
":=",
"importsOfFile",
"(",
"file",
")",
"\n",
"for",
"pkgName",
",",
"pkgPath",
":=",
"range",
"imports",
"{",
"if",
"_",
",",
"ok",
":=",
"p",
".",
"imports",
"[",
"pkgName",
"]",
";",
"!",
"ok",
"{",
"p",
".",
"imports",
"[",
"pkgName",
"]",
"=",
"pkgPath",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // parsePackage loads package specified by path, parses it and populates
// corresponding imports and importedInterfaces into the fileParser. | [
"parsePackage",
"loads",
"package",
"specified",
"by",
"path",
"parses",
"it",
"and",
"populates",
"corresponding",
"imports",
"and",
"importedInterfaces",
"into",
"the",
"fileParser",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/parse.go#L197-L220 | train |
golang/mock | mockgen/parse.go | importsOfFile | func importsOfFile(file *ast.File) (normalImports map[string]string, dotImports []string) {
normalImports = make(map[string]string)
dotImports = make([]string, 0)
for _, is := range file.Imports {
var pkgName string
importPath := is.Path.Value[1 : len(is.Path.Value)-1] // remove quotes
if is.Name != nil {
// Named imports are always certain.
if is.Name.Name == "_" {
continue
}
pkgName = is.Name.Name
} else {
pkg, err := build.Import(importPath, "", 0)
if err != nil {
// Fallback to import path suffix. Note that this is uncertain.
_, last := path.Split(importPath)
// If the last path component has dots, the first dot-delimited
// field is used as the name.
pkgName = strings.SplitN(last, ".", 2)[0]
} else {
pkgName = pkg.Name
}
}
if pkgName == "." {
dotImports = append(dotImports, importPath)
} else {
if _, ok := normalImports[pkgName]; ok {
log.Fatalf("imported package collision: %q imported twice", pkgName)
}
normalImports[pkgName] = importPath
}
}
return
} | go | func importsOfFile(file *ast.File) (normalImports map[string]string, dotImports []string) {
normalImports = make(map[string]string)
dotImports = make([]string, 0)
for _, is := range file.Imports {
var pkgName string
importPath := is.Path.Value[1 : len(is.Path.Value)-1] // remove quotes
if is.Name != nil {
// Named imports are always certain.
if is.Name.Name == "_" {
continue
}
pkgName = is.Name.Name
} else {
pkg, err := build.Import(importPath, "", 0)
if err != nil {
// Fallback to import path suffix. Note that this is uncertain.
_, last := path.Split(importPath)
// If the last path component has dots, the first dot-delimited
// field is used as the name.
pkgName = strings.SplitN(last, ".", 2)[0]
} else {
pkgName = pkg.Name
}
}
if pkgName == "." {
dotImports = append(dotImports, importPath)
} else {
if _, ok := normalImports[pkgName]; ok {
log.Fatalf("imported package collision: %q imported twice", pkgName)
}
normalImports[pkgName] = importPath
}
}
return
} | [
"func",
"importsOfFile",
"(",
"file",
"*",
"ast",
".",
"File",
")",
"(",
"normalImports",
"map",
"[",
"string",
"]",
"string",
",",
"dotImports",
"[",
"]",
"string",
")",
"{",
"normalImports",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"dotImports",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"_",
",",
"is",
":=",
"range",
"file",
".",
"Imports",
"{",
"var",
"pkgName",
"string",
"\n",
"importPath",
":=",
"is",
".",
"Path",
".",
"Value",
"[",
"1",
":",
"len",
"(",
"is",
".",
"Path",
".",
"Value",
")",
"-",
"1",
"]",
"// remove quotes",
"\n\n",
"if",
"is",
".",
"Name",
"!=",
"nil",
"{",
"// Named imports are always certain.",
"if",
"is",
".",
"Name",
".",
"Name",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"pkgName",
"=",
"is",
".",
"Name",
".",
"Name",
"\n",
"}",
"else",
"{",
"pkg",
",",
"err",
":=",
"build",
".",
"Import",
"(",
"importPath",
",",
"\"",
"\"",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Fallback to import path suffix. Note that this is uncertain.",
"_",
",",
"last",
":=",
"path",
".",
"Split",
"(",
"importPath",
")",
"\n",
"// If the last path component has dots, the first dot-delimited",
"// field is used as the name.",
"pkgName",
"=",
"strings",
".",
"SplitN",
"(",
"last",
",",
"\"",
"\"",
",",
"2",
")",
"[",
"0",
"]",
"\n",
"}",
"else",
"{",
"pkgName",
"=",
"pkg",
".",
"Name",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"pkgName",
"==",
"\"",
"\"",
"{",
"dotImports",
"=",
"append",
"(",
"dotImports",
",",
"importPath",
")",
"\n",
"}",
"else",
"{",
"if",
"_",
",",
"ok",
":=",
"normalImports",
"[",
"pkgName",
"]",
";",
"ok",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"pkgName",
")",
"\n",
"}",
"\n",
"normalImports",
"[",
"pkgName",
"]",
"=",
"importPath",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // importsOfFile returns a map of package name to import path
// of the imports in file. | [
"importsOfFile",
"returns",
"a",
"map",
"of",
"package",
"name",
"to",
"import",
"path",
"of",
"the",
"imports",
"in",
"file",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/parse.go#L444-L481 | train |
golang/mock | mockgen/parse.go | iterInterfaces | func iterInterfaces(file *ast.File) <-chan namedInterface {
ch := make(chan namedInterface)
go func() {
for _, decl := range file.Decls {
gd, ok := decl.(*ast.GenDecl)
if !ok || gd.Tok != token.TYPE {
continue
}
for _, spec := range gd.Specs {
ts, ok := spec.(*ast.TypeSpec)
if !ok {
continue
}
it, ok := ts.Type.(*ast.InterfaceType)
if !ok {
continue
}
ch <- namedInterface{ts.Name, it}
}
}
close(ch)
}()
return ch
} | go | func iterInterfaces(file *ast.File) <-chan namedInterface {
ch := make(chan namedInterface)
go func() {
for _, decl := range file.Decls {
gd, ok := decl.(*ast.GenDecl)
if !ok || gd.Tok != token.TYPE {
continue
}
for _, spec := range gd.Specs {
ts, ok := spec.(*ast.TypeSpec)
if !ok {
continue
}
it, ok := ts.Type.(*ast.InterfaceType)
if !ok {
continue
}
ch <- namedInterface{ts.Name, it}
}
}
close(ch)
}()
return ch
} | [
"func",
"iterInterfaces",
"(",
"file",
"*",
"ast",
".",
"File",
")",
"<-",
"chan",
"namedInterface",
"{",
"ch",
":=",
"make",
"(",
"chan",
"namedInterface",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"_",
",",
"decl",
":=",
"range",
"file",
".",
"Decls",
"{",
"gd",
",",
"ok",
":=",
"decl",
".",
"(",
"*",
"ast",
".",
"GenDecl",
")",
"\n",
"if",
"!",
"ok",
"||",
"gd",
".",
"Tok",
"!=",
"token",
".",
"TYPE",
"{",
"continue",
"\n",
"}",
"\n",
"for",
"_",
",",
"spec",
":=",
"range",
"gd",
".",
"Specs",
"{",
"ts",
",",
"ok",
":=",
"spec",
".",
"(",
"*",
"ast",
".",
"TypeSpec",
")",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"it",
",",
"ok",
":=",
"ts",
".",
"Type",
".",
"(",
"*",
"ast",
".",
"InterfaceType",
")",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n\n",
"ch",
"<-",
"namedInterface",
"{",
"ts",
".",
"Name",
",",
"it",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"close",
"(",
"ch",
")",
"\n",
"}",
"(",
")",
"\n",
"return",
"ch",
"\n",
"}"
] | // Create an iterator over all interfaces in file. | [
"Create",
"an",
"iterator",
"over",
"all",
"interfaces",
"in",
"file",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/parse.go#L489-L513 | train |
golang/mock | mockgen/parse.go | isVariadic | func isVariadic(f *ast.FuncType) bool {
nargs := len(f.Params.List)
if nargs == 0 {
return false
}
_, ok := f.Params.List[nargs-1].Type.(*ast.Ellipsis)
return ok
} | go | func isVariadic(f *ast.FuncType) bool {
nargs := len(f.Params.List)
if nargs == 0 {
return false
}
_, ok := f.Params.List[nargs-1].Type.(*ast.Ellipsis)
return ok
} | [
"func",
"isVariadic",
"(",
"f",
"*",
"ast",
".",
"FuncType",
")",
"bool",
"{",
"nargs",
":=",
"len",
"(",
"f",
".",
"Params",
".",
"List",
")",
"\n",
"if",
"nargs",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"_",
",",
"ok",
":=",
"f",
".",
"Params",
".",
"List",
"[",
"nargs",
"-",
"1",
"]",
".",
"Type",
".",
"(",
"*",
"ast",
".",
"Ellipsis",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // isVariadic returns whether the function is variadic. | [
"isVariadic",
"returns",
"whether",
"the",
"function",
"is",
"variadic",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/parse.go#L516-L523 | train |
golang/mock | gomock/controller.go | NewController | func NewController(t TestReporter) *Controller {
h, ok := t.(TestHelper)
if !ok {
h = nopTestHelper{t}
}
return &Controller{
T: h,
expectedCalls: newCallSet(),
}
} | go | func NewController(t TestReporter) *Controller {
h, ok := t.(TestHelper)
if !ok {
h = nopTestHelper{t}
}
return &Controller{
T: h,
expectedCalls: newCallSet(),
}
} | [
"func",
"NewController",
"(",
"t",
"TestReporter",
")",
"*",
"Controller",
"{",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"TestHelper",
")",
"\n",
"if",
"!",
"ok",
"{",
"h",
"=",
"nopTestHelper",
"{",
"t",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"Controller",
"{",
"T",
":",
"h",
",",
"expectedCalls",
":",
"newCallSet",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewController returns a new Controller. It is the preferred way to create a
// Controller. | [
"NewController",
"returns",
"a",
"new",
"Controller",
".",
"It",
"is",
"the",
"preferred",
"way",
"to",
"create",
"a",
"Controller",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/controller.go#L118-L128 | train |
golang/mock | gomock/controller.go | WithContext | func WithContext(ctx context.Context, t TestReporter) (*Controller, context.Context) {
h, ok := t.(TestHelper)
if !ok {
h = nopTestHelper{t}
}
ctx, cancel := context.WithCancel(ctx)
return NewController(&cancelReporter{h, cancel}), ctx
} | go | func WithContext(ctx context.Context, t TestReporter) (*Controller, context.Context) {
h, ok := t.(TestHelper)
if !ok {
h = nopTestHelper{t}
}
ctx, cancel := context.WithCancel(ctx)
return NewController(&cancelReporter{h, cancel}), ctx
} | [
"func",
"WithContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"t",
"TestReporter",
")",
"(",
"*",
"Controller",
",",
"context",
".",
"Context",
")",
"{",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"TestHelper",
")",
"\n",
"if",
"!",
"ok",
"{",
"h",
"=",
"nopTestHelper",
"{",
"t",
"}",
"\n",
"}",
"\n\n",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"ctx",
")",
"\n",
"return",
"NewController",
"(",
"&",
"cancelReporter",
"{",
"h",
",",
"cancel",
"}",
")",
",",
"ctx",
"\n",
"}"
] | // WithContext returns a new Controller and a Context, which is cancelled on any
// fatal failure. | [
"WithContext",
"returns",
"a",
"new",
"Controller",
"and",
"a",
"Context",
"which",
"is",
"cancelled",
"on",
"any",
"fatal",
"failure",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/controller.go#L145-L153 | train |
golang/mock | gomock/controller.go | RecordCall | func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call {
ctrl.T.Helper()
recv := reflect.ValueOf(receiver)
for i := 0; i < recv.Type().NumMethod(); i++ {
if recv.Type().Method(i).Name == method {
return ctrl.RecordCallWithMethodType(receiver, method, recv.Method(i).Type(), args...)
}
}
ctrl.T.Fatalf("gomock: failed finding method %s on %T", method, receiver)
panic("unreachable")
} | go | func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call {
ctrl.T.Helper()
recv := reflect.ValueOf(receiver)
for i := 0; i < recv.Type().NumMethod(); i++ {
if recv.Type().Method(i).Name == method {
return ctrl.RecordCallWithMethodType(receiver, method, recv.Method(i).Type(), args...)
}
}
ctrl.T.Fatalf("gomock: failed finding method %s on %T", method, receiver)
panic("unreachable")
} | [
"func",
"(",
"ctrl",
"*",
"Controller",
")",
"RecordCall",
"(",
"receiver",
"interface",
"{",
"}",
",",
"method",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Call",
"{",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n\n",
"recv",
":=",
"reflect",
".",
"ValueOf",
"(",
"receiver",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"recv",
".",
"Type",
"(",
")",
".",
"NumMethod",
"(",
")",
";",
"i",
"++",
"{",
"if",
"recv",
".",
"Type",
"(",
")",
".",
"Method",
"(",
"i",
")",
".",
"Name",
"==",
"method",
"{",
"return",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"receiver",
",",
"method",
",",
"recv",
".",
"Method",
"(",
"i",
")",
".",
"Type",
"(",
")",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"ctrl",
".",
"T",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"method",
",",
"receiver",
")",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // RecordCall is called by a mock. It should not be called by user code. | [
"RecordCall",
"is",
"called",
"by",
"a",
"mock",
".",
"It",
"should",
"not",
"be",
"called",
"by",
"user",
"code",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/controller.go#L162-L173 | train |
golang/mock | gomock/controller.go | RecordCallWithMethodType | func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call {
ctrl.T.Helper()
call := newCall(ctrl.T, receiver, method, methodType, args...)
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
ctrl.expectedCalls.Add(call)
return call
} | go | func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call {
ctrl.T.Helper()
call := newCall(ctrl.T, receiver, method, methodType, args...)
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
ctrl.expectedCalls.Add(call)
return call
} | [
"func",
"(",
"ctrl",
"*",
"Controller",
")",
"RecordCallWithMethodType",
"(",
"receiver",
"interface",
"{",
"}",
",",
"method",
"string",
",",
"methodType",
"reflect",
".",
"Type",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Call",
"{",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n\n",
"call",
":=",
"newCall",
"(",
"ctrl",
".",
"T",
",",
"receiver",
",",
"method",
",",
"methodType",
",",
"args",
"...",
")",
"\n\n",
"ctrl",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ctrl",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"ctrl",
".",
"expectedCalls",
".",
"Add",
"(",
"call",
")",
"\n\n",
"return",
"call",
"\n",
"}"
] | // RecordCallWithMethodType is called by a mock. It should not be called by user code. | [
"RecordCallWithMethodType",
"is",
"called",
"by",
"a",
"mock",
".",
"It",
"should",
"not",
"be",
"called",
"by",
"user",
"code",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/controller.go#L176-L186 | train |
golang/mock | gomock/controller.go | Call | func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} {
ctrl.T.Helper()
// Nest this code so we can use defer to make sure the lock is released.
actions := func() []func([]interface{}) []interface{} {
ctrl.T.Helper()
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
expected, err := ctrl.expectedCalls.FindMatch(receiver, method, args)
if err != nil {
origin := callerInfo(2)
ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, args, origin, err)
}
// Two things happen here:
// * the matching call no longer needs to check prerequite calls,
// * and the prerequite calls are no longer expected, so remove them.
preReqCalls := expected.dropPrereqs()
for _, preReqCall := range preReqCalls {
ctrl.expectedCalls.Remove(preReqCall)
}
actions := expected.call(args)
if expected.exhausted() {
ctrl.expectedCalls.Remove(expected)
}
return actions
}()
var rets []interface{}
for _, action := range actions {
if r := action(args); r != nil {
rets = r
}
}
return rets
} | go | func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} {
ctrl.T.Helper()
// Nest this code so we can use defer to make sure the lock is released.
actions := func() []func([]interface{}) []interface{} {
ctrl.T.Helper()
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
expected, err := ctrl.expectedCalls.FindMatch(receiver, method, args)
if err != nil {
origin := callerInfo(2)
ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, args, origin, err)
}
// Two things happen here:
// * the matching call no longer needs to check prerequite calls,
// * and the prerequite calls are no longer expected, so remove them.
preReqCalls := expected.dropPrereqs()
for _, preReqCall := range preReqCalls {
ctrl.expectedCalls.Remove(preReqCall)
}
actions := expected.call(args)
if expected.exhausted() {
ctrl.expectedCalls.Remove(expected)
}
return actions
}()
var rets []interface{}
for _, action := range actions {
if r := action(args); r != nil {
rets = r
}
}
return rets
} | [
"func",
"(",
"ctrl",
"*",
"Controller",
")",
"Call",
"(",
"receiver",
"interface",
"{",
"}",
",",
"method",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n\n",
"// Nest this code so we can use defer to make sure the lock is released.",
"actions",
":=",
"func",
"(",
")",
"[",
"]",
"func",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ctrl",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ctrl",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"expected",
",",
"err",
":=",
"ctrl",
".",
"expectedCalls",
".",
"FindMatch",
"(",
"receiver",
",",
"method",
",",
"args",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"origin",
":=",
"callerInfo",
"(",
"2",
")",
"\n",
"ctrl",
".",
"T",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"receiver",
",",
"method",
",",
"args",
",",
"origin",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Two things happen here:",
"// * the matching call no longer needs to check prerequite calls,",
"// * and the prerequite calls are no longer expected, so remove them.",
"preReqCalls",
":=",
"expected",
".",
"dropPrereqs",
"(",
")",
"\n",
"for",
"_",
",",
"preReqCall",
":=",
"range",
"preReqCalls",
"{",
"ctrl",
".",
"expectedCalls",
".",
"Remove",
"(",
"preReqCall",
")",
"\n",
"}",
"\n\n",
"actions",
":=",
"expected",
".",
"call",
"(",
"args",
")",
"\n",
"if",
"expected",
".",
"exhausted",
"(",
")",
"{",
"ctrl",
".",
"expectedCalls",
".",
"Remove",
"(",
"expected",
")",
"\n",
"}",
"\n",
"return",
"actions",
"\n",
"}",
"(",
")",
"\n\n",
"var",
"rets",
"[",
"]",
"interface",
"{",
"}",
"\n",
"for",
"_",
",",
"action",
":=",
"range",
"actions",
"{",
"if",
"r",
":=",
"action",
"(",
"args",
")",
";",
"r",
"!=",
"nil",
"{",
"rets",
"=",
"r",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"rets",
"\n",
"}"
] | // Call is called by a mock. It should not be called by user code. | [
"Call",
"is",
"called",
"by",
"a",
"mock",
".",
"It",
"should",
"not",
"be",
"called",
"by",
"user",
"code",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/controller.go#L189-L227 | train |
golang/mock | gomock/controller.go | Finish | func (ctrl *Controller) Finish() {
ctrl.T.Helper()
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
if ctrl.finished {
ctrl.T.Fatalf("Controller.Finish was called more than once. It has to be called exactly once.")
}
ctrl.finished = true
// If we're currently panicking, probably because this is a deferred call,
// pass through the panic.
if err := recover(); err != nil {
panic(err)
}
// Check that all remaining expected calls are satisfied.
failures := ctrl.expectedCalls.Failures()
for _, call := range failures {
ctrl.T.Errorf("missing call(s) to %v", call)
}
if len(failures) != 0 {
ctrl.T.Fatalf("aborting test due to missing call(s)")
}
} | go | func (ctrl *Controller) Finish() {
ctrl.T.Helper()
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
if ctrl.finished {
ctrl.T.Fatalf("Controller.Finish was called more than once. It has to be called exactly once.")
}
ctrl.finished = true
// If we're currently panicking, probably because this is a deferred call,
// pass through the panic.
if err := recover(); err != nil {
panic(err)
}
// Check that all remaining expected calls are satisfied.
failures := ctrl.expectedCalls.Failures()
for _, call := range failures {
ctrl.T.Errorf("missing call(s) to %v", call)
}
if len(failures) != 0 {
ctrl.T.Fatalf("aborting test due to missing call(s)")
}
} | [
"func",
"(",
"ctrl",
"*",
"Controller",
")",
"Finish",
"(",
")",
"{",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n\n",
"ctrl",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ctrl",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"ctrl",
".",
"finished",
"{",
"ctrl",
".",
"T",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ctrl",
".",
"finished",
"=",
"true",
"\n\n",
"// If we're currently panicking, probably because this is a deferred call,",
"// pass through the panic.",
"if",
"err",
":=",
"recover",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// Check that all remaining expected calls are satisfied.",
"failures",
":=",
"ctrl",
".",
"expectedCalls",
".",
"Failures",
"(",
")",
"\n",
"for",
"_",
",",
"call",
":=",
"range",
"failures",
"{",
"ctrl",
".",
"T",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"call",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"failures",
")",
"!=",
"0",
"{",
"ctrl",
".",
"T",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // Finish checks to see if all the methods that were expected to be called
// were called. It should be invoked for each Controller. It is not idempotent
// and therefore can only be invoked once. | [
"Finish",
"checks",
"to",
"see",
"if",
"all",
"the",
"methods",
"that",
"were",
"expected",
"to",
"be",
"called",
"were",
"called",
".",
"It",
"should",
"be",
"invoked",
"for",
"each",
"Controller",
".",
"It",
"is",
"not",
"idempotent",
"and",
"therefore",
"can",
"only",
"be",
"invoked",
"once",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/gomock/controller.go#L232-L257 | train |
golang/mock | mockgen/model/model.go | Imports | func (pkg *Package) Imports() map[string]bool {
im := make(map[string]bool)
for _, intf := range pkg.Interfaces {
intf.addImports(im)
}
return im
} | go | func (pkg *Package) Imports() map[string]bool {
im := make(map[string]bool)
for _, intf := range pkg.Interfaces {
intf.addImports(im)
}
return im
} | [
"func",
"(",
"pkg",
"*",
"Package",
")",
"Imports",
"(",
")",
"map",
"[",
"string",
"]",
"bool",
"{",
"im",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"intf",
":=",
"range",
"pkg",
".",
"Interfaces",
"{",
"intf",
".",
"addImports",
"(",
"im",
")",
"\n",
"}",
"\n",
"return",
"im",
"\n",
"}"
] | // Imports returns the imports needed by the Package as a set of import paths. | [
"Imports",
"returns",
"the",
"imports",
"needed",
"by",
"the",
"Package",
"as",
"a",
"set",
"of",
"import",
"paths",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/model/model.go#L44-L50 | train |
golang/mock | mockgen/model/model.go | funcArgsFromType | func funcArgsFromType(t reflect.Type) (in []*Parameter, variadic *Parameter, out []*Parameter, err error) {
nin := t.NumIn()
if t.IsVariadic() {
nin--
}
var p *Parameter
for i := 0; i < nin; i++ {
p, err = parameterFromType(t.In(i))
if err != nil {
return
}
in = append(in, p)
}
if t.IsVariadic() {
p, err = parameterFromType(t.In(nin).Elem())
if err != nil {
return
}
variadic = p
}
for i := 0; i < t.NumOut(); i++ {
p, err = parameterFromType(t.Out(i))
if err != nil {
return
}
out = append(out, p)
}
return
} | go | func funcArgsFromType(t reflect.Type) (in []*Parameter, variadic *Parameter, out []*Parameter, err error) {
nin := t.NumIn()
if t.IsVariadic() {
nin--
}
var p *Parameter
for i := 0; i < nin; i++ {
p, err = parameterFromType(t.In(i))
if err != nil {
return
}
in = append(in, p)
}
if t.IsVariadic() {
p, err = parameterFromType(t.In(nin).Elem())
if err != nil {
return
}
variadic = p
}
for i := 0; i < t.NumOut(); i++ {
p, err = parameterFromType(t.Out(i))
if err != nil {
return
}
out = append(out, p)
}
return
} | [
"func",
"funcArgsFromType",
"(",
"t",
"reflect",
".",
"Type",
")",
"(",
"in",
"[",
"]",
"*",
"Parameter",
",",
"variadic",
"*",
"Parameter",
",",
"out",
"[",
"]",
"*",
"Parameter",
",",
"err",
"error",
")",
"{",
"nin",
":=",
"t",
".",
"NumIn",
"(",
")",
"\n",
"if",
"t",
".",
"IsVariadic",
"(",
")",
"{",
"nin",
"--",
"\n",
"}",
"\n",
"var",
"p",
"*",
"Parameter",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"nin",
";",
"i",
"++",
"{",
"p",
",",
"err",
"=",
"parameterFromType",
"(",
"t",
".",
"In",
"(",
"i",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"in",
"=",
"append",
"(",
"in",
",",
"p",
")",
"\n",
"}",
"\n",
"if",
"t",
".",
"IsVariadic",
"(",
")",
"{",
"p",
",",
"err",
"=",
"parameterFromType",
"(",
"t",
".",
"In",
"(",
"nin",
")",
".",
"Elem",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"variadic",
"=",
"p",
"\n",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"t",
".",
"NumOut",
"(",
")",
";",
"i",
"++",
"{",
"p",
",",
"err",
"=",
"parameterFromType",
"(",
"t",
".",
"Out",
"(",
"i",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"out",
"=",
"append",
"(",
"out",
",",
"p",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // t's Kind must be a reflect.Func. | [
"t",
"s",
"Kind",
"must",
"be",
"a",
"reflect",
".",
"Func",
"."
] | 937870445b8bddd7f05ea90e81c58ebe83681534 | https://github.com/golang/mock/blob/937870445b8bddd7f05ea90e81c58ebe83681534/mockgen/model/model.go#L312-L340 | train |
anacrolix/torrent | metainfo/magnet.go | ParseMagnetURI | func ParseMagnetURI(uri string) (m Magnet, err error) {
u, err := url.Parse(uri)
if err != nil {
err = fmt.Errorf("error parsing uri: %s", err)
return
}
if u.Scheme != "magnet" {
err = fmt.Errorf("unexpected scheme: %q", u.Scheme)
return
}
xt := u.Query().Get("xt")
if !strings.HasPrefix(xt, xtPrefix) {
err = fmt.Errorf("bad xt parameter")
return
}
infoHash := xt[len(xtPrefix):]
// BTIH hash can be in HEX or BASE32 encoding
// will assign appropriate func judging from symbol length
var decode func(dst, src []byte) (int, error)
switch len(infoHash) {
case 40:
decode = hex.Decode
case 32:
decode = base32.StdEncoding.Decode
}
if decode == nil {
err = fmt.Errorf("unhandled xt parameter encoding: encoded length %d", len(infoHash))
return
}
n, err := decode(m.InfoHash[:], []byte(infoHash))
if err != nil {
err = fmt.Errorf("error decoding xt: %s", err)
return
}
if n != 20 {
panic(n)
}
m.DisplayName = u.Query().Get("dn")
m.Trackers = u.Query()["tr"]
return
} | go | func ParseMagnetURI(uri string) (m Magnet, err error) {
u, err := url.Parse(uri)
if err != nil {
err = fmt.Errorf("error parsing uri: %s", err)
return
}
if u.Scheme != "magnet" {
err = fmt.Errorf("unexpected scheme: %q", u.Scheme)
return
}
xt := u.Query().Get("xt")
if !strings.HasPrefix(xt, xtPrefix) {
err = fmt.Errorf("bad xt parameter")
return
}
infoHash := xt[len(xtPrefix):]
// BTIH hash can be in HEX or BASE32 encoding
// will assign appropriate func judging from symbol length
var decode func(dst, src []byte) (int, error)
switch len(infoHash) {
case 40:
decode = hex.Decode
case 32:
decode = base32.StdEncoding.Decode
}
if decode == nil {
err = fmt.Errorf("unhandled xt parameter encoding: encoded length %d", len(infoHash))
return
}
n, err := decode(m.InfoHash[:], []byte(infoHash))
if err != nil {
err = fmt.Errorf("error decoding xt: %s", err)
return
}
if n != 20 {
panic(n)
}
m.DisplayName = u.Query().Get("dn")
m.Trackers = u.Query()["tr"]
return
} | [
"func",
"ParseMagnetURI",
"(",
"uri",
"string",
")",
"(",
"m",
"Magnet",
",",
"err",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"uri",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"u",
".",
"Scheme",
"!=",
"\"",
"\"",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"u",
".",
"Scheme",
")",
"\n",
"return",
"\n",
"}",
"\n",
"xt",
":=",
"u",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"xt",
",",
"xtPrefix",
")",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"infoHash",
":=",
"xt",
"[",
"len",
"(",
"xtPrefix",
")",
":",
"]",
"\n\n",
"// BTIH hash can be in HEX or BASE32 encoding",
"// will assign appropriate func judging from symbol length",
"var",
"decode",
"func",
"(",
"dst",
",",
"src",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"\n",
"switch",
"len",
"(",
"infoHash",
")",
"{",
"case",
"40",
":",
"decode",
"=",
"hex",
".",
"Decode",
"\n",
"case",
"32",
":",
"decode",
"=",
"base32",
".",
"StdEncoding",
".",
"Decode",
"\n",
"}",
"\n\n",
"if",
"decode",
"==",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"infoHash",
")",
")",
"\n",
"return",
"\n",
"}",
"\n",
"n",
",",
"err",
":=",
"decode",
"(",
"m",
".",
"InfoHash",
"[",
":",
"]",
",",
"[",
"]",
"byte",
"(",
"infoHash",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"n",
"!=",
"20",
"{",
"panic",
"(",
"n",
")",
"\n",
"}",
"\n",
"m",
".",
"DisplayName",
"=",
"u",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"m",
".",
"Trackers",
"=",
"u",
".",
"Query",
"(",
")",
"[",
"\"",
"\"",
"]",
"\n",
"return",
"\n",
"}"
] | // ParseMagnetURI parses Magnet-formatted URIs into a Magnet instance | [
"ParseMagnetURI",
"parses",
"Magnet",
"-",
"formatted",
"URIs",
"into",
"a",
"Magnet",
"instance"
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/metainfo/magnet.go#L35-L77 | train |
anacrolix/torrent | metainfo/metainfo.go | Load | func Load(r io.Reader) (*MetaInfo, error) {
var mi MetaInfo
d := bencode.NewDecoder(r)
err := d.Decode(&mi)
if err != nil {
return nil, err
}
return &mi, nil
} | go | func Load(r io.Reader) (*MetaInfo, error) {
var mi MetaInfo
d := bencode.NewDecoder(r)
err := d.Decode(&mi)
if err != nil {
return nil, err
}
return &mi, nil
} | [
"func",
"Load",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"MetaInfo",
",",
"error",
")",
"{",
"var",
"mi",
"MetaInfo",
"\n",
"d",
":=",
"bencode",
".",
"NewDecoder",
"(",
"r",
")",
"\n",
"err",
":=",
"d",
".",
"Decode",
"(",
"&",
"mi",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"mi",
",",
"nil",
"\n",
"}"
] | // Load a MetaInfo from an io.Reader. Returns a non-nil error in case of
// failure. | [
"Load",
"a",
"MetaInfo",
"from",
"an",
"io",
".",
"Reader",
".",
"Returns",
"a",
"non",
"-",
"nil",
"error",
"in",
"case",
"of",
"failure",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/metainfo/metainfo.go#L25-L33 | train |
anacrolix/torrent | metainfo/metainfo.go | LoadFromFile | func LoadFromFile(filename string) (*MetaInfo, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
return Load(f)
} | go | func LoadFromFile(filename string) (*MetaInfo, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
return Load(f)
} | [
"func",
"LoadFromFile",
"(",
"filename",
"string",
")",
"(",
"*",
"MetaInfo",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"return",
"Load",
"(",
"f",
")",
"\n",
"}"
] | // Convenience function for loading a MetaInfo from a file. | [
"Convenience",
"function",
"for",
"loading",
"a",
"MetaInfo",
"from",
"a",
"file",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/metainfo/metainfo.go#L36-L43 | train |
anacrolix/torrent | metainfo/metainfo.go | Write | func (mi MetaInfo) Write(w io.Writer) error {
return bencode.NewEncoder(w).Encode(mi)
} | go | func (mi MetaInfo) Write(w io.Writer) error {
return bencode.NewEncoder(w).Encode(mi)
} | [
"func",
"(",
"mi",
"MetaInfo",
")",
"Write",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"return",
"bencode",
".",
"NewEncoder",
"(",
"w",
")",
".",
"Encode",
"(",
"mi",
")",
"\n",
"}"
] | // Encode to bencoded form. | [
"Encode",
"to",
"bencoded",
"form",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/metainfo/metainfo.go#L55-L57 | train |
anacrolix/torrent | metainfo/metainfo.go | SetDefaults | func (mi *MetaInfo) SetDefaults() {
mi.Comment = "yoloham"
mi.CreatedBy = "github.com/anacrolix/torrent"
mi.CreationDate = time.Now().Unix()
// mi.Info.PieceLength = 256 * 1024
} | go | func (mi *MetaInfo) SetDefaults() {
mi.Comment = "yoloham"
mi.CreatedBy = "github.com/anacrolix/torrent"
mi.CreationDate = time.Now().Unix()
// mi.Info.PieceLength = 256 * 1024
} | [
"func",
"(",
"mi",
"*",
"MetaInfo",
")",
"SetDefaults",
"(",
")",
"{",
"mi",
".",
"Comment",
"=",
"\"",
"\"",
"\n",
"mi",
".",
"CreatedBy",
"=",
"\"",
"\"",
"\n",
"mi",
".",
"CreationDate",
"=",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
"\n",
"// mi.Info.PieceLength = 256 * 1024",
"}"
] | // Set good default values in preparation for creating a new MetaInfo file. | [
"Set",
"good",
"default",
"values",
"in",
"preparation",
"for",
"creating",
"a",
"new",
"MetaInfo",
"file",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/metainfo/metainfo.go#L60-L65 | train |
anacrolix/torrent | metainfo/metainfo.go | Magnet | func (mi *MetaInfo) Magnet(displayName string, infoHash Hash) (m Magnet) {
for t := range mi.UpvertedAnnounceList().DistinctValues() {
m.Trackers = append(m.Trackers, t)
}
m.DisplayName = displayName
m.InfoHash = infoHash
return
} | go | func (mi *MetaInfo) Magnet(displayName string, infoHash Hash) (m Magnet) {
for t := range mi.UpvertedAnnounceList().DistinctValues() {
m.Trackers = append(m.Trackers, t)
}
m.DisplayName = displayName
m.InfoHash = infoHash
return
} | [
"func",
"(",
"mi",
"*",
"MetaInfo",
")",
"Magnet",
"(",
"displayName",
"string",
",",
"infoHash",
"Hash",
")",
"(",
"m",
"Magnet",
")",
"{",
"for",
"t",
":=",
"range",
"mi",
".",
"UpvertedAnnounceList",
"(",
")",
".",
"DistinctValues",
"(",
")",
"{",
"m",
".",
"Trackers",
"=",
"append",
"(",
"m",
".",
"Trackers",
",",
"t",
")",
"\n",
"}",
"\n",
"m",
".",
"DisplayName",
"=",
"displayName",
"\n",
"m",
".",
"InfoHash",
"=",
"infoHash",
"\n",
"return",
"\n",
"}"
] | // Creates a Magnet from a MetaInfo. | [
"Creates",
"a",
"Magnet",
"from",
"a",
"MetaInfo",
"."
] | d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb | https://github.com/anacrolix/torrent/blob/d2400968fc54c3d8a6482d4ca5ff16cc5e5139cb/metainfo/metainfo.go#L68-L75 | train |
Subsets and Splits