diff options
Diffstat (limited to 'src/pkg/testing')
-rw-r--r-- | src/pkg/testing/iotest/logger.go | 12 | ||||
-rw-r--r-- | src/pkg/testing/iotest/reader.go | 6 | ||||
-rw-r--r-- | src/pkg/testing/iotest/writer.go | 8 | ||||
-rw-r--r-- | src/pkg/testing/quick/quick.go | 74 | ||||
-rw-r--r-- | src/pkg/testing/quick/quick_test.go | 22 | ||||
-rw-r--r-- | src/pkg/testing/regexp.go | 98 | ||||
-rw-r--r-- | src/pkg/testing/regexp_test.go | 46 | ||||
-rw-r--r-- | src/pkg/testing/script/script.go | 32 | ||||
-rw-r--r-- | src/pkg/testing/script/script_test.go | 14 | ||||
-rw-r--r-- | src/pkg/testing/testing.go | 10 |
10 files changed, 161 insertions, 161 deletions
diff --git a/src/pkg/testing/iotest/logger.go b/src/pkg/testing/iotest/logger.go index 4eee6670b..0b01fcbbe 100644 --- a/src/pkg/testing/iotest/logger.go +++ b/src/pkg/testing/iotest/logger.go @@ -18,9 +18,9 @@ type writeLogger struct { func (l *writeLogger) Write(p []byte) (n int, err os.Error) { n, err = l.w.Write(p); if err != nil { - log.Stdoutf("%s %x: %v", l.prefix, p[0:n], err); + log.Stdoutf("%s %x: %v", l.prefix, p[0:n], err) } else { - log.Stdoutf("%s %x", l.prefix, p[0:n]); + log.Stdoutf("%s %x", l.prefix, p[0:n]) } return; } @@ -29,7 +29,7 @@ func (l *writeLogger) Write(p []byte) (n int, err os.Error) { // that it logs (using log.Stdout) each write to standard output, // printing the prefix and the hexadecimal data written. func NewWriteLogger(prefix string, w io.Writer) io.Writer { - return &writeLogger{prefix, w}; + return &writeLogger{prefix, w} } type readLogger struct { @@ -40,9 +40,9 @@ type readLogger struct { func (l *readLogger) Read(p []byte) (n int, err os.Error) { n, err = l.r.Read(p); if err != nil { - log.Stdoutf("%s %x: %v", l.prefix, p[0:n], err); + log.Stdoutf("%s %x: %v", l.prefix, p[0:n], err) } else { - log.Stdoutf("%s %x", l.prefix, p[0:n]); + log.Stdoutf("%s %x", l.prefix, p[0:n]) } return; } @@ -51,5 +51,5 @@ func (l *readLogger) Read(p []byte) (n int, err os.Error) { // that it logs (using log.Stdout) each write to standard output, // printing the prefix and the hexadecimal data written. func NewReadLogger(prefix string, r io.Reader) io.Reader { - return &readLogger{prefix, r}; + return &readLogger{prefix, r} } diff --git a/src/pkg/testing/iotest/reader.go b/src/pkg/testing/iotest/reader.go index ae427e6fa..61da735de 100644 --- a/src/pkg/testing/iotest/reader.go +++ b/src/pkg/testing/iotest/reader.go @@ -22,7 +22,7 @@ type oneByteReader struct { func (r *oneByteReader) Read(p []byte) (int, os.Error) { if len(p) == 0 { - return 0, nil; + return 0, nil } return r.r.Read(p[0:1]); } @@ -36,7 +36,7 @@ type halfReader struct { } func (r *halfReader) Read(p []byte) (int, os.Error) { - return r.r.Read(p[0 : (len(p)+1)/2]); + return r.r.Read(p[0 : (len(p)+1)/2]) } @@ -61,7 +61,7 @@ func (r *dataErrReader) Read(p []byte) (n int, err os.Error) { err = err1; } if n > 0 { - break; + break } n = bytes.Copy(p, r.unread); r.unread = r.unread[n:len(r.unread)]; diff --git a/src/pkg/testing/iotest/writer.go b/src/pkg/testing/iotest/writer.go index 8b0e4ca8f..54468a6fe 100644 --- a/src/pkg/testing/iotest/writer.go +++ b/src/pkg/testing/iotest/writer.go @@ -12,7 +12,7 @@ import ( // TruncateWriter returns a Writer that writes to w // but stops silently after n bytes. func TruncateWriter(w io.Writer, n int64) io.Writer { - return &truncateWriter{w, n}; + return &truncateWriter{w, n} } type truncateWriter struct { @@ -22,17 +22,17 @@ type truncateWriter struct { func (t *truncateWriter) Write(p []byte) (n int, err os.Error) { if t.n <= 0 { - return len(p), nil; + return len(p), nil } // real write n = len(p); if int64(n) > t.n { - n = int(t.n); + n = int(t.n) } n, err = t.w.Write(p[0:n]); t.n -= int64(n); if err == nil { - n = len(p); + n = len(p) } return; } diff --git a/src/pkg/testing/quick/quick.go b/src/pkg/testing/quick/quick.go index 3d47240bd..825fc12e2 100644 --- a/src/pkg/testing/quick/quick.go +++ b/src/pkg/testing/quick/quick.go @@ -28,7 +28,7 @@ type Generator interface { func randFloat32(rand *rand.Rand) float32 { f := rand.Float64() * math.MaxFloat32; if rand.Int() & 1 == 1 { - f = -f; + f = -f } return float32(f); } @@ -37,7 +37,7 @@ func randFloat32(rand *rand.Rand) float32 { func randFloat64(rand *rand.Rand) float64 { f := rand.Float64(); if rand.Int() & 1 == 1 { - f = -f; + f = -f } return f; } @@ -54,32 +54,32 @@ const complexSize = 50 // Note: in order to create arbitrary values for structs, all the members must be public. func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) { if m, ok := reflect.MakeZero(t).Interface().(Generator); ok { - return m.Generate(rand, complexSize), true; + return m.Generate(rand, complexSize), true } switch concrete := t.(type) { case *reflect.BoolType: - return reflect.NewValue(rand.Int() & 1 == 0), true; + return reflect.NewValue(rand.Int() & 1 == 0), true case *reflect.Float32Type: - return reflect.NewValue(randFloat32(rand)), true; + return reflect.NewValue(randFloat32(rand)), true case *reflect.Float64Type: - return reflect.NewValue(randFloat64(rand)), true; + return reflect.NewValue(randFloat64(rand)), true case *reflect.FloatType: if t.Size() == 4 { - return reflect.NewValue(float(randFloat32(rand))), true; + return reflect.NewValue(float(randFloat32(rand))), true } else { - return reflect.NewValue(float(randFloat64(rand))), true; + return reflect.NewValue(float(randFloat64(rand))), true } case *reflect.Int16Type: - return reflect.NewValue(int16(randInt64(rand))), true; + return reflect.NewValue(int16(randInt64(rand))), true case *reflect.Int32Type: - return reflect.NewValue(int32(randInt64(rand))), true; + return reflect.NewValue(int32(randInt64(rand))), true case *reflect.Int64Type: - return reflect.NewValue(randInt64(rand)), true; + return reflect.NewValue(randInt64(rand)), true case *reflect.Int8Type: - return reflect.NewValue(int8(randInt64(rand))), true; + return reflect.NewValue(int8(randInt64(rand))), true case *reflect.IntType: - return reflect.NewValue(int(randInt64(rand))), true; + return reflect.NewValue(int(randInt64(rand))), true case *reflect.MapType: numElems := rand.Intn(complexSize); m := reflect.MakeMap(concrete); @@ -87,7 +87,7 @@ func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) { key, ok1 := Value(concrete.Key(), rand); value, ok2 := Value(concrete.Elem(), rand); if !ok1 || !ok2 { - return nil, false; + return nil, false } m.SetElem(key, value); } @@ -95,7 +95,7 @@ func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) { case *reflect.PtrType: v, ok := Value(concrete.Elem(), rand); if !ok { - return nil, false; + return nil, false } p := reflect.MakeZero(concrete); p.(*reflect.PtrValue).PointTo(v); @@ -106,7 +106,7 @@ func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) { for i := 0; i < numElems; i++ { v, ok := Value(concrete.Elem(), rand); if !ok { - return nil, false; + return nil, false } s.Elem(i).SetValue(v); } @@ -115,7 +115,7 @@ func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) { numChars := rand.Intn(complexSize); codePoints := make([]int, numChars); for i := 0; i < numChars; i++ { - codePoints[i] = rand.Intn(0x10ffff); + codePoints[i] = rand.Intn(0x10ffff) } return reflect.NewValue(string(codePoints)), true; case *reflect.StructType: @@ -123,25 +123,25 @@ func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) { for i := 0; i < s.NumField(); i++ { v, ok := Value(concrete.Field(i).Type, rand); if !ok { - return nil, false; + return nil, false } s.Field(i).SetValue(v); } return s, true; case *reflect.Uint16Type: - return reflect.NewValue(uint16(randInt64(rand))), true; + return reflect.NewValue(uint16(randInt64(rand))), true case *reflect.Uint32Type: - return reflect.NewValue(uint32(randInt64(rand))), true; + return reflect.NewValue(uint32(randInt64(rand))), true case *reflect.Uint64Type: - return reflect.NewValue(uint64(randInt64(rand))), true; + return reflect.NewValue(uint64(randInt64(rand))), true case *reflect.Uint8Type: - return reflect.NewValue(uint8(randInt64(rand))), true; + return reflect.NewValue(uint8(randInt64(rand))), true case *reflect.UintType: - return reflect.NewValue(uint(randInt64(rand))), true; + return reflect.NewValue(uint(randInt64(rand))), true case *reflect.UintptrType: - return reflect.NewValue(uintptr(randInt64(rand))), true; + return reflect.NewValue(uintptr(randInt64(rand))), true default: - return nil, false; + return nil, false } return; @@ -169,7 +169,7 @@ var defaultConfig Config // getRand returns the *rand.Rand to use for a given Config. func (c *Config) getRand() *rand.Rand { if c.Rand == nil { - return rand.New(rand.NewSource(0)); + return rand.New(rand.NewSource(0)) } return c.Rand; } @@ -180,9 +180,9 @@ func (c *Config) getMaxCount() (maxCount int) { maxCount = c.MaxCount; if maxCount == 0 { if c.MaxCountScale != 0 { - maxCount = int(c.MaxCountScale * float(*defaultMaxCount)); + maxCount = int(c.MaxCountScale * float(*defaultMaxCount)) } else { - maxCount = *defaultMaxCount; + maxCount = *defaultMaxCount } } @@ -202,7 +202,7 @@ type CheckError struct { } func (s *CheckError) String() string { - return fmt.Sprintf("#%d: failed on input %s", s.Count, toString(s.In)); + return fmt.Sprintf("#%d: failed on input %s", s.Count, toString(s.In)) } // A CheckEqualError is the result CheckEqual finding an error. @@ -213,7 +213,7 @@ type CheckEqualError struct { } func (s *CheckEqualError) String() string { - return fmt.Sprintf("#%d: failed on input %s. Output 1: %s. Output 2: %s", s.Count, toString(s.In), toString(s.Out1), toString(s.Out2)); + return fmt.Sprintf("#%d: failed on input %s. Output 1: %s. Output 2: %s", s.Count, toString(s.In), toString(s.Out1), toString(s.Out2)) } // Check looks for an input to f, any function that returns bool, @@ -233,7 +233,7 @@ func (s *CheckEqualError) String() string { // } func Check(function interface{}, config *Config) (err os.Error) { if config == nil { - config = &defaultConfig; + config = &defaultConfig } f, fType, ok := functionAndType(function); @@ -258,7 +258,7 @@ func Check(function interface{}, config *Config) (err os.Error) { for i := 0; i < maxCount; i++ { err = arbitraryValues(arguments, fType, config, rand); if err != nil { - return; + return } if !f.Call(arguments)[0].(*reflect.BoolValue).Get() { @@ -276,7 +276,7 @@ func Check(function interface{}, config *Config) (err os.Error) { // describing the input and the outputs. func CheckEqual(f, g interface{}, config *Config) (err os.Error) { if config == nil { - config = &defaultConfig; + config = &defaultConfig } x, xType, ok := functionAndType(f); @@ -302,7 +302,7 @@ func CheckEqual(f, g interface{}, config *Config) (err os.Error) { for i := 0; i < maxCount; i++ { err = arbitraryValues(arguments, xType, config, rand); if err != nil { - return; + return } xOut := toInterfaces(x.Call(arguments)); @@ -340,7 +340,7 @@ func arbitraryValues(args []reflect.Value, f *reflect.FuncType, config *Config, func functionAndType(f interface{}) (v *reflect.FuncValue, t *reflect.FuncType, ok bool) { v, ok = reflect.NewValue(f).(*reflect.FuncValue); if !ok { - return; + return } t = v.Type().(*reflect.FuncType); return; @@ -349,7 +349,7 @@ func functionAndType(f interface{}) (v *reflect.FuncValue, t *reflect.FuncType, func toInterfaces(values []reflect.Value) []interface{} { ret := make([]interface{}, len(values)); for i, v := range values { - ret[i] = v.Interface(); + ret[i] = v.Interface() } return ret; } @@ -357,7 +357,7 @@ func toInterfaces(values []reflect.Value) []interface{} { func toString(interfaces []interface{}) string { s := make([]string, len(interfaces)); for i, v := range interfaces { - s[i] = fmt.Sprintf("%#v", v); + s[i] = fmt.Sprintf("%#v", v) } return strings.Join(s, ", "); } diff --git a/src/pkg/testing/quick/quick_test.go b/src/pkg/testing/quick/quick_test.go index 951582e35..b4037ab55 100644 --- a/src/pkg/testing/quick/quick_test.go +++ b/src/pkg/testing/quick/quick_test.go @@ -63,7 +63,7 @@ func fIntptr(a *int) *int { func reportError(property string, err os.Error, t *testing.T) { if err != nil { - t.Errorf("%s: %s", property, err); + t.Errorf("%s: %s", property, err) } } @@ -99,46 +99,46 @@ type myStruct struct { } func (m myStruct) Generate(r *rand.Rand, _ int) reflect.Value { - return reflect.NewValue(myStruct{x: 42}); + return reflect.NewValue(myStruct{x: 42}) } func myStructProperty(in myStruct) bool { return in.x == 42 } func TestCheckProperty(t *testing.T) { - reportError("myStructProperty", Check(myStructProperty, nil), t); + reportError("myStructProperty", Check(myStructProperty, nil), t) } func TestFailure(t *testing.T) { f := func(x int) bool { return false }; err := Check(f, nil); if err == nil { - t.Errorf("Check didn't return an error"); + t.Errorf("Check didn't return an error") } if _, ok := err.(*CheckError); !ok { - t.Errorf("Error was not a CheckError: %s", err); + t.Errorf("Error was not a CheckError: %s", err) } err = CheckEqual(fUint, fUint32, nil); if err == nil { - t.Errorf("#1 CheckEqual didn't return an error"); + t.Errorf("#1 CheckEqual didn't return an error") } if _, ok := err.(SetupError); !ok { - t.Errorf("#1 Error was not a SetupError: %s", err); + t.Errorf("#1 Error was not a SetupError: %s", err) } err = CheckEqual(func(x, y int) {}, func(x int) {}, nil); if err == nil { - t.Errorf("#2 CheckEqual didn't return an error"); + t.Errorf("#2 CheckEqual didn't return an error") } if _, ok := err.(SetupError); !ok { - t.Errorf("#2 Error was not a SetupError: %s", err); + t.Errorf("#2 Error was not a SetupError: %s", err) } err = CheckEqual(func(x int) int { return 0 }, func(x int) int32 { return 0 }, nil); if err == nil { - t.Errorf("#3 CheckEqual didn't return an error"); + t.Errorf("#3 CheckEqual didn't return an error") } if _, ok := err.(SetupError); !ok { - t.Errorf("#3 Error was not a SetupError: %s", err); + t.Errorf("#3 Error was not a SetupError: %s", err) } } diff --git a/src/pkg/testing/regexp.go b/src/pkg/testing/regexp.go index f4cfe5e6e..5093d512e 100644 --- a/src/pkg/testing/regexp.go +++ b/src/pkg/testing/regexp.go @@ -152,15 +152,15 @@ func (cclass *_CharClass) kind() int { return _CHARCLASS } func (cclass *_CharClass) print() { print("charclass"); if cclass.negate { - print(" (negated)"); + print(" (negated)") } for i := 0; i < len(cclass.ranges); i += 2 { l := cclass.ranges[i]; r := cclass.ranges[i+1]; if l == r { - print(" [", string(l), "]"); + print(" [", string(l), "]") } else { - print(" [", string(l), "-", string(r), "]"); + print(" [", string(l), "-", string(r), "]") } } } @@ -171,7 +171,7 @@ func (cclass *_CharClass) addRange(a, b int) { if n >= cap(cclass.ranges) { nr := make([]int, n, 2*n); for i, j := range nr { - nr[i] = j; + nr[i] = j } cclass.ranges = nr; } @@ -187,7 +187,7 @@ func (cclass *_CharClass) matches(c int) bool { min := cclass.ranges[i]; max := cclass.ranges[i+1]; if min <= c && c <= max { - return !cclass.negate; + return !cclass.negate } } return cclass.negate; @@ -256,7 +256,7 @@ func (re *Regexp) add(i instr) instr { if n >= cap(re.inst) { ni := make([]instr, n, 2*n); for i, j := range re.inst { - ni[i] = j; + ni[i] = j } re.inst = ni; } @@ -279,7 +279,7 @@ func (p *parser) c() int { return p.ch } func (p *parser) nextc() int { if p.pos >= len(p.re.expr) { - p.ch = endOfFile; + p.ch = endOfFile } else { c, w := utf8.DecodeRuneInString(p.re.expr[p.pos : len(p.re.expr)]); p.ch = c; @@ -299,7 +299,7 @@ func special(c int) bool { s := `\.+*?()|[]^$`; for i := 0; i < len(s); i++ { if c == int(s[i]) { - return true; + return true } } return false; @@ -309,7 +309,7 @@ func specialcclass(c int) bool { s := `\-[]`; for i := 0; i < len(s); i++ { if c == int(s[i]) { - return true; + return true } } return false; @@ -348,7 +348,7 @@ func (p *parser) charClass() instr { p.error = ErrExtraneousBackslash; return nil; case c == 'n': - c = '\n'; + c = '\n' case specialcclass(c): // c is as delivered default: @@ -364,7 +364,7 @@ func (p *parser) charClass() instr { p.nextc(); left = c; } else { // single char - cc.addRange(c, c); + cc.addRange(c, c) } case left <= c: // second of pair cc.addRange(left, c); @@ -384,11 +384,11 @@ func (p *parser) term() (start, end instr) { // The other functions (closure(), concatenation() etc.) assume // it's safe to recur to here. if p.error != "" { - return; + return } switch c := p.c(); c { case '|', endOfFile: - return nil, nil; + return nil, nil case '*', '+': p.error = ErrBareClosure; return; @@ -417,7 +417,7 @@ func (p *parser) term() (start, end instr) { p.nextc(); start = p.charClass(); if p.error != "" { - return; + return } if p.c() != ']' { p.error = ErrUnmatchedLbkt; @@ -450,7 +450,7 @@ func (p *parser) term() (start, end instr) { } start = ebra; } else { - end.setNext(ebra); + end.setNext(ebra) } bra.setNext(start); return bra, ebra; @@ -461,7 +461,7 @@ func (p *parser) term() (start, end instr) { p.error = ErrExtraneousBackslash; return; case c == 'n': - c = '\n'; + c = '\n' case special(c): // c is as delivered default: @@ -481,7 +481,7 @@ func (p *parser) term() (start, end instr) { func (p *parser) closure() (start, end instr) { start, end = p.term(); if start == nil || p.error != "" { - return; + return } switch p.c() { case '*': @@ -511,11 +511,11 @@ func (p *parser) closure() (start, end instr) { start = alt; // start is now alt end = nop; // end is nop pointed to by both branches default: - return; + return } switch p.nextc() { case '*', '+', '?': - p.error = ErrBadClosure; + p.error = ErrBadClosure } return; } @@ -524,7 +524,7 @@ func (p *parser) concatenation() (start, end instr) { for { nstart, nend := p.closure(); if p.error != "" { - return; + return } switch { case nstart == nil: // end of this concatenation @@ -534,7 +534,7 @@ func (p *parser) concatenation() (start, end instr) { } return; case start == nil: // this is first element of concatenation - start, end = nstart, nend; + start, end = nstart, nend default: end.setNext(nstart); end = nend; @@ -546,17 +546,17 @@ func (p *parser) concatenation() (start, end instr) { func (p *parser) regexp() (start, end instr) { start, end = p.concatenation(); if p.error != "" { - return; + return } for { switch p.c() { default: - return; + return case '|': p.nextc(); nstart, nend := p.concatenation(); if p.error != "" { - return; + return } alt := new(_Alt); p.re.add(alt); @@ -574,7 +574,7 @@ func (p *parser) regexp() (start, end instr) { func unNop(i instr) instr { for i.kind() == _NOP { - i = i.next(); + i = i.next() } return i; } @@ -583,7 +583,7 @@ func (re *Regexp) eliminateNops() { for i := 0; i < len(re.inst); i++ { inst := re.inst[i]; if inst.kind() == _END { - continue; + continue } inst.setNext(unNop(inst.next())); if inst.kind() == _ALT { @@ -599,7 +599,7 @@ func (re *Regexp) doParse() string { re.add(start); s, e := p.regexp(); if p.error != "" { - return p.error; + return p.error } start.setNext(s); re.start = start; @@ -624,7 +624,7 @@ func CompileRegexp(str string) (regexp *Regexp, error string) { func MustCompile(str string) *Regexp { regexp, error := CompileRegexp(str); if error != "" { - panicln(`regexp: compiling "`, str, `": `, error); + panicln(`regexp: compiling "`, str, `": `, error) } return regexp; } @@ -645,13 +645,13 @@ func addState(s []state, inst instr, match []int) []state { for i := 0; i < l; i++ { if s[i].inst.index() == index && // same instruction s[i].match[0] < pos { // earlier match already going; lefmost wins - return s; + return s } } if l == cap(s) { s1 := make([]state, 2*l)[0:l]; for i := 0; i < l; i++ { - s1[i] = s[i]; + s1[i] = s[i] } s = s1; } @@ -672,14 +672,14 @@ func (re *Regexp) doExecute(str string, bytes []byte, pos int) []int { found := false; end := len(str); if bytes != nil { - end = len(bytes); + end = len(bytes) } for pos <= end { if !found { // prime the pump if we haven't seen a match yet match := make([]int, 2*(re.nbra + 1)); for i := 0; i < len(match); i++ { - match[i] = -1; // no match seen; catches cases like "a(b)?c" on "ac" + match[i] = -1 // no match seen; catches cases like "a(b)?c" on "ac" } match[0] = pos; s[out] = addState(s[out], re.start.next(), match); @@ -688,15 +688,15 @@ func (re *Regexp) doExecute(str string, bytes []byte, pos int) []int { s[out] = s[out][0:0]; // clear out state if len(s[in]) == 0 { // machine has completed - break; + break } charwidth := 1; c := endOfFile; if pos < end { if bytes == nil { - c, charwidth = utf8.DecodeRuneInString(str[pos:end]); + c, charwidth = utf8.DecodeRuneInString(str[pos:end]) } else { - c, charwidth = utf8.DecodeRune(bytes[pos:end]); + c, charwidth = utf8.DecodeRune(bytes[pos:end]) } } for i := 0; i < len(s[in]); i++ { @@ -704,27 +704,27 @@ func (re *Regexp) doExecute(str string, bytes []byte, pos int) []int { switch s[in][i].inst.kind() { case _BOT: if pos == 0 { - s[in] = addState(s[in], st.inst.next(), st.match); + s[in] = addState(s[in], st.inst.next(), st.match) } case _EOT: if pos == end { - s[in] = addState(s[in], st.inst.next(), st.match); + s[in] = addState(s[in], st.inst.next(), st.match) } case _CHAR: if c == st.inst.(*_Char).char { - s[out] = addState(s[out], st.inst.next(), st.match); + s[out] = addState(s[out], st.inst.next(), st.match) } case _CHARCLASS: if st.inst.(*_CharClass).matches(c) { - s[out] = addState(s[out], st.inst.next(), st.match); + s[out] = addState(s[out], st.inst.next(), st.match) } case _ANY: if c != endOfFile { - s[out] = addState(s[out], st.inst.next(), st.match); + s[out] = addState(s[out], st.inst.next(), st.match) } case _NOTNL: if c != endOfFile && c != '\n' { - s[out] = addState(s[out], st.inst.next(), st.match); + s[out] = addState(s[out], st.inst.next(), st.match) } case _BRA: n := st.inst.(*_Bra).n; @@ -739,7 +739,7 @@ func (re *Regexp) doExecute(str string, bytes []byte, pos int) []int { // give other branch a copy of this match vector s1 := make([]int, 2*(re.nbra + 1)); for i := 0; i < len(s1); i++ { - s1[i] = st.match[i]; + s1[i] = st.match[i] } s[in] = addState(s[in], st.inst.next(), s1); case _END: @@ -770,7 +770,7 @@ func (re *Regexp) doExecute(str string, bytes []byte, pos int) []int { // A negative value means the subexpression did not match any element of the string. // An empty array means "no match". func (re *Regexp) ExecuteString(s string) (a []int) { - return re.doExecute(s, nil, 0); + return re.doExecute(s, nil, 0) } @@ -802,12 +802,12 @@ func (re *Regexp) Match(b []byte) bool { return len(re.doExecute("", b, 0)) > 0 func (re *Regexp) MatchStrings(s string) (a []string) { r := re.doExecute(s, nil, 0); if r == nil { - return nil; + return nil } a = make([]string, len(r)/2); for i := 0; i < len(r); i += 2 { if r[i] != -1 { // -1 means no match for this subexpression - a[i/2] = s[r[i]:r[i+1]]; + a[i/2] = s[r[i]:r[i+1]] } } return; @@ -821,12 +821,12 @@ func (re *Regexp) MatchStrings(s string) (a []string) { func (re *Regexp) MatchSlices(b []byte) (a [][]byte) { r := re.doExecute("", b, 0); if r == nil { - return nil; + return nil } a = make([][]byte, len(r)/2); for i := 0; i < len(r); i += 2 { if r[i] != -1 { // -1 means no match for this subexpression - a[i/2] = b[r[i]:r[i+1]]; + a[i/2] = b[r[i]:r[i+1]] } } return; @@ -838,7 +838,7 @@ func (re *Regexp) MatchSlices(b []byte) (a [][]byte) { func MatchString(pattern string, s string) (matched bool, error string) { re, err := CompileRegexp(pattern); if err != "" { - return false, err; + return false, err } return re.MatchString(s), ""; } @@ -849,7 +849,7 @@ func MatchString(pattern string, s string) (matched bool, error string) { func Match(pattern string, b []byte) (matched bool, error string) { re, err := CompileRegexp(pattern); if err != "" { - return false, err; + return false, err } return re.Match(b), ""; } diff --git a/src/pkg/testing/regexp_test.go b/src/pkg/testing/regexp_test.go index d24e801b9..89a214fca 100644 --- a/src/pkg/testing/regexp_test.go +++ b/src/pkg/testing/regexp_test.go @@ -89,7 +89,7 @@ var matches = []tester{ func compileTest(t *T, expr string, error string) *Regexp { re, err := CompileRegexp(expr); if err != error { - t.Error("compiling `", expr, "`; unexpected error: ", err); + t.Error("compiling `", expr, "`; unexpected error: ", err) } return re; } @@ -97,10 +97,10 @@ func compileTest(t *T, expr string, error string) *Regexp { func printVec(t *T, m []int) { l := len(m); if l == 0 { - t.Log("\t<no match>"); + t.Log("\t<no match>") } else { for i := 0; i < l; i = i+2 { - t.Log("\t", m[i], ",", m[i+1]); + t.Log("\t", m[i], ",", m[i+1]) } } } @@ -108,10 +108,10 @@ func printVec(t *T, m []int) { func printStrings(t *T, m []string) { l := len(m); if l == 0 { - t.Log("\t<no match>"); + t.Log("\t<no match>") } else { for i := 0; i < l; i = i+2 { - t.Logf("\t%q", m[i]); + t.Logf("\t%q", m[i]) } } } @@ -119,10 +119,10 @@ func printStrings(t *T, m []string) { func printBytes(t *T, b [][]byte) { l := len(b); if l == 0 { - t.Log("\t<no match>"); + t.Log("\t<no match>") } else { for i := 0; i < l; i = i+2 { - t.Logf("\t%q", b[i]); + t.Logf("\t%q", b[i]) } } } @@ -130,11 +130,11 @@ func printBytes(t *T, b [][]byte) { func equal(m1, m2 []int) bool { l := len(m1); if l != len(m2) { - return false; + return false } for i := 0; i < l; i++ { if m1[i] != m2[i] { - return false; + return false } } return true; @@ -143,11 +143,11 @@ func equal(m1, m2 []int) bool { func equalStrings(m1, m2 []string) bool { l := len(m1); if l != len(m2) { - return false; + return false } for i := 0; i < l; i++ { if m1[i] != m2[i] { - return false; + return false } } return true; @@ -156,11 +156,11 @@ func equalStrings(m1, m2 []string) bool { func equalBytes(m1 [][]byte, m2 []string) bool { l := len(m1); if l != len(m2) { - return false; + return false } for i := 0; i < l; i++ { if string(m1[i]) != m2[i] { - return false; + return false } } return true; @@ -169,7 +169,7 @@ func equalBytes(m1 [][]byte, m2 []string) bool { func executeTest(t *T, expr string, str string, match []int) { re := compileTest(t, expr, ""); if re == nil { - return; + return } m := re.ExecuteString(str); if !equal(m, match) { @@ -190,13 +190,13 @@ func executeTest(t *T, expr string, str string, match []int) { func TestGoodCompile(t *T) { for i := 0; i < len(good_re); i++ { - compileTest(t, good_re[i], ""); + compileTest(t, good_re[i], "") } } func TestBadCompile(t *T) { for i := 0; i < len(bad_re); i++ { - compileTest(t, bad_re[i].re, bad_re[i].err); + compileTest(t, bad_re[i].re, bad_re[i].err) } } @@ -210,16 +210,16 @@ func TestExecute(t *T) { func matchTest(t *T, expr string, str string, match []int) { re := compileTest(t, expr, ""); if re == nil { - return; + return } m := re.MatchString(str); if m != (len(match) > 0) { - t.Error("MatchString failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0); + t.Error("MatchString failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0) } // now try bytes m = re.Match(strings.Bytes(str)); if m != (len(match) > 0) { - t.Error("Match failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0); + t.Error("Match failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0) } } @@ -233,11 +233,11 @@ func TestMatch(t *T) { func matchStringsTest(t *T, expr string, str string, match []int) { re := compileTest(t, expr, ""); if re == nil { - return; + return } strs := make([]string, len(match)/2); for i := 0; i < len(match); i++ { - strs[i/2] = str[match[i]:match[i+1]]; + strs[i/2] = str[match[i]:match[i+1]] } m := re.MatchStrings(str); if !equalStrings(m, strs) { @@ -266,10 +266,10 @@ func TestMatchStrings(t *T) { func matchFunctionTest(t *T, expr string, str string, match []int) { m, err := MatchString(expr, str); if err == "" { - return; + return } if m != (len(match) > 0) { - t.Error("function Match failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0); + t.Error("function Match failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0) } } diff --git a/src/pkg/testing/script/script.go b/src/pkg/testing/script/script.go index 6bf6ca26f..623685efd 100644 --- a/src/pkg/testing/script/script.go +++ b/src/pkg/testing/script/script.go @@ -43,7 +43,7 @@ type sendAction interface { func (e Event) isReady() bool { for _, predecessor := range e.predecessors { if !predecessor.occurred { - return false; + return false } } @@ -66,7 +66,7 @@ func (r Recv) getChannel() interface{} { return r.Channel } func (r Recv) recvMatch(chanEvent interface{}) bool { c, ok := chanEvent.(channelRecv); if !ok || c.channel != r.Channel { - return false; + return false } return reflect.DeepEqual(c.value, r.Expected); @@ -88,7 +88,7 @@ func (r RecvMatch) getChannel() interface{} { return r.Channel } func (r RecvMatch) recvMatch(chanEvent interface{}) bool { c, ok := chanEvent.(channelRecv); if !ok || c.channel != r.Channel { - return false; + return false } return r.Match(c.value); @@ -110,7 +110,7 @@ func (r Closed) getChannel() interface{} { return r.Channel } func (r Closed) recvMatch(chanEvent interface{}) bool { c, ok := chanEvent.(channelClosed); if !ok || c.channel != r.Channel { - return false; + return false } return true; @@ -130,7 +130,7 @@ func (s Send) getSend() sendAction { return s } func (s Send) getChannel() interface{} { return s.Channel } func newEmptyInterface(args ...) reflect.Value { - return reflect.NewValue(args).(*reflect.StructValue).Field(0); + return reflect.NewValue(args).(*reflect.StructValue).Field(0) } func (s Send) send() { @@ -140,9 +140,9 @@ func (s Send) send() { c := reflect.NewValue(s.Channel).(*reflect.ChanValue); var v reflect.Value; if iface, ok := c.Type().(*reflect.ChanType).Elem().(*reflect.InterfaceType); ok && iface.NumMethod() == 0 { - v = newEmptyInterface(s.Value); + v = newEmptyInterface(s.Value) } else { - v = reflect.NewValue(s.Value); + v = reflect.NewValue(s.Value) } c.Send(v); } @@ -170,7 +170,7 @@ type ReceivedUnexpected struct { func (r ReceivedUnexpected) String() string { names := make([]string, len(r.ready)); for i, v := range r.ready { - names[i] = v.name; + names[i] = v.name } return fmt.Sprintf("received unexpected value on one of the channels: %#v. Runnable events: %s", r.Value, strings.Join(names, ", ")); } @@ -224,23 +224,23 @@ func Perform(seed int64, events []*Event) (err os.Error) { channels, err := getChannels(events); if err != nil { - return; + return } multiplex := make(chan interface{}); for _, channel := range channels { - go recvValues(multiplex, channel); + go recvValues(multiplex, channel) } Outer: for { ready, err := readyEvents(events); if err != nil { - return err; + return err } if len(ready) == 0 { // All events occurred. - break; + break } event := ready[r.Intn(len(ready))]; @@ -271,11 +271,11 @@ func getChannels(events []*Event) ([]interface{}, os.Error) { j := 0; for _, event := range events { if recv := event.action.getRecv(); recv == nil { - continue; + continue } c := event.action.getChannel(); if _, ok := reflect.NewValue(c).(*reflect.ChanValue); !ok { - return nil, SetupError("one of the channel values is not a channel"); + return nil, SetupError("one of the channel values is not a channel") } duplicate := false; @@ -329,7 +329,7 @@ func readyEvents(events []*Event) ([]*Event, os.Error) { eventsWaiting := false; for _, event := range events { if event.occurred { - continue; + continue } eventsWaiting = true; @@ -343,7 +343,7 @@ func readyEvents(events []*Event) ([]*Event, os.Error) { names := make([]string, len(events)); for _, event := range events { if event.occurred { - continue; + continue } names[j] = event.name; } diff --git a/src/pkg/testing/script/script_test.go b/src/pkg/testing/script/script_test.go index a1c6f28a7..359218c60 100644 --- a/src/pkg/testing/script/script_test.go +++ b/src/pkg/testing/script/script_test.go @@ -11,7 +11,7 @@ import ( func TestNoop(t *testing.T) { err := Perform(0, nil); if err != nil { - t.Errorf("Got error: %s", err); + t.Errorf("Got error: %s", err) } } @@ -24,7 +24,7 @@ func TestSimple(t *testing.T) { err := Perform(0, []*Event{a, b}); if err != nil { - t.Errorf("Got error: %s", err); + t.Errorf("Got error: %s", err) } } @@ -37,9 +37,9 @@ func TestFail(t *testing.T) { err := Perform(0, []*Event{a, b}); if err == nil { - t.Errorf("Failed to get expected error"); + t.Errorf("Failed to get expected error") } else if _, ok := err.(ReceivedUnexpected); !ok { - t.Errorf("Error returned was of the wrong type: %s", err); + t.Errorf("Error returned was of the wrong type: %s", err) } } @@ -51,13 +51,13 @@ func TestClose(t *testing.T) { err := Perform(0, []*Event{a, b}); if err != nil { - t.Errorf("Got error: %s", err); + t.Errorf("Got error: %s", err) } } func matchOne(v interface{}) bool { if i, ok := v.(int); ok && i == 1 { - return true; + return true } return false; } @@ -70,6 +70,6 @@ func TestRecvMatch(t *testing.T) { err := Perform(0, []*Event{a, b}); if err != nil { - t.Errorf("Got error: %s", err); + t.Errorf("Got error: %s", err) } } diff --git a/src/pkg/testing/testing.go b/src/pkg/testing/testing.go index b04e8d40c..62c79e0b3 100644 --- a/src/pkg/testing/testing.go +++ b/src/pkg/testing/testing.go @@ -32,7 +32,7 @@ func tabify(s string) string { } for i := 0; i < n-1; i++ { // -1 to avoid final newline if s[i] == '\n' { - return s[0 : i+1]+"\t"+tabify(s[i+1 : n]); + return s[0 : i+1]+"\t"+tabify(s[i+1 : n]) } } return s; @@ -67,7 +67,7 @@ func (t *T) Log(args ...) { t.errors += "\t"+tabify(fmt.Sprintln(args)) } // Log formats its arguments according to the format, analogous to Printf(), // and records the text in the error log. func (t *T) Logf(format string, args ...) { - t.errors += "\t"+tabify(fmt.Sprintf(format, args)); + t.errors += "\t"+tabify(fmt.Sprintf(format, args)) } // Error is equivalent to Log() followed by Fail(). @@ -112,7 +112,7 @@ func Main(tests []Test) { flag.Parse(); ok := true; if len(tests) == 0 { - println("testing: warning: no tests to run"); + println("testing: warning: no tests to run") } re, err := CompileRegexp(*match); if err != "" { @@ -121,10 +121,10 @@ func Main(tests []Test) { } for i := 0; i < len(tests); i++ { if !re.MatchString(tests[i].Name) { - continue; + continue } if *chatty { - println("=== RUN ", tests[i].Name); + println("=== RUN ", tests[i].Name) } t := new(T); t.ch = make(chan *T); |