repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
jung-kurt/gofpdf
spotcolor.go
AddSpotColor
func (f *Fpdf) AddSpotColor(nameStr string, c, m, y, k byte) { if f.err == nil { _, ok := f.spotColorMap[nameStr] if !ok { id := len(f.spotColorMap) + 1 f.spotColorMap[nameStr] = spotColorType{ id: id, val: cmykColorType{ c: byteBound(c), m: byteBound(m), y: byteBound(y), k: byteBound(k), }, } } else { f.err = fmt.Errorf("name \"%s\" is already associated with a spot color", nameStr) } } }
go
func (f *Fpdf) AddSpotColor(nameStr string, c, m, y, k byte) { if f.err == nil { _, ok := f.spotColorMap[nameStr] if !ok { id := len(f.spotColorMap) + 1 f.spotColorMap[nameStr] = spotColorType{ id: id, val: cmykColorType{ c: byteBound(c), m: byteBound(m), y: byteBound(y), k: byteBound(k), }, } } else { f.err = fmt.Errorf("name \"%s\" is already associated with a spot color", nameStr) } } }
[ "func", "(", "f", "*", "Fpdf", ")", "AddSpotColor", "(", "nameStr", "string", ",", "c", ",", "m", ",", "y", ",", "k", "byte", ")", "{", "if", "f", ".", "err", "==", "nil", "{", "_", ",", "ok", ":=", "f", ".", "spotColorMap", "[", "nameStr", "]", "\n", "if", "!", "ok", "{", "id", ":=", "len", "(", "f", ".", "spotColorMap", ")", "+", "1", "\n", "f", ".", "spotColorMap", "[", "nameStr", "]", "=", "spotColorType", "{", "id", ":", "id", ",", "val", ":", "cmykColorType", "{", "c", ":", "byteBound", "(", "c", ")", ",", "m", ":", "byteBound", "(", "m", ")", ",", "y", ":", "byteBound", "(", "y", ")", ",", "k", ":", "byteBound", "(", "k", ")", ",", "}", ",", "}", "\n", "}", "else", "{", "f", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"name \\\"%s\\\" is already associated with a spot color\"", ",", "\\\"", ")", "\n", "}", "\n", "}", "\n", "}" ]
// AddSpotColor adds an ink-based CMYK color to the gofpdf instance and // associates it with the specified name. The individual components specify // percentages ranging from 0 to 100. Values above this are quietly capped to // 100. An error occurs if the specified name is already associated with a // color.
[ "AddSpotColor", "adds", "an", "ink", "-", "based", "CMYK", "color", "to", "the", "gofpdf", "instance", "and", "associates", "it", "with", "the", "specified", "name", ".", "The", "individual", "components", "specify", "percentages", "ranging", "from", "0", "to", "100", ".", "Values", "above", "this", "are", "quietly", "capped", "to", "100", ".", "An", "error", "occurs", "if", "the", "specified", "name", "is", "already", "associated", "with", "a", "color", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L36-L54
train
jung-kurt/gofpdf
spotcolor.go
GetDrawSpotColor
func (f *Fpdf) GetDrawSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.draw) }
go
func (f *Fpdf) GetDrawSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.draw) }
[ "func", "(", "f", "*", "Fpdf", ")", "GetDrawSpotColor", "(", ")", "(", "name", "string", ",", "c", ",", "m", ",", "y", ",", "k", "byte", ")", "{", "return", "f", ".", "returnSpotColor", "(", "f", ".", "color", ".", "draw", ")", "\n", "}" ]
// GetDrawSpotColor returns the most recently used spot color information for // drawing. This will not be the current drawing color if some other color type // such as RGB is active. If no spot color has been set for drawing, zero // values are returned.
[ "GetDrawSpotColor", "returns", "the", "most", "recently", "used", "spot", "color", "information", "for", "drawing", ".", "This", "will", "not", "be", "the", "current", "drawing", "color", "if", "some", "other", "color", "type", "such", "as", "RGB", "is", "active", ".", "If", "no", "spot", "color", "has", "been", "set", "for", "drawing", "zero", "values", "are", "returned", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L143-L145
train
jung-kurt/gofpdf
spotcolor.go
GetTextSpotColor
func (f *Fpdf) GetTextSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.text) }
go
func (f *Fpdf) GetTextSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.text) }
[ "func", "(", "f", "*", "Fpdf", ")", "GetTextSpotColor", "(", ")", "(", "name", "string", ",", "c", ",", "m", ",", "y", ",", "k", "byte", ")", "{", "return", "f", ".", "returnSpotColor", "(", "f", ".", "color", ".", "text", ")", "\n", "}" ]
// GetTextSpotColor returns the most recently used spot color information for // text output. This will not be the current text color if some other color // type such as RGB is active. If no spot color has been set for text, zero // values are returned.
[ "GetTextSpotColor", "returns", "the", "most", "recently", "used", "spot", "color", "information", "for", "text", "output", ".", "This", "will", "not", "be", "the", "current", "text", "color", "if", "some", "other", "color", "type", "such", "as", "RGB", "is", "active", ".", "If", "no", "spot", "color", "has", "been", "set", "for", "text", "zero", "values", "are", "returned", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L151-L153
train
jung-kurt/gofpdf
spotcolor.go
GetFillSpotColor
func (f *Fpdf) GetFillSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.fill) }
go
func (f *Fpdf) GetFillSpotColor() (name string, c, m, y, k byte) { return f.returnSpotColor(f.color.fill) }
[ "func", "(", "f", "*", "Fpdf", ")", "GetFillSpotColor", "(", ")", "(", "name", "string", ",", "c", ",", "m", ",", "y", ",", "k", "byte", ")", "{", "return", "f", ".", "returnSpotColor", "(", "f", ".", "color", ".", "fill", ")", "\n", "}" ]
// GetFillSpotColor returns the most recently used spot color information for // fill output. This will not be the current fill color if some other color // type such as RGB is active. If no fill spot color has been set, zero values // are returned.
[ "GetFillSpotColor", "returns", "the", "most", "recently", "used", "spot", "color", "information", "for", "fill", "output", ".", "This", "will", "not", "be", "the", "current", "fill", "color", "if", "some", "other", "color", "type", "such", "as", "RGB", "is", "active", ".", "If", "no", "fill", "spot", "color", "has", "been", "set", "zero", "values", "are", "returned", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L159-L161
train
jung-kurt/gofpdf
layer.go
BeginLayer
func (f *Fpdf) BeginLayer(id int) { f.EndLayer() if id >= 0 && id < len(f.layer.list) { f.outf("/OC /OC%d BDC", id) f.layer.currentLayer = id } }
go
func (f *Fpdf) BeginLayer(id int) { f.EndLayer() if id >= 0 && id < len(f.layer.list) { f.outf("/OC /OC%d BDC", id) f.layer.currentLayer = id } }
[ "func", "(", "f", "*", "Fpdf", ")", "BeginLayer", "(", "id", "int", ")", "{", "f", ".", "EndLayer", "(", ")", "\n", "if", "id", ">=", "0", "&&", "id", "<", "len", "(", "f", ".", "layer", ".", "list", ")", "{", "f", ".", "outf", "(", "\"/OC /OC%d BDC\"", ",", "id", ")", "\n", "f", ".", "layer", ".", "currentLayer", "=", "id", "\n", "}", "\n", "}" ]
// BeginLayer is called to begin adding content to the specified layer. All // content added to the page between a call to BeginLayer and a call to // EndLayer is added to the layer specified by id. See AddLayer for more // details.
[ "BeginLayer", "is", "called", "to", "begin", "adding", "content", "to", "the", "specified", "layer", ".", "All", "content", "added", "to", "the", "page", "between", "a", "call", "to", "BeginLayer", "and", "a", "call", "to", "EndLayer", "is", "added", "to", "the", "layer", "specified", "by", "id", ".", "See", "AddLayer", "for", "more", "details", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/layer.go#L55-L61
train
jung-kurt/gofpdf
layer.go
EndLayer
func (f *Fpdf) EndLayer() { if f.layer.currentLayer >= 0 { f.out("EMC") f.layer.currentLayer = -1 } }
go
func (f *Fpdf) EndLayer() { if f.layer.currentLayer >= 0 { f.out("EMC") f.layer.currentLayer = -1 } }
[ "func", "(", "f", "*", "Fpdf", ")", "EndLayer", "(", ")", "{", "if", "f", ".", "layer", ".", "currentLayer", ">=", "0", "{", "f", ".", "out", "(", "\"EMC\"", ")", "\n", "f", ".", "layer", ".", "currentLayer", "=", "-", "1", "\n", "}", "\n", "}" ]
// EndLayer is called to stop adding content to the currently active layer. See // BeginLayer for more details.
[ "EndLayer", "is", "called", "to", "stop", "adding", "content", "to", "the", "currently", "active", "layer", ".", "See", "BeginLayer", "for", "more", "details", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/layer.go#L65-L70
train
jung-kurt/gofpdf
contrib/barcode/barcode.go
GetUnscaledBarcodeDimensions
func GetUnscaledBarcodeDimensions(pdf barcodePdf, code string) (w, h float64) { barcodes.Lock() unscaled, ok := barcodes.cache[code] barcodes.Unlock() if !ok { err := errors.New("Barcode not found") pdf.SetError(err) return } return convertFrom96Dpi(pdf, float64(unscaled.Bounds().Dx())), convertFrom96Dpi(pdf, float64(unscaled.Bounds().Dy())) }
go
func GetUnscaledBarcodeDimensions(pdf barcodePdf, code string) (w, h float64) { barcodes.Lock() unscaled, ok := barcodes.cache[code] barcodes.Unlock() if !ok { err := errors.New("Barcode not found") pdf.SetError(err) return } return convertFrom96Dpi(pdf, float64(unscaled.Bounds().Dx())), convertFrom96Dpi(pdf, float64(unscaled.Bounds().Dy())) }
[ "func", "GetUnscaledBarcodeDimensions", "(", "pdf", "barcodePdf", ",", "code", "string", ")", "(", "w", ",", "h", "float64", ")", "{", "barcodes", ".", "Lock", "(", ")", "\n", "unscaled", ",", "ok", ":=", "barcodes", ".", "cache", "[", "code", "]", "\n", "barcodes", ".", "Unlock", "(", ")", "\n", "if", "!", "ok", "{", "err", ":=", "errors", ".", "New", "(", "\"Barcode not found\"", ")", "\n", "pdf", ".", "SetError", "(", "err", ")", "\n", "return", "\n", "}", "\n", "return", "convertFrom96Dpi", "(", "pdf", ",", "float64", "(", "unscaled", ".", "Bounds", "(", ")", ".", "Dx", "(", ")", ")", ")", ",", "convertFrom96Dpi", "(", "pdf", ",", "float64", "(", "unscaled", ".", "Bounds", "(", ")", ".", "Dy", "(", ")", ")", ")", "\n", "}" ]
// GetUnscaledBarcodeDimensions returns the width and height of the // unscaled barcode associated with the given code.
[ "GetUnscaledBarcodeDimensions", "returns", "the", "width", "and", "height", "of", "the", "unscaled", "barcode", "associated", "with", "the", "given", "code", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L127-L140
train
jung-kurt/gofpdf
contrib/barcode/barcode.go
uniqueBarcodeName
func uniqueBarcodeName(code string, x, y float64) string { xStr := strconv.FormatFloat(x, 'E', -1, 64) yStr := strconv.FormatFloat(y, 'E', -1, 64) return "barcode-" + code + "-" + xStr + yStr }
go
func uniqueBarcodeName(code string, x, y float64) string { xStr := strconv.FormatFloat(x, 'E', -1, 64) yStr := strconv.FormatFloat(y, 'E', -1, 64) return "barcode-" + code + "-" + xStr + yStr }
[ "func", "uniqueBarcodeName", "(", "code", "string", ",", "x", ",", "y", "float64", ")", "string", "{", "xStr", ":=", "strconv", ".", "FormatFloat", "(", "x", ",", "'E'", ",", "-", "1", ",", "64", ")", "\n", "yStr", ":=", "strconv", ".", "FormatFloat", "(", "y", ",", "'E'", ",", "-", "1", ",", "64", ")", "\n", "return", "\"barcode-\"", "+", "code", "+", "\"-\"", "+", "xStr", "+", "yStr", "\n", "}" ]
// uniqueBarcodeName makes sure every barcode has a unique name for its // dimensions. Scaling a barcode image results in quality loss, which could be // a problem for barcode readers.
[ "uniqueBarcodeName", "makes", "sure", "every", "barcode", "has", "a", "unique", "name", "for", "its", "dimensions", ".", "Scaling", "a", "barcode", "image", "results", "in", "quality", "loss", "which", "could", "be", "a", "problem", "for", "barcode", "readers", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L252-L257
train
jung-kurt/gofpdf
contrib/barcode/barcode.go
barcodeKey
func barcodeKey(bcode barcode.Barcode) string { return bcode.Metadata().CodeKind + bcode.Content() }
go
func barcodeKey(bcode barcode.Barcode) string { return bcode.Metadata().CodeKind + bcode.Content() }
[ "func", "barcodeKey", "(", "bcode", "barcode", ".", "Barcode", ")", "string", "{", "return", "bcode", ".", "Metadata", "(", ")", ".", "CodeKind", "+", "bcode", ".", "Content", "(", ")", "\n", "}" ]
// barcodeKey combines the code type and code value into a unique identifier for // a barcode type. This is so that we can store several barcodes with the same // code but different type in the barcodes map.
[ "barcodeKey", "combines", "the", "code", "type", "and", "code", "value", "into", "a", "unique", "identifier", "for", "a", "barcode", "type", ".", "This", "is", "so", "that", "we", "can", "store", "several", "barcodes", "with", "the", "same", "code", "but", "different", "type", "in", "the", "barcodes", "map", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L262-L264
train
jung-kurt/gofpdf
grid.go
StateGet
func StateGet(pdf *Fpdf) (st StateType) { st.clrDraw.R, st.clrDraw.G, st.clrDraw.B = pdf.GetDrawColor() st.clrFill.R, st.clrFill.G, st.clrFill.B = pdf.GetFillColor() st.clrText.R, st.clrText.G, st.clrText.B = pdf.GetTextColor() st.lineWd = pdf.GetLineWidth() _, st.fontSize = pdf.GetFontSize() st.alpha, st.blendStr = pdf.GetAlpha() st.cellMargin = pdf.GetCellMargin() return }
go
func StateGet(pdf *Fpdf) (st StateType) { st.clrDraw.R, st.clrDraw.G, st.clrDraw.B = pdf.GetDrawColor() st.clrFill.R, st.clrFill.G, st.clrFill.B = pdf.GetFillColor() st.clrText.R, st.clrText.G, st.clrText.B = pdf.GetTextColor() st.lineWd = pdf.GetLineWidth() _, st.fontSize = pdf.GetFontSize() st.alpha, st.blendStr = pdf.GetAlpha() st.cellMargin = pdf.GetCellMargin() return }
[ "func", "StateGet", "(", "pdf", "*", "Fpdf", ")", "(", "st", "StateType", ")", "{", "st", ".", "clrDraw", ".", "R", ",", "st", ".", "clrDraw", ".", "G", ",", "st", ".", "clrDraw", ".", "B", "=", "pdf", ".", "GetDrawColor", "(", ")", "\n", "st", ".", "clrFill", ".", "R", ",", "st", ".", "clrFill", ".", "G", ",", "st", ".", "clrFill", ".", "B", "=", "pdf", ".", "GetFillColor", "(", ")", "\n", "st", ".", "clrText", ".", "R", ",", "st", ".", "clrText", ".", "G", ",", "st", ".", "clrText", ".", "B", "=", "pdf", ".", "GetTextColor", "(", ")", "\n", "st", ".", "lineWd", "=", "pdf", ".", "GetLineWidth", "(", ")", "\n", "_", ",", "st", ".", "fontSize", "=", "pdf", ".", "GetFontSize", "(", ")", "\n", "st", ".", "alpha", ",", "st", ".", "blendStr", "=", "pdf", ".", "GetAlpha", "(", ")", "\n", "st", ".", "cellMargin", "=", "pdf", ".", "GetCellMargin", "(", ")", "\n", "return", "\n", "}" ]
// StateGet returns a variable that contains common state values.
[ "StateGet", "returns", "a", "variable", "that", "contains", "common", "state", "values", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L35-L44
train
jung-kurt/gofpdf
grid.go
Put
func (st StateType) Put(pdf *Fpdf) { pdf.SetDrawColor(st.clrDraw.R, st.clrDraw.G, st.clrDraw.B) pdf.SetFillColor(st.clrFill.R, st.clrFill.G, st.clrFill.B) pdf.SetTextColor(st.clrText.R, st.clrText.G, st.clrText.B) pdf.SetLineWidth(st.lineWd) pdf.SetFontUnitSize(st.fontSize) pdf.SetAlpha(st.alpha, st.blendStr) pdf.SetCellMargin(st.cellMargin) }
go
func (st StateType) Put(pdf *Fpdf) { pdf.SetDrawColor(st.clrDraw.R, st.clrDraw.G, st.clrDraw.B) pdf.SetFillColor(st.clrFill.R, st.clrFill.G, st.clrFill.B) pdf.SetTextColor(st.clrText.R, st.clrText.G, st.clrText.B) pdf.SetLineWidth(st.lineWd) pdf.SetFontUnitSize(st.fontSize) pdf.SetAlpha(st.alpha, st.blendStr) pdf.SetCellMargin(st.cellMargin) }
[ "func", "(", "st", "StateType", ")", "Put", "(", "pdf", "*", "Fpdf", ")", "{", "pdf", ".", "SetDrawColor", "(", "st", ".", "clrDraw", ".", "R", ",", "st", ".", "clrDraw", ".", "G", ",", "st", ".", "clrDraw", ".", "B", ")", "\n", "pdf", ".", "SetFillColor", "(", "st", ".", "clrFill", ".", "R", ",", "st", ".", "clrFill", ".", "G", ",", "st", ".", "clrFill", ".", "B", ")", "\n", "pdf", ".", "SetTextColor", "(", "st", ".", "clrText", ".", "R", ",", "st", ".", "clrText", ".", "G", ",", "st", ".", "clrText", ".", "B", ")", "\n", "pdf", ".", "SetLineWidth", "(", "st", ".", "lineWd", ")", "\n", "pdf", ".", "SetFontUnitSize", "(", "st", ".", "fontSize", ")", "\n", "pdf", ".", "SetAlpha", "(", "st", ".", "alpha", ",", "st", ".", "blendStr", ")", "\n", "pdf", ".", "SetCellMargin", "(", "st", ".", "cellMargin", ")", "\n", "}" ]
// Put sets the common state values contained in the state structure // specified by st.
[ "Put", "sets", "the", "common", "state", "values", "contained", "in", "the", "state", "structure", "specified", "by", "st", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L48-L56
train
jung-kurt/gofpdf
grid.go
defaultFormatter
func defaultFormatter(val float64, precision int) string { return strconv.FormatFloat(val, 'f', precision, 64) }
go
func defaultFormatter(val float64, precision int) string { return strconv.FormatFloat(val, 'f', precision, 64) }
[ "func", "defaultFormatter", "(", "val", "float64", ",", "precision", "int", ")", "string", "{", "return", "strconv", ".", "FormatFloat", "(", "val", ",", "'f'", ",", "precision", ",", "64", ")", "\n", "}" ]
// defaultFormatter returns the string form of val with precision decimal places.
[ "defaultFormatter", "returns", "the", "string", "form", "of", "val", "with", "precision", "decimal", "places", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L62-L64
train
jung-kurt/gofpdf
grid.go
XY
func (g GridType) XY(dataX, dataY float64) (x, y float64) { return g.xm*dataX + g.xb, g.ym*dataY + g.yb }
go
func (g GridType) XY(dataX, dataY float64) (x, y float64) { return g.xm*dataX + g.xb, g.ym*dataY + g.yb }
[ "func", "(", "g", "GridType", ")", "XY", "(", "dataX", ",", "dataY", "float64", ")", "(", "x", ",", "y", "float64", ")", "{", "return", "g", ".", "xm", "*", "dataX", "+", "g", ".", "xb", ",", "g", ".", "ym", "*", "dataY", "+", "g", ".", "yb", "\n", "}" ]
// XY converts dataX and dataY, specified in logical data units, to the X and Y // position on the current page.
[ "XY", "converts", "dataX", "and", "dataY", "specified", "in", "logical", "data", "units", "to", "the", "X", "and", "Y", "position", "on", "the", "current", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L167-L169
train
jung-kurt/gofpdf
grid.go
Pos
func (g GridType) Pos(xRel, yRel float64) (x, y float64) { x = g.w*xRel + g.x y = g.h*(1-yRel) + g.y return }
go
func (g GridType) Pos(xRel, yRel float64) (x, y float64) { x = g.w*xRel + g.x y = g.h*(1-yRel) + g.y return }
[ "func", "(", "g", "GridType", ")", "Pos", "(", "xRel", ",", "yRel", "float64", ")", "(", "x", ",", "y", "float64", ")", "{", "x", "=", "g", ".", "w", "*", "xRel", "+", "g", ".", "x", "\n", "y", "=", "g", ".", "h", "*", "(", "1", "-", "yRel", ")", "+", "g", ".", "y", "\n", "return", "\n", "}" ]
// Pos returns the point, in page units, indicated by the relative positions // xRel and yRel. These are values between 0 and 1. xRel specifies the relative // position between the grid's left and right edges. yRel specifies the // relative position between the grid's bottom and top edges.
[ "Pos", "returns", "the", "point", "in", "page", "units", "indicated", "by", "the", "relative", "positions", "xRel", "and", "yRel", ".", "These", "are", "values", "between", "0", "and", "1", ".", "xRel", "specifies", "the", "relative", "position", "between", "the", "grid", "s", "left", "and", "right", "edges", ".", "yRel", "specifies", "the", "relative", "position", "between", "the", "grid", "s", "bottom", "and", "top", "edges", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L175-L179
train
jung-kurt/gofpdf
grid.go
X
func (g GridType) X(dataX float64) float64 { return g.xm*dataX + g.xb }
go
func (g GridType) X(dataX float64) float64 { return g.xm*dataX + g.xb }
[ "func", "(", "g", "GridType", ")", "X", "(", "dataX", "float64", ")", "float64", "{", "return", "g", ".", "xm", "*", "dataX", "+", "g", ".", "xb", "\n", "}" ]
// X converts dataX, specified in logical data units, to the X position on the // current page.
[ "X", "converts", "dataX", "specified", "in", "logical", "data", "units", "to", "the", "X", "position", "on", "the", "current", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L183-L185
train
jung-kurt/gofpdf
grid.go
Y
func (g GridType) Y(dataY float64) float64 { return g.ym*dataY + g.yb }
go
func (g GridType) Y(dataY float64) float64 { return g.ym*dataY + g.yb }
[ "func", "(", "g", "GridType", ")", "Y", "(", "dataY", "float64", ")", "float64", "{", "return", "g", ".", "ym", "*", "dataY", "+", "g", ".", "yb", "\n", "}" ]
// Y converts dataY, specified in logical data units, to the Y position on the // current page.
[ "Y", "converts", "dataY", "specified", "in", "logical", "data", "units", "to", "the", "Y", "position", "on", "the", "current", "page", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L201-L203
train
jung-kurt/gofpdf
grid.go
XRange
func (g GridType) XRange() (min, max float64) { min = g.xTicks[0] max = g.xTicks[len(g.xTicks)-1] return }
go
func (g GridType) XRange() (min, max float64) { min = g.xTicks[0] max = g.xTicks[len(g.xTicks)-1] return }
[ "func", "(", "g", "GridType", ")", "XRange", "(", ")", "(", "min", ",", "max", "float64", ")", "{", "min", "=", "g", ".", "xTicks", "[", "0", "]", "\n", "max", "=", "g", ".", "xTicks", "[", "len", "(", "g", ".", "xTicks", ")", "-", "1", "]", "\n", "return", "\n", "}" ]
// XRange returns the minimum and maximum values for the current tickmark // sequence. These correspond to the data values of the graph's left and right // edges.
[ "XRange", "returns", "the", "minimum", "and", "maximum", "values", "for", "the", "current", "tickmark", "sequence", ".", "These", "correspond", "to", "the", "data", "values", "of", "the", "graph", "s", "left", "and", "right", "edges", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L208-L212
train
jung-kurt/gofpdf
grid.go
YRange
func (g GridType) YRange() (min, max float64) { min = g.yTicks[0] max = g.yTicks[len(g.yTicks)-1] return }
go
func (g GridType) YRange() (min, max float64) { min = g.yTicks[0] max = g.yTicks[len(g.yTicks)-1] return }
[ "func", "(", "g", "GridType", ")", "YRange", "(", ")", "(", "min", ",", "max", "float64", ")", "{", "min", "=", "g", ".", "yTicks", "[", "0", "]", "\n", "max", "=", "g", ".", "yTicks", "[", "len", "(", "g", ".", "yTicks", ")", "-", "1", "]", "\n", "return", "\n", "}" ]
// YRange returns the minimum and maximum values for the current tickmark // sequence. These correspond to the data values of the graph's bottom and top // edges.
[ "YRange", "returns", "the", "minimum", "and", "maximum", "values", "for", "the", "current", "tickmark", "sequence", ".", "These", "correspond", "to", "the", "data", "values", "of", "the", "graph", "s", "bottom", "and", "top", "edges", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L217-L221
train
jung-kurt/gofpdf
htmlbasic.go
HTMLBasicTokenize
func HTMLBasicTokenize(htmlStr string) (list []HTMLBasicSegmentType) { // This routine is adapted from http://www.fpdf.org/ list = make([]HTMLBasicSegmentType, 0, 16) htmlStr = strings.Replace(htmlStr, "\n", " ", -1) htmlStr = strings.Replace(htmlStr, "\r", "", -1) tagRe, _ := regexp.Compile(`(?U)<.*>`) attrRe, _ := regexp.Compile(`([^=]+)=["']?([^"']+)`) capList := tagRe.FindAllStringIndex(htmlStr, -1) if capList != nil { var seg HTMLBasicSegmentType var parts []string pos := 0 for _, cap := range capList { if pos < cap[0] { seg.Cat = 'T' seg.Str = htmlStr[pos:cap[0]] seg.Attr = nil list = append(list, seg) } if htmlStr[cap[0]+1] == '/' { seg.Cat = 'C' seg.Str = strings.ToLower(htmlStr[cap[0]+2 : cap[1]-1]) seg.Attr = nil list = append(list, seg) } else { // Extract attributes parts = strings.Split(htmlStr[cap[0]+1:cap[1]-1], " ") if len(parts) > 0 { for j, part := range parts { if j == 0 { seg.Cat = 'O' seg.Str = strings.ToLower(parts[0]) seg.Attr = make(map[string]string) } else { attrList := attrRe.FindAllStringSubmatch(part, -1) if attrList != nil { for _, attr := range attrList { seg.Attr[strings.ToLower(attr[1])] = attr[2] } } } } list = append(list, seg) } } pos = cap[1] } if len(htmlStr) > pos { seg.Cat = 'T' seg.Str = htmlStr[pos:] seg.Attr = nil list = append(list, seg) } } else { list = append(list, HTMLBasicSegmentType{Cat: 'T', Str: htmlStr, Attr: nil}) } return }
go
func HTMLBasicTokenize(htmlStr string) (list []HTMLBasicSegmentType) { // This routine is adapted from http://www.fpdf.org/ list = make([]HTMLBasicSegmentType, 0, 16) htmlStr = strings.Replace(htmlStr, "\n", " ", -1) htmlStr = strings.Replace(htmlStr, "\r", "", -1) tagRe, _ := regexp.Compile(`(?U)<.*>`) attrRe, _ := regexp.Compile(`([^=]+)=["']?([^"']+)`) capList := tagRe.FindAllStringIndex(htmlStr, -1) if capList != nil { var seg HTMLBasicSegmentType var parts []string pos := 0 for _, cap := range capList { if pos < cap[0] { seg.Cat = 'T' seg.Str = htmlStr[pos:cap[0]] seg.Attr = nil list = append(list, seg) } if htmlStr[cap[0]+1] == '/' { seg.Cat = 'C' seg.Str = strings.ToLower(htmlStr[cap[0]+2 : cap[1]-1]) seg.Attr = nil list = append(list, seg) } else { // Extract attributes parts = strings.Split(htmlStr[cap[0]+1:cap[1]-1], " ") if len(parts) > 0 { for j, part := range parts { if j == 0 { seg.Cat = 'O' seg.Str = strings.ToLower(parts[0]) seg.Attr = make(map[string]string) } else { attrList := attrRe.FindAllStringSubmatch(part, -1) if attrList != nil { for _, attr := range attrList { seg.Attr[strings.ToLower(attr[1])] = attr[2] } } } } list = append(list, seg) } } pos = cap[1] } if len(htmlStr) > pos { seg.Cat = 'T' seg.Str = htmlStr[pos:] seg.Attr = nil list = append(list, seg) } } else { list = append(list, HTMLBasicSegmentType{Cat: 'T', Str: htmlStr, Attr: nil}) } return }
[ "func", "HTMLBasicTokenize", "(", "htmlStr", "string", ")", "(", "list", "[", "]", "HTMLBasicSegmentType", ")", "{", "list", "=", "make", "(", "[", "]", "HTMLBasicSegmentType", ",", "0", ",", "16", ")", "\n", "htmlStr", "=", "strings", ".", "Replace", "(", "htmlStr", ",", "\"\\n\"", ",", "\\n", ",", "\" \"", ")", "\n", "-", "1", "\n", "htmlStr", "=", "strings", ".", "Replace", "(", "htmlStr", ",", "\"\\r\"", ",", "\\r", ",", "\"\"", ")", "\n", "-", "1", "\n", "tagRe", ",", "_", ":=", "regexp", ".", "Compile", "(", "`(?U)<.*>`", ")", "\n", "attrRe", ",", "_", ":=", "regexp", ".", "Compile", "(", "`([^=]+)=[\"']?([^\"']+)`", ")", "\n", "capList", ":=", "tagRe", ".", "FindAllStringIndex", "(", "htmlStr", ",", "-", "1", ")", "\n", "}" ]
// HTMLBasicTokenize returns a list of HTML tags and literal elements. This is // done with regular expressions, so the result is only marginally better than // useless.
[ "HTMLBasicTokenize", "returns", "a", "list", "of", "HTML", "tags", "and", "literal", "elements", ".", "This", "is", "done", "with", "regular", "expressions", "so", "the", "result", "is", "only", "marginally", "better", "than", "useless", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/htmlbasic.go#L35-L92
train
jung-kurt/gofpdf
htmlbasic.go
HTMLBasicNew
func (f *Fpdf) HTMLBasicNew() (html HTMLBasicType) { html.pdf = f html.Link.ClrR, html.Link.ClrG, html.Link.ClrB = 0, 0, 128 html.Link.Bold, html.Link.Italic, html.Link.Underscore = false, false, true return }
go
func (f *Fpdf) HTMLBasicNew() (html HTMLBasicType) { html.pdf = f html.Link.ClrR, html.Link.ClrG, html.Link.ClrB = 0, 0, 128 html.Link.Bold, html.Link.Italic, html.Link.Underscore = false, false, true return }
[ "func", "(", "f", "*", "Fpdf", ")", "HTMLBasicNew", "(", ")", "(", "html", "HTMLBasicType", ")", "{", "html", ".", "pdf", "=", "f", "\n", "html", ".", "Link", ".", "ClrR", ",", "html", ".", "Link", ".", "ClrG", ",", "html", ".", "Link", ".", "ClrB", "=", "0", ",", "0", ",", "128", "\n", "html", ".", "Link", ".", "Bold", ",", "html", ".", "Link", ".", "Italic", ",", "html", ".", "Link", ".", "Underscore", "=", "false", ",", "false", ",", "true", "\n", "return", "\n", "}" ]
// HTMLBasicNew returns an instance that facilitates writing basic HTML in the // specified PDF file.
[ "HTMLBasicNew", "returns", "an", "instance", "that", "facilitates", "writing", "basic", "HTML", "in", "the", "specified", "PDF", "file", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/htmlbasic.go#L109-L114
train
jung-kurt/gofpdf
font.go
getInfoFromTrueType
func getInfoFromTrueType(fileStr string, msgWriter io.Writer, embed bool, encList encListType) (info fontInfoType, err error) { var ttf TtfType ttf, err = TtfParse(fileStr) if err != nil { return } if embed { if !ttf.Embeddable { err = fmt.Errorf("font license does not allow embedding") return } info.Data, err = ioutil.ReadFile(fileStr) if err != nil { return } info.OriginalSize = len(info.Data) } k := 1000.0 / float64(ttf.UnitsPerEm) info.FontName = ttf.PostScriptName info.Bold = ttf.Bold info.Desc.ItalicAngle = int(ttf.ItalicAngle) info.IsFixedPitch = ttf.IsFixedPitch info.Desc.Ascent = round(k * float64(ttf.TypoAscender)) info.Desc.Descent = round(k * float64(ttf.TypoDescender)) info.UnderlineThickness = round(k * float64(ttf.UnderlineThickness)) info.UnderlinePosition = round(k * float64(ttf.UnderlinePosition)) info.Desc.FontBBox = fontBoxType{ round(k * float64(ttf.Xmin)), round(k * float64(ttf.Ymin)), round(k * float64(ttf.Xmax)), round(k * float64(ttf.Ymax)), } // printf("FontBBox\n") // dump(info.Desc.FontBBox) info.Desc.CapHeight = round(k * float64(ttf.CapHeight)) info.Desc.MissingWidth = round(k * float64(ttf.Widths[0])) var wd int for j := 0; j < len(info.Widths); j++ { wd = info.Desc.MissingWidth if encList[j].name != ".notdef" { uv := encList[j].uv pos, ok := ttf.Chars[uint16(uv)] if ok { wd = round(k * float64(ttf.Widths[pos])) } else { fmt.Fprintf(msgWriter, "Character %s is missing\n", encList[j].name) } } info.Widths[j] = wd } // printf("getInfoFromTrueType/FontBBox\n") // dump(info.Desc.FontBBox) return }
go
func getInfoFromTrueType(fileStr string, msgWriter io.Writer, embed bool, encList encListType) (info fontInfoType, err error) { var ttf TtfType ttf, err = TtfParse(fileStr) if err != nil { return } if embed { if !ttf.Embeddable { err = fmt.Errorf("font license does not allow embedding") return } info.Data, err = ioutil.ReadFile(fileStr) if err != nil { return } info.OriginalSize = len(info.Data) } k := 1000.0 / float64(ttf.UnitsPerEm) info.FontName = ttf.PostScriptName info.Bold = ttf.Bold info.Desc.ItalicAngle = int(ttf.ItalicAngle) info.IsFixedPitch = ttf.IsFixedPitch info.Desc.Ascent = round(k * float64(ttf.TypoAscender)) info.Desc.Descent = round(k * float64(ttf.TypoDescender)) info.UnderlineThickness = round(k * float64(ttf.UnderlineThickness)) info.UnderlinePosition = round(k * float64(ttf.UnderlinePosition)) info.Desc.FontBBox = fontBoxType{ round(k * float64(ttf.Xmin)), round(k * float64(ttf.Ymin)), round(k * float64(ttf.Xmax)), round(k * float64(ttf.Ymax)), } // printf("FontBBox\n") // dump(info.Desc.FontBBox) info.Desc.CapHeight = round(k * float64(ttf.CapHeight)) info.Desc.MissingWidth = round(k * float64(ttf.Widths[0])) var wd int for j := 0; j < len(info.Widths); j++ { wd = info.Desc.MissingWidth if encList[j].name != ".notdef" { uv := encList[j].uv pos, ok := ttf.Chars[uint16(uv)] if ok { wd = round(k * float64(ttf.Widths[pos])) } else { fmt.Fprintf(msgWriter, "Character %s is missing\n", encList[j].name) } } info.Widths[j] = wd } // printf("getInfoFromTrueType/FontBBox\n") // dump(info.Desc.FontBBox) return }
[ "func", "getInfoFromTrueType", "(", "fileStr", "string", ",", "msgWriter", "io", ".", "Writer", ",", "embed", "bool", ",", "encList", "encListType", ")", "(", "info", "fontInfoType", ",", "err", "error", ")", "{", "var", "ttf", "TtfType", "\n", "ttf", ",", "err", "=", "TtfParse", "(", "fileStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "embed", "{", "if", "!", "ttf", ".", "Embeddable", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"font license does not allow embedding\"", ")", "\n", "return", "\n", "}", "\n", "info", ".", "Data", ",", "err", "=", "ioutil", ".", "ReadFile", "(", "fileStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "info", ".", "OriginalSize", "=", "len", "(", "info", ".", "Data", ")", "\n", "}", "\n", "k", ":=", "1000.0", "/", "float64", "(", "ttf", ".", "UnitsPerEm", ")", "\n", "info", ".", "FontName", "=", "ttf", ".", "PostScriptName", "\n", "info", ".", "Bold", "=", "ttf", ".", "Bold", "\n", "info", ".", "Desc", ".", "ItalicAngle", "=", "int", "(", "ttf", ".", "ItalicAngle", ")", "\n", "info", ".", "IsFixedPitch", "=", "ttf", ".", "IsFixedPitch", "\n", "info", ".", "Desc", ".", "Ascent", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "TypoAscender", ")", ")", "\n", "info", ".", "Desc", ".", "Descent", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "TypoDescender", ")", ")", "\n", "info", ".", "UnderlineThickness", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "UnderlineThickness", ")", ")", "\n", "info", ".", "UnderlinePosition", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "UnderlinePosition", ")", ")", "\n", "info", ".", "Desc", ".", "FontBBox", "=", "fontBoxType", "{", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Xmin", ")", ")", ",", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Ymin", ")", ")", ",", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Xmax", ")", ")", ",", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Ymax", ")", ")", ",", "}", "\n", "info", ".", "Desc", ".", "CapHeight", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "CapHeight", ")", ")", "\n", "info", ".", "Desc", ".", "MissingWidth", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Widths", "[", "0", "]", ")", ")", "\n", "var", "wd", "int", "\n", "for", "j", ":=", "0", ";", "j", "<", "len", "(", "info", ".", "Widths", ")", ";", "j", "++", "{", "wd", "=", "info", ".", "Desc", ".", "MissingWidth", "\n", "if", "encList", "[", "j", "]", ".", "name", "!=", "\".notdef\"", "{", "uv", ":=", "encList", "[", "j", "]", ".", "uv", "\n", "pos", ",", "ok", ":=", "ttf", ".", "Chars", "[", "uint16", "(", "uv", ")", "]", "\n", "if", "ok", "{", "wd", "=", "round", "(", "k", "*", "float64", "(", "ttf", ".", "Widths", "[", "pos", "]", ")", ")", "\n", "}", "else", "{", "fmt", ".", "Fprintf", "(", "msgWriter", ",", "\"Character %s is missing\\n\"", ",", "\\n", ")", "\n", "}", "\n", "}", "\n", "encList", "[", "j", "]", ".", "name", "\n", "}", "\n", "info", ".", "Widths", "[", "j", "]", "=", "wd", "\n", "}" ]
// getInfoFromTrueType returns information from a TrueType font
[ "getInfoFromTrueType", "returns", "information", "from", "a", "TrueType", "font" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/font.go#L85-L138
train
jung-kurt/gofpdf
font.go
makeFontEncoding
func makeFontEncoding(encList encListType, refEncFileStr string) (diffStr string, err error) { var refList encListType if refList, err = loadMap(refEncFileStr); err != nil { return } var buf fmtBuffer last := 0 for j := 32; j < 256; j++ { if encList[j].name != refList[j].name { if j != last+1 { buf.printf("%d ", j) } last = j buf.printf("/%s ", encList[j].name) } } diffStr = strings.TrimSpace(buf.String()) return }
go
func makeFontEncoding(encList encListType, refEncFileStr string) (diffStr string, err error) { var refList encListType if refList, err = loadMap(refEncFileStr); err != nil { return } var buf fmtBuffer last := 0 for j := 32; j < 256; j++ { if encList[j].name != refList[j].name { if j != last+1 { buf.printf("%d ", j) } last = j buf.printf("/%s ", encList[j].name) } } diffStr = strings.TrimSpace(buf.String()) return }
[ "func", "makeFontEncoding", "(", "encList", "encListType", ",", "refEncFileStr", "string", ")", "(", "diffStr", "string", ",", "err", "error", ")", "{", "var", "refList", "encListType", "\n", "if", "refList", ",", "err", "=", "loadMap", "(", "refEncFileStr", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "var", "buf", "fmtBuffer", "\n", "last", ":=", "0", "\n", "for", "j", ":=", "32", ";", "j", "<", "256", ";", "j", "++", "{", "if", "encList", "[", "j", "]", ".", "name", "!=", "refList", "[", "j", "]", ".", "name", "{", "if", "j", "!=", "last", "+", "1", "{", "buf", ".", "printf", "(", "\"%d \"", ",", "j", ")", "\n", "}", "\n", "last", "=", "j", "\n", "buf", ".", "printf", "(", "\"/%s \"", ",", "encList", "[", "j", "]", ".", "name", ")", "\n", "}", "\n", "}", "\n", "diffStr", "=", "strings", ".", "TrimSpace", "(", "buf", ".", "String", "(", ")", ")", "\n", "return", "\n", "}" ]
// makeFontEncoding builds differences from reference encoding
[ "makeFontEncoding", "builds", "differences", "from", "reference", "encoding" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/font.go#L314-L332
train
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", "(", "\"%x\"", ",", "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", ")", "{", "if", "page", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"Pages start at 1 No template will have a page 0\"", ")", "\n", "}", "\n", "if", "page", ">", "t", ".", "NumPages", "(", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"The template does not have a page %d\"", ",", "page", ")", "\n", "}", "\n", "if", "t", ".", "page", "==", "page", "{", "return", "t", ",", "nil", "\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", "++", "{", "p", "[", "x", "-", "1", "]", ",", "_", "=", "t", ".", "FromPage", "(", "x", ")", "\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", "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", "for", "x", ":=", "0", ";", "x", "<", "len", "(", "t", ".", "templates", ")", ";", "x", "++", "{", "imgs", ":=", "t", ".", "templates", "[", "x", "]", ".", "Images", "(", ")", "\n", "for", "key", ",", "val", ":=", "range", "imgs", "{", "name", ":=", "sprintf", "(", "\"t%s-%s\"", ",", "t", ".", "templates", "[", "x", "]", ".", "ID", "(", ")", ",", "key", ")", "\n", "childrenImgs", "[", "name", "]", "=", "val", "\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", "for", "x", ":=", "0", ";", "x", "<", "len", "(", "t", ".", "templates", ")", ";", "x", "++", "{", "tmpls", ":=", "t", ".", "templates", "[", "x", "]", ".", "Templates", "(", ")", "\n", "childrenTmpls", "=", "append", "(", "childrenTmpls", ",", "tmpls", "...", ")", "\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", "childrensTemplates", ":=", "t", ".", "childrensTemplates", "(", ")", "\n", "firstClassTemplates", ":=", "make", "(", "[", "]", "Template", ",", "0", ")", "\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", "firstClassTemplates", "=", "append", "(", "firstClassTemplates", ",", "t", ".", "templates", "[", "x", "]", ")", "\n", "}", "\n", "err", ":=", "encoder", ".", "Encode", "(", "firstClassTemplates", ")", "\n", "childrenImgs", ":=", "t", ".", "childrenImages", "(", ")", "\n", "firstClassImgs", ":=", "make", "(", "map", "[", "string", "]", "*", "ImageInfoType", ")", "\n", "for", "key", ",", "img", ":=", "range", "t", ".", "images", "{", "if", "_", ",", "ok", ":=", "childrenImgs", "[", "key", "]", ";", "!", "ok", "{", "firstClassImgs", "[", "key", "]", "=", "img", "\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", "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", "firstClassTemplates", ":=", "make", "(", "[", "]", "*", "FpdfTpl", ",", "0", ")", "\n", "err", ":=", "decoder", ".", "Decode", "(", "&", "firstClassTemplates", ")", "\n", "t", ".", "templates", "=", "make", "(", "[", "]", "Template", ",", "len", "(", "firstClassTemplates", ")", ")", "\n", "for", "x", ":=", "0", ";", "x", "<", "len", "(", "t", ".", "templates", ")", ";", "x", "++", "{", "t", ".", "templates", "[", "x", "]", "=", "Template", "(", "firstClassTemplates", "[", "x", "]", ")", "\n", "}", "\n", "firstClassImages", ":=", "t", ".", "childrenImages", "(", ")", "\n", "t", ".", "templates", "=", "append", "(", "t", ".", "childrensTemplates", "(", ")", ",", "t", ".", "templates", "...", ")", "\n", "t", ".", "images", "=", "make", "(", "map", "[", "string", "]", "*", "ImageInfoType", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "decoder", ".", "Decode", "(", "&", "t", ".", "images", ")", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "firstClassImages", "{", "t", ".", "images", "[", "k", "]", "=", "v", "\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", "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", "]", "!=", "\"gofpdf\"", ";", "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", "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", "(", "\"documents are different\"", ")", "\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", "{", "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", ")", "{", "fdt", ".", "File", "=", "\"\"", "\n", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "&", "fdt", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"%x\"", ",", "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", "==", "\"OTTO\"", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"fonts based on PostScript outlines are not supported\"", ")", "\n", "return", "\n", "}", "\n", "if", "version", "!=", "\"\\x00\\x01\\x00\\x00\"", "\\x00", "\n", "\\x01", "\n", "\\x00", "\n", "\\x00", "\n", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"unrecognized file format\"", ")", "\n", "return", "\n", "}", "\n", "numTables", ":=", "int", "(", "t", ".", "ReadUShort", "(", ")", ")", "\n", "t", ".", "Skip", "(", "3", "*", "2", ")", "\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", ")", "\n", "offset", ":=", "t", ".", "ReadULong", "(", ")", "\n", "t", ".", "Skip", "(", "4", ")", "\n", "t", ".", "tables", "[", "tag", "]", "=", "offset", "\n", "}", "\n", "err", "=", "t", ".", "ParseComponents", "(", ")", "\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", "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", ",", "\"Sum\"", ",", "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", ",", "\"Sum\"", ",", "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", "filename", ":=", "f", ".", "Name", "(", ")", "\n", "defer", "os", ".", "Remove", "(", "filename", ")", "\n", "if", "err", ":=", "f", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "cmd", ":=", "exec", ".", "Command", "(", "program", ",", "\"-output\"", ",", "filename", ")", "\n", "cmd", ".", "Stdout", "=", "os", ".", "Stdout", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n", "if", "err", ":=", "cmd", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "f", ",", "err", "=", "os", ".", "Open", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "pkg", "model", ".", "Package", "\n", "if", "err", ":=", "gob", ".", "NewDecoder", "(", "f", ")", ".", "Decode", "(", "&", "pkg", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "f", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\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", ")", "{", "tmpDir", ",", "err", ":=", "ioutil", ".", "TempDir", "(", "dir", ",", "\"gomock_reflect_\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "if", "err", ":=", "os", ".", "RemoveAll", "(", "tmpDir", ")", ";", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"failed to remove temp directory: %s\"", ",", "err", ")", "\n", "}", "\n", "}", "(", ")", "\n", "const", "progSource", "=", "\"prog.go\"", "\n", "var", "progBinary", "=", "\"prog.bin\"", "\n", "if", "runtime", ".", "GOOS", "==", "\"windows\"", "{", "progBinary", "+=", "\".exe\"", "\n", "}", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "filepath", ".", "Join", "(", "tmpDir", ",", "progSource", ")", ",", "program", ",", "0600", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "cmdArgs", ":=", "[", "]", "string", "{", "}", "\n", "cmdArgs", "=", "append", "(", "cmdArgs", ",", "\"build\"", ")", "\n", "if", "*", "buildFlags", "!=", "\"\"", "{", "cmdArgs", "=", "append", "(", "cmdArgs", ",", "*", "buildFlags", ")", "\n", "}", "\n", "cmdArgs", "=", "append", "(", "cmdArgs", ",", "\"-o\"", ",", "progBinary", ",", "progSource", ")", "\n", "cmd", ":=", "exec", ".", "Command", "(", "\"go\"", ",", "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", "(", "\"Woah! %v\"", ",", "err", ")", "\n", "}", "\n", "if", "len", "(", "keys", ")", ">", "0", "&&", "keys", "[", "0", "]", "==", "\"a\"", "{", "index", ".", "Ellip", "(", "\"%d\"", ",", "0", ",", "1", ",", "1", ",", "2", ",", "3", ")", "\n", "index", ".", "Ellip", "(", "\"%d\"", ",", "1", ",", "3", ",", "6", ",", "10", ",", "15", ")", "\n", "index", ".", "EllipOnly", "(", "\"arg\"", ")", "\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", "mt", ":=", "c", ".", "methodType", "\n", "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", ")", "\n", "}", "\n", "for", "i", ",", "ret", ":=", "range", "rets", "{", "if", "got", ",", "want", ":=", "reflect", ".", "TypeOf", "(", "ret", ")", ",", "mt", ".", "Out", "(", "i", ")", ";", "got", "==", "want", "{", "}", "else", "if", "got", "==", "nil", "{", "switch", "want", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Chan", ",", "reflect", ".", "Func", ",", "reflect", ".", "Interface", ",", "reflect", ".", "Map", ",", "reflect", ".", "Ptr", ",", "reflect", ".", "Slice", ":", "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", ")", "\n", "}", "\n", "}", "else", "if", "got", ".", "AssignableTo", "(", "want", ")", "{", "v", ":=", "reflect", ".", "New", "(", "want", ")", ".", "Elem", "(", ")", "\n", "v", ".", "Set", "(", "reflect", ".", "ValueOf", "(", "ret", ")", ")", "\n", "rets", "[", "i", "]", "=", "v", ".", "Interface", "(", ")", "\n", "}", "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", ")", "\n", "}", "\n", "}", "\n", "c", ".", "addAction", "(", "func", "(", "[", "]", "interface", "{", "}", ")", "[", "]", "interface", "{", "}", "{", "return", "rets", "\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", "mt", ":=", "c", ".", "methodType", "\n", "if", "n", "<", "0", "||", "n", ">=", "mt", ".", "NumIn", "(", ")", "{", "c", ".", "t", ".", "Fatalf", "(", "\"SetArg(%d, ...) called for a method with %d args [%s]\"", ",", "n", ",", "mt", ".", "NumIn", "(", ")", ",", "c", ".", "origin", ")", "\n", "}", "\n", "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", "(", "\"SetArg(%d, ...) argument is a %v, not assignable to %v [%s]\"", ",", "n", ",", "vt", ",", "dt", ",", "c", ".", "origin", ")", "\n", "}", "\n", "case", "reflect", ".", "Interface", ":", "case", "reflect", ".", "Slice", ":", "default", ":", "c", ".", "t", ".", "Fatalf", "(", "\"SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice type %v [%s]\"", ",", "n", ",", "at", ",", "c", ".", "origin", ")", "\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", "if", "c", "==", "preReq", "{", "c", ".", "t", ".", "Fatalf", "(", "\"A call isn't allowed to be its own prerequisite\"", ")", "\n", "}", "\n", "if", "preReq", ".", "isPreReq", "(", "c", ")", "{", "c", ".", "t", ".", "Fatalf", "(", "\"Loop in call order: %v is a prerequisite to %v (possibly indirectly).\"", ",", "c", ",", "preReq", ")", "\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", "=", "\"x\"", "\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", "return", "\"Mock\"", "+", "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", "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", "ia", ":=", "newIdentifierAllocator", "(", "argNames", ")", "\n", "idRecv", ":=", "ia", ".", "allocateIdentifier", "(", "\"m\"", ")", "\n", "g", ".", "p", "(", "\"// %v mocks base method\"", ",", "m", ".", "Name", ")", "\n", "g", ".", "p", "(", "\"func (%v *%v) %v(%v)%v {\"", ",", "idRecv", ",", "mockType", ",", "m", ".", "Name", ",", "argString", ",", "retString", ")", "\n", "g", ".", "in", "(", ")", "\n", "g", ".", "p", "(", "\"%s.ctrl.T.Helper()\"", ",", "idRecv", ")", "\n", "var", "callArgs", "string", "\n", "if", "m", ".", "Variadic", "==", "nil", "{", "if", "len", "(", "argNames", ")", ">", "0", "{", "callArgs", "=", "\", \"", "+", "strings", ".", "Join", "(", "argNames", ",", "\", \"", ")", "\n", "}", "\n", "}", "else", "{", "idVarArgs", ":=", "ia", ".", "allocateIdentifier", "(", "\"varargs\"", ")", "\n", "idVArg", ":=", "ia", ".", "allocateIdentifier", "(", "\"a\"", ")", "\n", "g", ".", "p", "(", "\"%s := []interface{}{%s}\"", ",", "idVarArgs", ",", "strings", ".", "Join", "(", "argNames", "[", ":", "len", "(", "argNames", ")", "-", "1", "]", ",", "\", \"", ")", ")", "\n", "g", ".", "p", "(", "\"for _, %s := range %s {\"", ",", "idVArg", ",", "argNames", "[", "len", "(", "argNames", ")", "-", "1", "]", ")", "\n", "g", ".", "in", "(", ")", "\n", "g", ".", "p", "(", "\"%s = append(%s, %s)\"", ",", "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", "(", "\"ret\"", ")", "\n", "g", ".", "p", "(", "`%v := %v.ctrl.Call(%v, %q%v)`", ",", "idRet", ",", "idRecv", ",", "idRecv", ",", "m", ".", "Name", ",", "callArgs", ")", "\n", "retNames", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "rets", ")", ")", "\n", "for", "i", ",", "t", ":=", "range", "rets", "{", "retNames", "[", "i", "]", "=", "ia", ".", "allocateIdentifier", "(", "fmt", ".", "Sprintf", "(", "\"ret%d\"", ",", "i", ")", ")", "\n", "g", ".", "p", "(", "\"%s, _ := %s[%d].(%s)\"", ",", "retNames", "[", "i", "]", ",", "idRet", ",", "i", ",", "t", ")", "\n", "}", "\n", "g", ".", "p", "(", "\"return \"", "+", "strings", ".", "Join", "(", "retNames", ",", "\", \"", ")", ")", "\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", "(", "\"Failed to format generated source code: %s\\n%s\"", ",", "\\n", ",", "err", ")", "\n", "}", "\n", "g", ".", "buf", ".", "String", "(", ")", "\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", "{", "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", "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%v\"", ",", "\\n", ")", "\n", "}", "else", "err", "\n", "}", "\n", "{", "return", "call", ",", "nil", "\n", "}", "\n", "exhausted", ":=", "cs", ".", "exhausted", "[", "key", "]", "\n", "for", "_", ",", "call", ":=", "range", "exhausted", "{", "if", "err", ":=", "call", ".", "matches", "(", "args", ")", ";", "err", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "&", "callsErrors", ",", "\"\\n%v\"", ",", "\\n", ")", "\n", "}", "\n", "}", "\n", "err", "\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", ",", "\"Anon\"", ",", "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", ",", "\"Anon\"", ",", "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", ",", "\"Chan\"", ",", "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", ",", "\"ConcreteRet\"", ")", "\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", ",", "\"Ellip\"", ",", "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", ",", "\"EllipOnly\"", ",", "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", ",", "\"ForeignFour\"", ",", "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", ",", "\"ForeignOne\"", ",", "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", ",", "\"ForeignThree\"", ",", "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", ",", "\"ForeignTwo\"", ",", "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", ",", "\"Func\"", ",", "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", ",", "\"GetTwo\"", ",", "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", ",", "\"Map\"", ",", "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", ",", "\"NillableRet\"", ")", "\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", ",", "\"Other\"", ")", "\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", ",", "\"Ptr\"", ",", "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", ",", "\"Slice\"", ",", "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", ",", "\"Struct\"", ",", "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", ",", "\"StructChan\"", ",", "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", ",", "\"Summary\"", ",", "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", ",", "\"Templates\"", ",", "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", ",", "\"ForeignEmbeddedMethod\"", ")", "\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", ",", "\"ForeignEmbeddedMethod\"", ",", "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", ",", "\"ImplicitPackage\"", ",", "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", ",", "\"ImplicitPackage\"", ",", "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", ",", "\"RegularMethod\"", ")", "\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", ",", "\"EmbeddedMethod\"", ",", "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