Best Syzkaller code snippet using prog.Append
re1.go
Source:re1.go
1// Package re1 implements a very simple regular expression language.2// The language is inspired by plan9 regular expressions3// (https://9fans.github.io/plan9port/man/man7/regexp.html),4// rsc's regexp blog posts (https://swtch.com/~rsc/regexp),5// and nominally by the much more sohpistocated RE2 library6// (https://github.com/google/re2).7//8// The grammar is:9// regexp = choice.10// choice = concat [ "|" choice ].11// concat = repeat [ concat ].12// repeat = term { "*" | "+" | "?" }.13// term = "." | "^" | "$" | "(" regexp ")" | charclass | literal.14// charclass = "[" [ "^" ] ( classlit [ "-" classlit ] ) { classlit [ "-" classlit ] } "]".15// A literal is any non-meta rune or a rune preceded by \.16// A classlit is any non-"]", non-"-" rune or a rune preceded by \.17//18// The meta characters are:19// | choice20// * zero or more, greedy21// + one or more, greedy22// ? zero or one23// . any non-newline rune24// ^ beginning of file or line25// $ end of file or line26// () capturing group27// [] character class (^ negates, - is a range)28// \n newline29// \t tab30// \ otherwise is the literal of the following rune31// or is \ itself if there is no following rune.32package re133import (34 "errors"35 "io"36 "strings"37 "unicode/utf8"38)39// Regexp is a compiled regular expression.40type Regexp struct {41 prog []instr42 ncap int43 class [][][2]rune44 source string45}46// Opts are compile-time options. The zero value is default.47type Opts struct {48 // Reverse compiles the expression for reverse matching.49 // This swaps the order of concatenations, and it swaps ^ and $.50 Reverse bool51 // Delimiter specifies a rune that delimits parsing if unescaped.52 Delimiter rune53 // ID is a user-specfied ID to identify the the regexp.54 // This is used to distinguish which regexp matched55 // when concatenating multiple regexps into one.56 ID int57}58// New compiles a regular expression.59// The expression is terminated by the end of the string,60// an un-escaped newline,61// or an un-escaped delimiter (if set in opts).62func New(t string, opts Opts) (*Regexp, string, error) {63 src := t64 switch re, t, err := choice(t, 0, opts); {65 case err != nil:66 return nil, "", err67 case re == nil:68 re = &Regexp{}69 fallthrough70 default:71 re = groupProg(re)72 re.prog = append(re.prog, instr{op: match, arg: opts.ID})73 re.source = src74 return re, t, nil75 }76}77const (78 any = -iota79 bol80 eol81 class // arg is class index82 nclass // arg is class index83 jmp // arg is jump offset84 fork // arg is low-priority fork offset (high-priority is 1)85 rfork // arg is high-priority fork offset (low-priority is 1)86 save // arg is save-to index87 match // arg is the id of the matching regexp88)89type instr struct {90 op int91 arg int92}93func choice(t0 string, depth int, opts Opts) (*Regexp, string, error) {94 switch left, t, err := concat(t0, depth, opts); {95 case err != nil:96 return nil, "", err97 case peek(t) != '|':98 return left, t, nil99 case left == nil:100 return nil, "", errors.New("unexpected |")101 default:102 _, t = next(t) // eat |103 var right *Regexp104 if right, t, err = choice(t, depth, opts); err != nil {105 return nil, "", err106 }107 return choiceProg(left, right), t, nil108 }109}110func concat(t string, depth int, opts Opts) (*Regexp, string, error) {111 left, t, err := repeat(t, depth, opts)112 if left == nil || err != nil {113 return left, t, err114 }115 var right *Regexp116 switch right, t, err = concat(t, depth, opts); {117 case err != nil:118 return nil, "", err119 case right != nil:120 left = catProg(left, right, opts.Reverse)121 fallthrough122 default:123 return left, t, err124 }125}126func repeat(t string, depth int, opts Opts) (*Regexp, string, error) {127 left, t, err := term(t, depth, opts)128 if left == nil || err != nil {129 return left, t, err130 }131 for strings.ContainsRune("*+?", peek(t)) {132 var r rune133 r, t = next(t)134 left = repProg(left, r)135 }136 return left, t, nil137}138func term(t0 string, depth int, opts Opts) (*Regexp, string, error) {139 switch r, t := next(t0); r {140 case eof, '\n', opts.Delimiter:141 return nil, t, nil142 case '\\':143 r, t = esc(t)144 fallthrough145 default:146 return opProg(int(r)), t, nil147 case '.':148 return opProg(any), t, nil149 case '^':150 if opts.Reverse {151 return opProg(eol), t, nil152 }153 return opProg(bol), t, nil154 case '$':155 if opts.Reverse {156 return opProg(bol), t, nil157 }158 return opProg(eol), t, nil159 case '(':160 return group(t, depth, opts)161 case '[':162 return charclass(t)163 case '|':164 return nil, t0, nil165 case ')':166 if depth == 0 {167 return nil, t, errors.New("unopened )")168 }169 return nil, t0, nil170 case '*', '+', '?':171 return nil, "", errors.New("unexpected " + string([]rune{r}))172 }173}174func group(t string, depth int, opts Opts) (*Regexp, string, error) {175 left, t, err := choice(t, depth+1, opts)176 switch r, t := next(t); {177 case err != nil:178 return nil, "", err179 case r != ')':180 return nil, "", errors.New("unclosed (")181 case left == nil:182 left = &Regexp{}183 fallthrough184 default:185 return groupProg(left), t, nil186 }187}188func charclass(t string) (*Regexp, string, error) {189 op := class190 if peek(t) == '^' {191 _, t = next(t) // eat ^192 op = nclass193 }194 var r, p rune195 var cl [][2]rune196 for len(t) > 0 {197 switch r, t = next(t); r {198 case ']':199 if p != 0 {200 cl = append(cl, [2]rune{p, p})201 }202 if len(cl) == 0 {203 return nil, "", errors.New("empty charclass")204 }205 return charClassProg(op, cl), t, nil206 case '-':207 if p == 0 || peek(t) == ']' || peek(t) == '-' {208 return nil, "", errors.New("bad range")209 }210 r, t = next(t)211 if r == '\\' {212 r, t = esc(t)213 }214 if p >= r {215 return nil, "", errors.New("bad range")216 }217 cl = append(cl, [2]rune{p, r})218 p = 0219 case '\\':220 r, t = esc(t)221 fallthrough222 default:223 if p != 0 {224 cl = append(cl, [2]rune{p, p})225 }226 p = r227 }228 }229 return nil, "", errors.New("unclosed [")230}231func choiceProg(left, right *Regexp) *Regexp {232 prog := make([]instr, 0, 2+len(left.prog)+len(right.prog))233 prog = append(prog, instr{op: fork, arg: len(left.prog) + 2})234 prog = append(prog, left.prog...)235 left.prog = append(prog, instr{op: jmp, arg: len(right.prog) + 1})236 return catProg(left, right, false)237}238func catProg(left, right *Regexp, rev bool) *Regexp {239 for i := range right.prog {240 instr := &right.prog[i]241 if instr.op == save {242 instr.arg += left.ncap * 2243 }244 }245 if rev {246 left, right = right, left247 }248 for _, instr := range right.prog {249 if instr.op == class || instr.op == nclass {250 instr.arg += len(left.class)251 }252 left.prog = append(left.prog, instr)253 }254 left.ncap += right.ncap255 left.class = append(left.class, right.class...)256 return left257}258func repProg(left *Regexp, op rune) *Regexp {259 prog := make([]instr, 0, len(left.prog)+2)260 switch op {261 case '+':262 prog = append(left.prog, instr{op: rfork, arg: -len(left.prog)})263 case '*':264 prog = []instr{{op: fork, arg: len(left.prog) + 2}}265 prog = append(prog, left.prog...)266 prog = append(prog, instr{op: rfork, arg: -len(prog) + 1})267 case '?':268 prog = []instr{{op: fork, arg: len(left.prog) + 1}}269 prog = append(prog, left.prog...)270 }271 left.prog = prog272 return left273}274func groupProg(left *Regexp) *Regexp {275 prog := make([]instr, 0, len(left.prog)+2)276 prog = append(prog, instr{op: save, arg: 0})277 for _, instr := range left.prog {278 if instr.op == save {279 instr.arg += 2280 }281 prog = append(prog, instr)282 }283 left.prog = append(prog, instr{op: save, arg: 1})284 left.ncap++285 return left286}287func charClassProg(op int, cl [][2]rune) *Regexp {288 return &Regexp{prog: []instr{{op: op}}, class: [][][2]rune{cl}}289}290func opProg(op int) *Regexp { return &Regexp{prog: []instr{{op: op}}} }291const eof = -1292func next(t string) (rune, string) {293 if len(t) == 0 {294 return eof, ""295 }296 r, w := utf8.DecodeRuneInString(t)297 return r, t[w:]298}299func peek(t string) rune {300 r, _ := next(t)301 return r302}303func esc(t string) (rune, string) {304 var r rune305 switch r, t = next(t); r {306 case eof:307 r = '\\'308 case 'n':309 r = '\n'310 case 't':311 r = '\t'312 }313 return r, t314}315// Find returns nil on no match or a slice with pairs of int64s for each sub-expression match (0 is the full match) and the last element is the matching regexp ID.316func (re *Regexp) Find(rr io.RuneReader) []int64 { return run(newVM(re, rr)) }317type vm struct {318 re *Regexp319 rr io.RuneReader320 at, lim int64321 c, n rune // cur and next rune.322 seen []int64 // at for which each pc was last add()ed.323 cur, next []thread324 free [][]int64325 match []int64326}327type thread struct {328 pc int329 mem []int64330}331func newVM(re *Regexp, rr io.RuneReader) *vm {332 v := &vm{re: re, rr: rr, lim: -1, c: eof, n: eof}333 v.seen = make([]int64, len(re.prog))334 for i := range v.seen {335 v.seen[i] = -1336 }337 read(v)338 return v339}340func newMem(v *vm, init []int64) (m []int64) {341 if n := len(v.free); n > 0 {342 m, v.free = v.free[n-1], v.free[:n-1]343 } else {344 m = make([]int64, 2*v.re.ncap+1 /* match ID */)345 }346 if init != nil {347 copy(m, init)348 return m349 }350 for i := range m {351 m[i] = -1352 }353 return m354}355func run(v *vm) []int64 {356 for {357 if v.match == nil {358 add(v, 0, newMem(v, nil))359 }360 if v.lim >= 0 && v.at >= v.lim {361 // Check this after add() to allow empty regexps to match empty.362 return v.match363 }364 read(v)365 v.cur, v.next = v.next, v.cur[:0]366 for _, t := range v.cur {367 step(v, t.pc, t.mem)368 }369 if v.c == eof || (v.match != nil && len(v.next) == 0) {370 return v.match371 }372 }373}374func read(v *vm) {375 if v.n != eof {376 v.at += int64(utf8.RuneLen(v.n))377 }378 v.c = v.n379 var err error380 if v.n, _, err = v.rr.ReadRune(); err != nil {381 v.n = eof382 }383}384func step(v *vm, pc int, mem []int64) {385 if !accepts(v, v.re.prog[pc]) {386 v.free = append(v.free, mem)387 return388 }389 add(v, pc+1, mem)390}391func accepts(v *vm, instr instr) bool {392 switch instr.op {393 case any:394 return v.c != '\n' && v.c != eof395 case class, nclass:396 cl := v.re.class[instr.arg]397 return classAccepts(v.c, cl, instr.op == nclass)398 default:399 return int(v.c) == instr.op400 }401}402func classAccepts(r rune, class [][2]rune, neg bool) bool {403 if r == eof {404 return false405 }406 for _, c := range class {407 if c[0] <= r && r <= c[1] {408 return !neg409 }410 }411 return neg412}413func add(v *vm, pc int, mem []int64) {414 if v.seen[pc] == v.at {415 v.free = append(v.free, mem)416 return417 }418 v.seen[pc] = v.at419 _add(v, pc, mem)420}421func _add(v *vm, pc int, mem []int64) {422 switch instr := v.re.prog[pc]; instr.op {423 default:424 v.next = append(v.next, thread{pc: pc, mem: mem})425 case jmp:426 add(v, pc+instr.arg, mem)427 case fork:428 clone := newMem(v, mem)429 add(v, pc+1, mem)430 add(v, pc+instr.arg, clone)431 case rfork:432 clone := newMem(v, mem)433 add(v, pc+instr.arg, mem)434 add(v, pc+1, clone)435 case save:436 mem[instr.arg] = v.at437 add(v, pc+1, mem)438 case bol:439 if v.c != eof && v.c != '\n' {440 v.free = append(v.free, mem)441 return442 }443 add(v, pc+1, mem)444 case eol:445 if v.n != eof && v.n != '\n' {446 v.free = append(v.free, mem)447 return448 }449 add(v, pc+1, mem)450 case match:451 mem[len(mem)-1] = int64(instr.arg)452 setMatch(v, mem)453 }454}455func setMatch(v *vm, mem []int64) {456 switch {457 case v.match == nil:458 v.match = mem459 case mem[0] <= v.match[0] && mem[1] > v.match[1]:460 v.free = append(v.free, v.match)461 v.match = mem462 default:463 v.free = append(v.free, mem)464 }465}...
compile.go
Source:compile.go
1package kbd2import (3 "math"4 "github.com/zyedidia/gpeg/charset"5)6type Pattern interface {7 Compile() Program8}9type AltNode struct {10 s1 Pattern11 s2 Pattern12}13func Alt(s ...Pattern) Pattern {14 acc := s[len(s)-1]15 for i := len(s) - 2; i >= 0; i-- {16 acc = &AltNode{17 s1: s[i],18 s2: acc,19 }20 }21 return acc22}23func (n *AltNode) Compile() Program {24 p1 := n.s1.Compile()25 p2 := n.s2.Compile()26 var prog Program27 prog = append(prog, iSplit{1, len(p1) + 2})28 prog = append(prog, p1...)29 prog = append(prog, iJump{len(p2) + 1})30 prog = append(prog, p2...)31 return prog32}33type SeqNode struct {34 s1 Pattern35 s2 Pattern36}37func Seq(s ...Pattern) Pattern {38 acc := s[0]39 for _, p := range s[1:] {40 acc = &SeqNode{41 s1: acc,42 s2: p,43 }44 }45 return acc46}47func (n *SeqNode) Compile() Program {48 p1 := n.s1.Compile()49 p2 := n.s2.Compile()50 var prog Program51 prog = append(prog, p1...)52 prog = append(prog, p2...)53 return prog54}55type StarNode struct {56 s Pattern57}58func Star(s Pattern) *StarNode {59 return &StarNode{60 s: s,61 }62}63func (n *StarNode) Compile() Program {64 p := n.s.Compile()65 var prog Program66 prog = append(prog, iSplit{1, len(p) + 2})67 prog = append(prog, p...)68 prog = append(prog, iJump{-len(p) - 1})69 return prog70}71type PlusNode struct {72 s Pattern73}74func Plus(s Pattern) *PlusNode {75 return &PlusNode{76 s: s,77 }78}79func (n *PlusNode) Compile() Program {80 p := n.s.Compile()81 var prog Program82 prog = append(prog, p...)83 prog = append(prog, iSplit{-len(p), 1})84 return prog85}86type OptNode struct {87 s Pattern88}89func Opt(s Pattern) *OptNode {90 return &OptNode{91 s: s,92 }93}94func (n *OptNode) Compile() Program {95 p := n.s.Compile()96 var prog Program97 prog = append(prog, iSplit{1, len(p) + 1})98 prog = append(prog, p...)99 return prog100}101type LitNode struct {102 ev Event103}104func Lit(ev Event) *LitNode {105 return &LitNode{106 ev: ev,107 }108}109func MustLit(s string) *LitNode {110 ev, err := ToEvent(s)111 if err != nil {112 panic(err)113 }114 return &LitNode{115 ev: ev,116 }117}118func AnyRune() *LitNode {119 return &LitNode{120 ev: &WildcardRuneEvent{121 Low: 0,122 High: math.MaxInt32,123 },124 }125}126func RangeRune(low, high rune) *LitNode {127 return &LitNode{128 ev: &WildcardRuneEvent{129 Low: low,130 High: high,131 },132 }133}134func Set(s charset.Set) *LitNode {135 return &LitNode{136 ev: &WildcardRuneSetEvent{137 Set: s,138 },139 }140}141func (n *LitNode) Compile() Program {142 return Program{143 iConsume{144 match: n.ev,145 },146 }147}148type CapNode struct {149 s Pattern150 cmd string151}152func Cap(n Pattern, cmd string) *CapNode {153 return &CapNode{154 s: n,155 cmd: cmd,156 }157}158func (c *CapNode) Compile() Program {159 p := c.s.Compile()160 var prog Program161 prog = append(prog, iCapStart{})162 prog = append(prog, p...)163 prog = append(prog, iCapEnd{c.cmd})164 return prog165}166type EndNode struct{}167func End() *EndNode {168 return &EndNode{}169}170func (n *EndNode) Compile() Program {171 return Program{172 iEnd{},173 }174}175type NonTermNode struct {176 name string177}178func NonTerm(name string) Pattern {179 return &NonTermNode{180 name: name,181 }182}183func (n *NonTermNode) Compile() Program {184 var prog Program185 prog = append(prog, iOpenCall{n.name})186 return prog187}188type GrammarNode struct {189 fns map[string]Pattern190 root string191}192func Grammar(root string, fns map[string]Pattern) Pattern {193 return &GrammarNode{194 fns: fns,195 root: root,196 }197}198func (n *GrammarNode) Compile() Program {199 var prog Program200 prog = append(prog, iOpenCall{n.root})201 prog = append(prog, iEnd{})202 fnlocs := make(map[string]int)203 i := len(prog)204 for name, fn := range n.fns {205 fnlocs[name] = i206 fnprog := fn.Compile()207 prog = append(prog, fnprog...)208 prog = append(prog, iRet{})209 i += 1 + len(fnprog)210 }211 for j, insn := range prog {212 switch t := insn.(type) {213 case iOpenCall:214 prog[j] = iCall{fnlocs[t.name]}215 }216 }217 return prog218}...
prog.go
Source:prog.go
1package dtfmt2import (3 "errors"4 "time"5)6type prog struct {7 p []byte8}9const (10 opNone byte = iota11 opCopy1 // copy next byte12 opCopy2 // copy next 2 bytes13 opCopy3 // copy next 3 bytes14 opCopy4 // copy next 4 bytes15 opCopyShort // [op, len, content[len]]16 opCopyLong // [op, len1, len, content[len1<<8 + len]]17 opNum // [op, ft]18 opNumPadded // [op, ft, digits]19 opTwoDigit // [op, ft]20 opTextShort // [op, ft]21 opTextLong // [op, ft]22)23func (p prog) eval(bytes []byte, ctx *ctx, t time.Time) ([]byte, error) {24 for i := 0; i < len(p.p); {25 op := p.p[i]26 i++27 switch op {28 case opNone:29 case opCopy1:30 bytes = append(bytes, p.p[i])31 i++32 case opCopy2:33 bytes = append(bytes, p.p[i], p.p[i+1])34 i += 235 case opCopy3:36 bytes = append(bytes, p.p[i], p.p[i+1], p.p[i+2])37 i += 338 case opCopy4:39 bytes = append(bytes, p.p[i], p.p[i+1], p.p[i+2], p.p[i+3])40 i += 441 case opCopyShort:42 l := int(p.p[i])43 i++44 bytes = append(bytes, p.p[i:i+l]...)45 i += l46 case opCopyLong:47 l := int(p.p[i])<<8 | int(p.p[i+1])48 i += 249 bytes = append(bytes, p.p[i:i+l]...)50 i += l51 case opNum:52 ft := fieldType(p.p[i])53 i++54 v, err := getIntField(ft, ctx, t)55 if err != nil {56 return bytes, err57 }58 bytes = appendUnpadded(bytes, v)59 case opNumPadded:60 ft, digits := fieldType(p.p[i]), int(p.p[i+1])61 i += 262 v, err := getIntField(ft, ctx, t)63 if err != nil {64 return bytes, err65 }66 bytes = appendPadded(bytes, v, digits)67 case opTwoDigit:68 ft := fieldType(p.p[i])69 i++70 v, err := getIntField(ft, ctx, t)71 if err != nil {72 return bytes, err73 }74 bytes = appendPadded(bytes, v%100, 2)75 case opTextShort:76 ft := fieldType(p.p[i])77 i++78 s, err := getTextFieldShort(ft, ctx, t)79 if err != nil {80 return bytes, err81 }82 bytes = append(bytes, s...)83 case opTextLong:84 ft := fieldType(p.p[i])85 i++86 s, err := getTextField(ft, ctx, t)87 if err != nil {88 return bytes, err89 }90 bytes = append(bytes, s...)91 default:92 return bytes, errors.New("unknown opcode")93 }94 }95 return bytes, nil96}97func makeProg(b ...byte) (prog, error) {98 return prog{b}, nil99}100func makeCopy(b []byte) (prog, error) {101 l := len(b)102 switch l {103 case 0:104 return prog{}, nil105 case 1:106 return makeProg(opCopy1, b[0])107 case 2:108 return makeProg(opCopy2, b[0], b[1])109 case 3:110 return makeProg(opCopy2, b[0], b[1], b[2])111 case 4:112 return makeProg(opCopy2, b[0], b[1], b[2], b[3])113 }114 if l < 256 {115 return prog{append([]byte{opCopyShort, byte(l)}, b...)}, nil116 }117 if l < (1 << 16) {118 l1 := byte(l >> 8)119 l2 := byte(l)120 return prog{append([]byte{opCopyLong, l1, l2}, b...)}, nil121 }122 return prog{}, errors.New("literal too long")123}...
Append
Using AI Code Generation
1import "fmt"2func main() {3 printSlice(s)4 s = append(s, 0)5 printSlice(s)6 s = append(s, 1)7 printSlice(s)8 s = append(s, 2,3,4)9 printSlice(s)10}11func printSlice(s []int) {12 fmt.Printf("len=%d cap=%d %v13", len(s), cap(s), s)14}
Append
Using AI Code Generation
1import "fmt"2type prog struct {3}4func main() {5 p1 := prog{"Go", 2009}6 p2 := prog{"C", 1972}7 p3 := prog{"Python", 1991}8 p4 := prog{"Java", 1995}9 fmt.Println(p1, p2, p3, p4)10 langs := []prog{p1, p2, p3, p4}11 fmt.Println(langs)12 langs = append(langs, prog{"Ruby", 1995})13 fmt.Println(langs)14 langs = append(langs, prog{"JavaScript", 1995}, prog{"C++", 1983})15 fmt.Println(langs)16 x := []prog{{"C#", 2000}, {"PHP", 1994}}17 langs = append(langs, x...)18 fmt.Println(langs)19}20{Go 2009} {C 1972} {Python 1991} {Java 1995}21[{Go 2009} {C 1972} {Python 1991} {Java 1995}]22[{Go 2009} {C 1972} {Python 1991} {Java 1995} {Ruby 1995}]23[{Go 2009} {C 1972} {Python 1991} {Java 1995} {Ruby 1995} {JavaScript 1995} {C++ 1983}]24[{Go 2009} {C 1972} {Python 1991} {Java 1995} {Ruby 1995} {JavaScript 1995} {C++ 1983} {C# 2000} {PHP 1994}]25import "fmt"26func main() {27 s1 := []int{1, 2, 3, 4, 5}28 s2 := []int{6, 7, 8, 9, 10}29 s3 := append(s1, s2...)30 fmt.Println(s1, s2, s3)31}
Append
Using AI Code Generation
1import (2func main() {3 str.WriteString("Hello")4 fmt.Println(str.String())5 str.WriteString(" world")6 fmt.Println(str.String())7 str.WriteString("!")8 fmt.Println(str.String())9}10import (11func main() {12 str.WriteString("Hello")13 fmt.Println(str.String())14 str.WriteString(" world")15 fmt.Println(str.String())16 str.WriteString("!")17 fmt.Println(str.String())18 str.Reset()19 fmt.Println(str.String())20}21import (22func main() {23 str.WriteString("Hello")24 fmt.Println(str.String())25 str.WriteString(" world")26 fmt.Println(str.String())27 str.WriteString("!")28 fmt.Println(str.String())29 str.Reset()30 fmt.Println(str.String())31 str.WriteString("Hello")32 fmt.Println(str.String())33}34import (35func main() {36 str.WriteString("Hello")37 fmt.Println(str.String())38 str.WriteString(" world")39 fmt.Println(str.String())40 str.WriteString("!")41 fmt.Println(str.String())42 str.Reset()43 fmt.Println(str.String())44 str.WriteString("Hello")45 fmt.Println(str.String())46 str.WriteString(" world")47 fmt.Println(str.String())48}49import (50func main() {51 str.WriteString("Hello")52 fmt.Println(str.String())53 str.WriteString(" world")54 fmt.Println(str.String())55 str.WriteString("!")56 fmt.Println(str.String())57 str.Reset()58 fmt.Println(str.String())59 str.WriteString("Hello")60 fmt.Println(str.String())61 str.WriteString(" world")62 fmt.Println(str.String())63 str.WriteString("!")64 fmt.Println(str.String())65}66import (67func main() {68 str.WriteString("Hello")69 fmt.Println(str.String())70 str.WriteString(" world")71 fmt.Println(str.String())72 str.WriteString("!")73 fmt.Println(str.String())74 str.Reset()75 fmt.Println(str.String())76 str.WriteString("Hello")77 fmt.Println(str.String
Append
Using AI Code Generation
1func main() {2 fmt.Println("Hello World")3 fmt.Println("Hello World")4 fmt.Println("Hello World")5 fmt.Println("Hello World")6 fmt.Println("Hello World")7}8func main() {9 fmt.Println("Hello World")10 fmt.Println("Hello World")11 fmt.Println("Hello World")12 fmt.Println("Hello World")13 fmt.Println("Hello World")14}15func main() {16 fmt.Println("Hello World")17 fmt.Println("Hello World")18 fmt.Println("Hello World")19 fmt.Println("Hello World")20 fmt.Println("Hello World")21}22func main() {23 fmt.Println("Hello World")24 fmt.Println("Hello World")25 fmt.Println("Hello World")26 fmt.Println("Hello World")27 fmt.Println("Hello World")28}29func main() {30 fmt.Println("Hello World")31 fmt.Println("Hello World")32 fmt.Println("Hello World")33 fmt.Println("Hello World")34 fmt.Println("Hello World")35}36func main() {37 fmt.Println("Hello World")38 fmt.Println("Hello World")39 fmt.Println("Hello World")40 fmt.Println("Hello World")41 fmt.Println("Hello World")42}43func main() {44 fmt.Println("Hello World")45 fmt.Println("Hello World")46 fmt.Println("Hello World")47 fmt.Println("Hello World")48 fmt.Println("Hello World")49}50func main() {51 fmt.Println("Hello World")52 fmt.Println("Hello World")53 fmt.Println("Hello World")54 fmt.Println("Hello World")55 fmt.Println("Hello World")56}57func main() {58 fmt.Println("Hello World")59 fmt.Println("Hello World")60 fmt.Println("Hello World")61 fmt.Println("Hello World")62 fmt.Println("Hello World")63}
Append
Using AI Code Generation
1import (2func main() {3 prog := new(Prog)4 prog.Append("Hello")5 prog.Append("World")6 fmt.Println(prog.String())7}8import (9type Prog struct {10}11func (p *Prog) Append(s string) {12 p.strings = append(p.strings, s)13}14func (p *Prog) String() string {15 return strings.Join(p.strings, " ")16}
Append
Using AI Code Generation
1import (2func main() {3 p1 := prog{1, 2, 3, 4, 5}4 fmt.Println("Before Append:", p1)5 p1.Append(6)6 fmt.Println("After Append:", p1)7}8Before Append: {1 2 3 4 5}9After Append: {1 2 3 4 5 6}10import (11func main() {12 p1 := prog{1, 2, 3, 4, 5}13 fmt.Println("Before Append:", p1)14 p1.Append(6, 7, 8, 9, 10)15 fmt.Println("After Append:", p1)16}17Before Append: {1 2 3 4 5}18After Append: {1 2 3 4 5 6 7 8 9 10}19import (20func main() {21 p1 := prog{1, 2, 3, 4, 5}22 fmt.Println("Before Append:", p1)23 p1.Append(6, 7, 8, 9, 10, 11, 12, 13, 14, 15)24 fmt.Println("After Append:", p1)25}26Before Append: {1 2 3 4 5}27After Append: {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15}28import (29func main() {30 p1 := prog{1, 2, 3, 4, 5}31 fmt.Println("Before Append:", p1)
Append
Using AI Code Generation
1import "fmt"2func main() {3 var s = prog{[]string{"C", "C++", "Java", "Python"}, "C"}4 s.Append("Golang")5 fmt.Println(s)6}7import "fmt"8func main() {9 var s = prog{[]string{"C", "C++", "Java", "Python"}, "C"}10 s.Add("Golang")11 fmt.Println(s)12}13import "fmt"14func main() {15 var s = prog{[]string{"C", "C++", "Java", "Python"}, "C"}16 s.Delete("C++")17 fmt.Println(s)18}19import "fmt"20func main() {21 var s = prog{[]string{"C", "C++", "Java", "Python"}, "C"}22 s.Update("C++", "Golang")23 fmt.Println(s)24}25import "fmt"26func main() {27 var s = prog{[]string{"C", "C++", "Java", "Python"}, "C"}28 s.Replace("C++", "Golang")29 fmt.Println(s)30}31import "fmt"32func main() {33 var s = prog{[]string{"C", "C++", "Java", "Python"}, "C"}34 fmt.Println(s.Find("C++"))35}36import "fmt"37func main() {38 var s = prog{[]string{"C", "C++", "Java", "
Append
Using AI Code Generation
1import (2func main() {3 fmt.Println(prog.Append("Hello ", "World"))4}5import (6func main() {7 fmt.Println(prog.Append("Hello ", "World"))8}9import (10func main() {11 fmt.Println(prog.Append("Hello ", "World"))12}13import (14func main() {15 fmt.Println(prog.Append("Hello ", "World"))16}17import (18func main() {19 fmt.Println(prog.Append("Hello ", "World"))20}21import (22func main() {23 fmt.Println(prog.Append("Hello ", "World"))24}25import (26func main() {27 fmt.Println(prog.Append("Hello ", "World"))28}29import (30func main() {31 fmt.Println(prog.Append("Hello ", "World"))32}33import (
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!