Best Syzkaller code snippet using prog.isReadableData
encoding.go
Source:encoding.go
...113 }114 if typ.Varlen() && len(data)+8 >= sz {115 data = data[:sz]116 }117 serializeData(ctx.buf, data, isReadableDataType(typ))118 if typ.Varlen() && sz != len(data) {119 ctx.printf("/%v", sz)120 }121}122func (a *GroupArg) serialize(ctx *serializer) {123 var delims []byte124 switch a.Type().(type) {125 case *StructType:126 delims = []byte{'{', '}'}127 case *ArrayType:128 delims = []byte{'[', ']'}129 default:130 panic("unknown group type")131 }132 ctx.buf.WriteByte(delims[0])133 lastNonDefault := len(a.Inner) - 1134 if !ctx.verbose && a.fixedInnerSize() {135 for ; lastNonDefault >= 0; lastNonDefault-- {136 if !isDefault(a.Inner[lastNonDefault]) {137 break138 }139 }140 }141 for i := 0; i <= lastNonDefault; i++ {142 arg1 := a.Inner[i]143 if arg1 != nil && IsPad(arg1.Type()) {144 continue145 }146 if i != 0 {147 ctx.printf(", ")148 }149 ctx.arg(arg1)150 }151 ctx.buf.WriteByte(delims[1])152}153func (a *UnionArg) serialize(ctx *serializer) {154 typ := a.Type().(*UnionType)155 ctx.printf("@%v", typ.Fields[a.Index].Name)156 if !ctx.verbose && isDefault(a.Option) {157 return158 }159 ctx.printf("=")160 ctx.arg(a.Option)161}162func (a *ResultArg) serialize(ctx *serializer) {163 if len(a.uses) != 0 {164 ctx.printf("<r%v=>", ctx.allocVarID(a))165 }166 if a.Res == nil {167 ctx.printf("0x%x", a.Val)168 return169 }170 id, ok := ctx.vars[a.Res]171 if !ok {172 panic("no result")173 }174 ctx.printf("r%v", id)175 if a.OpDiv != 0 {176 ctx.printf("/%v", a.OpDiv)177 }178 if a.OpAdd != 0 {179 ctx.printf("+%v", a.OpAdd)180 }181}182type DeserializeMode int183const (184 Strict DeserializeMode = iota185 NonStrict DeserializeMode = iota186)187func (target *Target) Deserialize(data []byte, mode DeserializeMode) (*Prog, error) {188 defer func() {189 if err := recover(); err != nil {190 panic(fmt.Errorf("%v\ntarget: %v/%v, rev: %v, mode=%v, prog:\n%q",191 err, target.OS, target.Arch, GitRevision, mode, data))192 }193 }()194 p := newParser(target, data, mode == Strict)195 prog, err := p.parseProg()196 if err := p.Err(); err != nil {197 return nil, err198 }199 if err != nil {200 return nil, err201 }202 // This validation is done even in non-debug mode because deserialization203 // procedure does not catch all bugs (e.g. mismatched types).204 // And we can receive bad programs from corpus and hub.205 if err := prog.validate(); err != nil {206 return nil, err207 }208 if p.autos != nil {209 p.fixupAutos(prog)210 }211 if err := prog.sanitize(mode == NonStrict); err != nil {212 return nil, err213 }214 return prog, nil215}216func (p *parser) parseProg() (*Prog, error) {217 prog := &Prog{218 Target: p.target,219 }220 for p.Scan() {221 if p.EOF() {222 if p.comment != "" {223 prog.Comments = append(prog.Comments, p.comment)224 p.comment = ""225 }226 continue227 }228 if p.Char() == '#' {229 if p.comment != "" {230 prog.Comments = append(prog.Comments, p.comment)231 }232 p.comment = strings.TrimSpace(p.s[p.i+1:])233 continue234 }235 name := p.Ident()236 r := ""237 if p.Char() == '=' {238 r = name239 p.Parse('=')240 name = p.Ident()241 }242 meta := p.target.SyscallMap[name]243 if meta == nil {244 return nil, fmt.Errorf("unknown syscall %v", name)245 }246 c := &Call{247 Meta: meta,248 Ret: MakeReturnArg(meta.Ret),249 Comment: p.comment,250 }251 prog.Calls = append(prog.Calls, c)252 p.Parse('(')253 for i := 0; p.Char() != ')'; i++ {254 if i >= len(meta.Args) {255 p.eatExcessive(false, "excessive syscall arguments")256 break257 }258 field := meta.Args[i]259 if IsPad(field.Type) {260 return nil, fmt.Errorf("padding in syscall %v arguments", name)261 }262 arg, err := p.parseArg(field.Type, DirIn)263 if err != nil {264 return nil, err265 }266 c.Args = append(c.Args, arg)267 if p.Char() != ')' {268 p.Parse(',')269 }270 }271 p.Parse(')')272 p.SkipWs()273 if !p.EOF() {274 if p.Char() != '#' {275 return nil, fmt.Errorf("tailing data (line #%v)", p.l)276 }277 if c.Comment != "" {278 prog.Comments = append(prog.Comments, c.Comment)279 }280 c.Comment = strings.TrimSpace(p.s[p.i+1:])281 }282 for i := len(c.Args); i < len(meta.Args); i++ {283 p.strictFailf("missing syscall args")284 c.Args = append(c.Args, meta.Args[i].DefaultArg(DirIn))285 }286 if len(c.Args) != len(meta.Args) {287 return nil, fmt.Errorf("wrong call arg count: %v, want %v", len(c.Args), len(meta.Args))288 }289 if r != "" && c.Ret != nil {290 p.vars[r] = c.Ret291 }292 p.comment = ""293 }294 if p.comment != "" {295 prog.Comments = append(prog.Comments, p.comment)296 }297 return prog, nil298}299func (p *parser) parseArg(typ Type, dir Dir) (Arg, error) {300 r := ""301 if p.Char() == '<' {302 p.Parse('<')303 r = p.Ident()304 p.Parse('=')305 p.Parse('>')306 }307 arg, err := p.parseArgImpl(typ, dir)308 if err != nil {309 return nil, err310 }311 if arg == nil {312 if typ != nil {313 arg = typ.DefaultArg(dir)314 } else if r != "" {315 return nil, fmt.Errorf("named nil argument")316 }317 }318 if r != "" {319 if res, ok := arg.(*ResultArg); ok {320 p.vars[r] = res321 }322 }323 return arg, nil324}325func (p *parser) parseArgImpl(typ Type, dir Dir) (Arg, error) {326 if typ == nil && p.Char() != 'n' {327 p.eatExcessive(true, "non-nil argument for nil type")328 return nil, nil329 }330 switch p.Char() {331 case '0':332 return p.parseArgInt(typ, dir)333 case 'r':334 return p.parseArgRes(typ, dir)335 case '&':336 return p.parseArgAddr(typ, dir)337 case '"', '\'':338 return p.parseArgString(typ, dir)339 case '{':340 return p.parseArgStruct(typ, dir)341 case '[':342 return p.parseArgArray(typ, dir)343 case '@':344 return p.parseArgUnion(typ, dir)345 case 'n':346 p.Parse('n')347 p.Parse('i')348 p.Parse('l')349 return nil, nil350 case 'A':351 p.Parse('A')352 p.Parse('U')353 p.Parse('T')354 p.Parse('O')355 return p.parseAuto(typ, dir)356 default:357 return nil, fmt.Errorf("failed to parse argument at '%c' (line #%v/%v: %v)",358 p.Char(), p.l, p.i, p.s)359 }360}361func (p *parser) parseArgInt(typ Type, dir Dir) (Arg, error) {362 val := p.Ident()363 v, err := strconv.ParseUint(val, 0, 64)364 if err != nil {365 return nil, fmt.Errorf("wrong arg value '%v': %v", val, err)366 }367 switch typ.(type) {368 case *ConstType, *IntType, *FlagsType, *ProcType, *CsumType:369 arg := Arg(MakeConstArg(typ, dir, v))370 if dir == DirOut && !typ.isDefaultArg(arg) {371 p.strictFailf("out arg %v has non-default value: %v", typ, v)372 arg = typ.DefaultArg(dir)373 }374 return arg, nil375 case *LenType:376 return MakeConstArg(typ, dir, v), nil377 case *ResourceType:378 return MakeResultArg(typ, dir, nil, v), nil379 case *PtrType, *VmaType:380 index := -v % uint64(len(p.target.SpecialPointers))381 return MakeSpecialPointerArg(typ, dir, index), nil382 default:383 p.eatExcessive(true, "wrong int arg %T", typ)384 return typ.DefaultArg(dir), nil385 }386}387func (p *parser) parseAuto(typ Type, dir Dir) (Arg, error) {388 switch typ.(type) {389 case *ConstType, *LenType, *CsumType:390 return p.auto(MakeConstArg(typ, dir, 0)), nil391 default:392 return nil, fmt.Errorf("wrong type %T for AUTO", typ)393 }394}395func (p *parser) parseArgRes(typ Type, dir Dir) (Arg, error) {396 id := p.Ident()397 var div, add uint64398 if p.Char() == '/' {399 p.Parse('/')400 op := p.Ident()401 v, err := strconv.ParseUint(op, 0, 64)402 if err != nil {403 return nil, fmt.Errorf("wrong result div op: '%v'", op)404 }405 div = v406 }407 if p.Char() == '+' {408 p.Parse('+')409 op := p.Ident()410 v, err := strconv.ParseUint(op, 0, 64)411 if err != nil {412 return nil, fmt.Errorf("wrong result add op: '%v'", op)413 }414 add = v415 }416 v := p.vars[id]417 if v == nil {418 p.strictFailf("undeclared variable %v", id)419 return typ.DefaultArg(dir), nil420 }421 arg := MakeResultArg(typ, dir, v, 0)422 arg.OpDiv = div423 arg.OpAdd = add424 return arg, nil425}426func (p *parser) parseArgAddr(typ Type, dir Dir) (Arg, error) {427 var elem Type428 elemDir := DirInOut429 switch t1 := typ.(type) {430 case *PtrType:431 elem, elemDir = t1.Elem, t1.ElemDir432 case *VmaType:433 default:434 p.eatExcessive(true, "wrong addr arg")435 return typ.DefaultArg(dir), nil436 }437 p.Parse('&')438 auto := false439 var addr, vmaSize uint64440 if p.Char() == 'A' {441 p.Parse('A')442 p.Parse('U')443 p.Parse('T')444 p.Parse('O')445 if elem == nil {446 return nil, fmt.Errorf("vma type can't be AUTO")447 }448 auto = true449 } else {450 var err error451 addr, vmaSize, err = p.parseAddr()452 if err != nil {453 return nil, err454 }455 }456 var inner Arg457 if p.Char() == '=' {458 p.Parse('=')459 if p.Char() == 'A' {460 p.Parse('A')461 p.Parse('N')462 p.Parse('Y')463 p.Parse('=')464 anyPtr := p.target.getAnyPtrType(typ.Size())465 typ, elem, elemDir = anyPtr, anyPtr.Elem, anyPtr.ElemDir466 }467 var err error468 inner, err = p.parseArg(elem, elemDir)469 if err != nil {470 return nil, err471 }472 }473 if elem == nil {474 if addr%p.target.PageSize != 0 {475 p.strictFailf("unaligned vma address 0x%x", addr)476 addr &= ^(p.target.PageSize - 1)477 }478 return MakeVmaPointerArg(typ, dir, addr, vmaSize), nil479 }480 if inner == nil {481 inner = elem.DefaultArg(elemDir)482 }483 arg := MakePointerArg(typ, dir, addr, inner)484 if auto {485 p.auto(arg)486 }487 return arg, nil488}489func (p *parser) parseArgString(t Type, dir Dir) (Arg, error) {490 typ, ok := t.(*BufferType)491 if !ok {492 p.eatExcessive(true, "wrong string arg")493 return t.DefaultArg(dir), nil494 }495 data, err := p.deserializeData()496 if err != nil {497 return nil, err498 }499 size := ^uint64(0)500 if p.Char() == '/' {501 p.Parse('/')502 sizeStr := p.Ident()503 size, err = strconv.ParseUint(sizeStr, 0, 64)504 if err != nil {505 return nil, fmt.Errorf("failed to parse buffer size: %q", sizeStr)506 }507 maxMem := p.target.NumPages * p.target.PageSize508 if size > maxMem {509 p.strictFailf("too large string argument %v", size)510 size = maxMem511 }512 }513 if !typ.Varlen() {514 size = typ.Size()515 } else if size == ^uint64(0) {516 size = uint64(len(data))517 }518 if dir == DirOut {519 return MakeOutDataArg(typ, dir, size), nil520 }521 if diff := int(size) - len(data); diff > 0 {522 data = append(data, make([]byte, diff)...)523 }524 data = data[:size]525 if typ.Kind == BufferString && len(typ.Values) != 0 &&526 // AUTOGENERATED will be padded by 0's.527 !strings.HasPrefix(typ.Values[0], "AUTOGENERATED") {528 matched := false529 for _, val := range typ.Values {530 if string(data) == val {531 matched = true532 break533 }534 }535 if !matched {536 p.strictFailf("bad string value %q, expect %q", data, typ.Values)537 data = []byte(typ.Values[0])538 }539 }540 return MakeDataArg(typ, dir, data), nil541}542func (p *parser) parseArgStruct(typ Type, dir Dir) (Arg, error) {543 p.Parse('{')544 t1, ok := typ.(*StructType)545 if !ok {546 p.eatExcessive(false, "wrong struct arg")547 p.Parse('}')548 return typ.DefaultArg(dir), nil549 }550 var inner []Arg551 for i := 0; p.Char() != '}'; i++ {552 if i >= len(t1.Fields) {553 p.eatExcessive(false, "excessive struct %v fields", typ.Name())554 break555 }556 field := t1.Fields[i]557 if IsPad(field.Type) {558 inner = append(inner, MakeConstArg(field.Type, dir, 0))559 } else {560 arg, err := p.parseArg(field.Type, dir)561 if err != nil {562 return nil, err563 }564 inner = append(inner, arg)565 if p.Char() != '}' {566 p.Parse(',')567 }568 }569 }570 p.Parse('}')571 for len(inner) < len(t1.Fields) {572 field := t1.Fields[len(inner)]573 if !IsPad(field.Type) {574 p.strictFailf("missing struct %v fields %v/%v", typ.Name(), len(inner), len(t1.Fields))575 }576 inner = append(inner, field.Type.DefaultArg(dir))577 }578 return MakeGroupArg(typ, dir, inner), nil579}580func (p *parser) parseArgArray(typ Type, dir Dir) (Arg, error) {581 p.Parse('[')582 t1, ok := typ.(*ArrayType)583 if !ok {584 p.eatExcessive(false, "wrong array arg %T", typ)585 p.Parse(']')586 return typ.DefaultArg(dir), nil587 }588 var inner []Arg589 for i := 0; p.Char() != ']'; i++ {590 arg, err := p.parseArg(t1.Elem, dir)591 if err != nil {592 return nil, err593 }594 inner = append(inner, arg)595 if p.Char() != ']' {596 p.Parse(',')597 }598 }599 p.Parse(']')600 if t1.Kind == ArrayRangeLen && t1.RangeBegin == t1.RangeEnd {601 for uint64(len(inner)) < t1.RangeBegin {602 p.strictFailf("missing array elements")603 inner = append(inner, t1.Elem.DefaultArg(dir))604 }605 inner = inner[:t1.RangeBegin]606 }607 return MakeGroupArg(typ, dir, inner), nil608}609func (p *parser) parseArgUnion(typ Type, dir Dir) (Arg, error) {610 t1, ok := typ.(*UnionType)611 if !ok {612 p.eatExcessive(true, "wrong union arg")613 return typ.DefaultArg(dir), nil614 }615 p.Parse('@')616 name := p.Ident()617 var optType Type618 index := -1619 for i, field := range t1.Fields {620 if name == field.Name {621 optType, index = field.Type, i622 break623 }624 }625 if optType == nil {626 p.eatExcessive(true, "wrong union option")627 return typ.DefaultArg(dir), nil628 }629 var opt Arg630 if p.Char() == '=' {631 p.Parse('=')632 var err error633 opt, err = p.parseArg(optType, dir)634 if err != nil {635 return nil, err636 }637 } else {638 opt = optType.DefaultArg(dir)639 }640 return MakeUnionArg(typ, dir, opt, index), nil641}642// Eats excessive call arguments and struct fields to recover after description changes.643func (p *parser) eatExcessive(stopAtComma bool, what string, args ...interface{}) {644 p.strictFailf(what, args...)645 paren, brack, brace := 0, 0, 0646 for !p.EOF() && p.e == nil {647 ch := p.Char()648 switch ch {649 case '(':650 paren++651 case ')':652 if paren == 0 {653 return654 }655 paren--656 case '[':657 brack++658 case ']':659 if brack == 0 {660 return661 }662 brack--663 case '{':664 brace++665 case '}':666 if brace == 0 {667 return668 }669 brace--670 case ',':671 if stopAtComma && paren == 0 && brack == 0 && brace == 0 {672 return673 }674 case '\'', '"':675 p.Parse(ch)676 for !p.EOF() && p.Char() != ch {677 p.Parse(p.Char())678 }679 if p.EOF() {680 return681 }682 }683 p.Parse(ch)684 }685}686const (687 encodingAddrBase = 0x7f0000000000688 maxLineLen = 1 << 20689)690func (target *Target) serializeAddr(arg *PointerArg) string {691 ssize := ""692 if arg.VmaSize != 0 {693 ssize = fmt.Sprintf("/0x%x", arg.VmaSize)694 }695 return fmt.Sprintf("(0x%x%v)", encodingAddrBase+arg.Address, ssize)696}697func (p *parser) parseAddr() (uint64, uint64, error) {698 p.Parse('(')699 pstr := p.Ident()700 addr, err := strconv.ParseUint(pstr, 0, 64)701 if err != nil {702 return 0, 0, fmt.Errorf("failed to parse addr: %q", pstr)703 }704 if addr < encodingAddrBase {705 return 0, 0, fmt.Errorf("address without base offset: %q", pstr)706 }707 addr -= encodingAddrBase708 // This is not used anymore, but left here to parse old programs.709 if p.Char() == '+' || p.Char() == '-' {710 minus := false711 if p.Char() == '-' {712 minus = true713 p.Parse('-')714 } else {715 p.Parse('+')716 }717 ostr := p.Ident()718 off, err := strconv.ParseUint(ostr, 0, 64)719 if err != nil {720 return 0, 0, fmt.Errorf("failed to parse addr offset: %q", ostr)721 }722 if minus {723 off = -off724 }725 addr += off726 }727 target := p.target728 maxMem := target.NumPages * target.PageSize729 var vmaSize uint64730 if p.Char() == '/' {731 p.Parse('/')732 pstr := p.Ident()733 size, err := strconv.ParseUint(pstr, 0, 64)734 if err != nil {735 return 0, 0, fmt.Errorf("failed to parse addr size: %q", pstr)736 }737 addr = addr & ^(target.PageSize - 1)738 vmaSize = (size + target.PageSize - 1) & ^(target.PageSize - 1)739 if vmaSize == 0 {740 vmaSize = target.PageSize741 }742 if vmaSize > maxMem {743 vmaSize = maxMem744 }745 if addr > maxMem-vmaSize {746 addr = maxMem - vmaSize747 }748 }749 p.Parse(')')750 return addr, vmaSize, nil751}752func serializeData(buf *bytes.Buffer, data []byte, readable bool) {753 if !readable && !isReadableData(data) {754 fmt.Fprintf(buf, "\"%v\"", hex.EncodeToString(data))755 return756 }757 buf.WriteByte('\'')758 encodeData(buf, data, true, false)759 buf.WriteByte('\'')760}761func EncodeData(buf *bytes.Buffer, data []byte, readable bool) {762 if !readable && isReadableData(data) {763 readable = true764 }765 encodeData(buf, data, readable, true)766}767func encodeData(buf *bytes.Buffer, data []byte, readable, cstr bool) {768 for _, v := range data {769 if !readable {770 lo, hi := byteToHex(v)771 buf.Write([]byte{'\\', 'x', hi, lo})772 continue773 }774 switch v {775 case '\a':776 buf.Write([]byte{'\\', 'a'})777 case '\b':778 buf.Write([]byte{'\\', 'b'})779 case '\f':780 buf.Write([]byte{'\\', 'f'})781 case '\n':782 buf.Write([]byte{'\\', 'n'})783 case '\r':784 buf.Write([]byte{'\\', 'r'})785 case '\t':786 buf.Write([]byte{'\\', 't'})787 case '\v':788 buf.Write([]byte{'\\', 'v'})789 case '\'':790 buf.Write([]byte{'\\', '\''})791 case '"':792 buf.Write([]byte{'\\', '"'})793 case '\\':794 buf.Write([]byte{'\\', '\\'})795 default:796 if isPrintable(v) {797 buf.WriteByte(v)798 } else {799 if cstr {800 // We would like to use hex encoding with \x,801 // but C's \x is hard to use: it can contain _any_ number of hex digits802 // (not just 2 or 4), so later non-hex encoded chars will glue to \x.803 c0 := (v>>6)&0x7 + '0'804 c1 := (v>>3)&0x7 + '0'805 c2 := (v>>0)&0x7 + '0'806 buf.Write([]byte{'\\', c0, c1, c2})807 } else {808 lo, hi := byteToHex(v)809 buf.Write([]byte{'\\', 'x', hi, lo})810 }811 }812 }813 }814}815func isReadableDataType(typ *BufferType) bool {816 return typ.Kind == BufferString || typ.Kind == BufferFilename817}818func isReadableData(data []byte) bool {819 if len(data) == 0 {820 return false821 }822 for _, v := range data {823 if isPrintable(v) {824 continue825 }826 switch v {827 case 0, '\a', '\b', '\f', '\n', '\r', '\t', '\v':828 continue829 }830 return false831 }832 return true...
isReadableData
Using AI Code Generation
1import (2func main() {3 reader := bufio.NewReader(os.Stdin)4 fmt.Print("Enter a string: ")5 text, _ := reader.ReadString('\n')6 fmt.Println(text)7}
isReadableData
Using AI Code Generation
1import (2func main() {3 fmt.Println(stringutil.Reverse("!oG ,olleH"))4 fmt.Println(stringutil.MyName)5 fmt.Println(stringutil.IsReadableData("abc"))6}
isReadableData
Using AI Code Generation
1import (2func main() {3 fmt.Println("Enter the file name:")4 fmt.Scan(&name)5 _, err := os.Stat(name)6 if err != nil {7 fmt.Println(err)8 }9 if os.IsNotExist(err) {10 fmt.Println("File does not exist")11 } else {12 fmt.Println("File exists")13 }14}
isReadableData
Using AI Code Generation
1import (2func main() {3 fmt.Println("Enter data to check if it is readable")4 fmt.Scanln(&data)5 if prog.IsReadableData(data) {6 fmt.Println("Data is readable")7 } else {8 fmt.Println("Data is not readable")9 }10}11import (12func main() {13 fmt.Println("Enter data to check if it is readable")14 fmt.Scanln(&data)15 if prog.IsReadableData(data) {16 fmt.Println("Data is readable")17 } else {18 fmt.Println("Data is not readable")19 }20}21import "strings"22func IsReadableData(data string) bool {23 return strings.ContainsAny(data, "aeiouAEIOU")24}25import "strings"26func IsReadableData(data string) bool {27 return strings.ContainsAny(data, "aeiouAEIOU")28}29import "strings"30func IsReadableData(data string) bool {31 return strings.ContainsAny(data, "aeiouAEIOU")32}33import "strings"34func IsReadableData(data string) bool {35 return strings.ContainsAny(data, "aeiouAEIOU")36}37import "strings"38func IsReadableData(data string) bool {39 return strings.ContainsAny(data, "aeiouAEIOU")40}41import "strings"42func IsReadableData(data string) bool {43 return strings.ContainsAny(data, "aeiouAEIOU")44}45import "strings"
isReadableData
Using AI Code Generation
1import (2func main() {3 fmt.Println(prog.IsReadableData("this is a string"))4 fmt.Println(prog.IsReadableData("this is a string 123"))5 fmt.Println(prog.IsReadableData("this is a string 123 !@#$%^&*()"))6 fmt.Println(prog.IsReadableData("this is a string 123 !@#$%^&*() \n"))7}
isReadableData
Using AI Code Generation
1import (2func main() {3 fmt.Println("Enter the path of the file")4 fmt.Scanln(&path)5 fmt.Println("Is the file readable: ", prog.IsReadableData(path))6}
isReadableData
Using AI Code Generation
1import (2func main() {3 p.IsReadableData()4 fmt.Println("Path: 2.go")5}6import "fmt"7type Program struct {8}9func (p Program) IsReadableData() {10 fmt.Println("Path: 1.go")11 fmt.Println("code to use isReadableData method of prog class")12}
isReadableData
Using AI Code Generation
1import (2func main() {3 p := prog.Prog{Data: "Hello World"}4 fmt.Println(p.IsReadableData())5}6import (7type Prog struct {8}9func (p Prog) IsReadableData() bool {10 if p.Data == "" {11 fmt.Println("Data is empty")12 }13 if strings.Contains(p.Data, "Hello") {14 fmt.Println("Data is readable")15 }16 fmt.Println("Data is not readable")17}
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!!