1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 longIdentifier1, longIdentifier2, longIdentifier3 int
22 // no spaces around simple or parenthesized expressions
49 // spaces around expressions of different precedence or expressions containing spaces
71 // spaces around operators with equal or lower precedence than comparisons
81 // spaces around "long" operands
82 _ = a + longIdentifier1
83 _ = longIdentifier1 + a
84 _ = longIdentifier1 + longIdentifier2*longIdentifier3
85 _ = s + "a longer string"
87 // some selected cases
89 _ = a + t0.x + t1.x*t2.x
90 _ = a + b + c + d + e + 2*3
91 _ = a + b + c + 2*3 + d + e
93 _ = a - b + c - d + (a + b + c) + d&e
95 _ = Open(dpath+"/file", O_WRONLY|O_CREAT, 0666)
96 _ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx)
120 1<<d.logWindowSize - 1
122 buf = make(x, 2*cap(b.buf)+n)
124 dst[i*3+2] = dbuf[0] << 2
125 dst[i*3+2] = dbuf[0]<<2 | dbuf[1]>>4
127 b.buf = b.buf[0 : b.off+m+n]
128 b.buf = b.buf[0 : b.off+m*n]
129 f(b.buf[0 : b.off+m+n])
132 tw.octal(header[148:155], chksum)
136 x1, x0 := x>>w2, x&m2
138 z1 = (t1 + t0>>w2) >> w2
139 q1, r1 := x1/d1, x1%d1
141 x1 = (x1 << z) | (x0 >> (uint(w) - z))
142 x1 = x1<<z | x0>>(uint(w)-z)
165 b[a>>24] ^ b[(a>>16)&0xFF] ^ b[(a>>8)&0xFF] ^ b[a&0xFF]
166 len(longVariableName) * 2
168 token(matchType + xlength<<lengthShift + xoffset)
172 func f(x int, args ...int) {
177 // make sure syntactically legal code remains syntactically legal
178 f(3, 42 ...) // a blank must remain between 42 and ...
188 _ = 42 .x // a blank must remain between 42 and .x
198 // a blank must remain between the binary operator and the 2nd operand
207 _ = f(x / *y, x < -1, x < <-1, x + +1, x - -1, x & &x, x & ^x)
221 // one-line structs/interfaces in composite literals (up to a threshold)
224 _ = struct{ x int }{0}
225 _ = struct{ x, y, z int }{0, 1, 2}
231 }{struct{ int }{0}} // compositeLit context not propagated => multiLine result
236 // do not modify literals
237 _ = "tab1 tab2 tab3 end" // string contains 3 tabs
238 _ = "tab1 tab2 tab3 end" // same string with 3 blanks - may be unaligned because editors see tabs in strings
239 _ = "" // this comment should be aligned with the one on the previous line
245 _ = `three spaces before the end of the line starting here:
246 they must not be removed`
251 // smart handling of indentation for multi-line raw strings
260 // the next line should not be indented
269 // the next line should not be indented
273 var _ = /* comment */ ``
274 var _ = /* comment */ `foo`
275 var _ = /* comment */ `foo
278 var _ = /* comment */
280 var _ = /* comment */
282 var _ = /* comment */
283 // the next line should not be indented
303 // the next line should not be indented
322 // one-line function literals (body is on a single line)
324 _ = func() int { return 0 }
325 _ = func(x, y int) bool { m := (x + y) / 2; return m < 0 }
327 // multi-line function literals (body is not on one line)
333 _ = func(x, y int) bool {
343 f(func(x, y int) bool {
366 _ = [][]int{{1}, {1, 2}, {1, 2, 3}}
370 // various multi-line expressions
372 // do not add extra indentation to multi-line string lists
389 `datafmt.T2 = s ["-" p "-"];`
392 const _ = `datafmt "datafmt";` +
395 `datafmt.T3 = s {" " a a / ","};`
398 const _ = `datafmt "datafmt";` +
401 `datafmt.T3 = s {" " a a / ","};`
408 `datafmt.T2 = s ["-" p "-"];`
411 `datafmt "datafmt";` +
414 `datafmt.T3 = s {" " a a / ","};`
416 _ = `datafmt "datafmt";` +
419 `datafmt.T3 = s {" " a a / ","};`
424 // respect source lines in multi-line expressions
430 _ = "933262154439441526816992388562667004907159682643816214685929" +
431 "638952175999932299156089414639761565182862536979208272237582" +
432 "51185210916864000000000000000000000000" // 100!
433 _ = "170141183460469231731687303715884105727" // prime
437 // Alignment after overlong lines
440 _ = "2432902008176640000" // 20!
441 _ = "933262154439441526816992388562667004907159682643816214685929" +
442 "638952175999932299156089414639761565182862536979208272237582" +
443 "51185210916864000000000000000000000000" // 100!
444 _ = "170141183460469231731687303715884105727" // prime
448 // Correct placement of operators and comments in multi-line expressions
456 _ = "ba0408" + "7265717569726564" // field 71, encoding 2, string "required"
460 // Correct placement of terminating comma/closing parentheses in multi-line calls.
486 // Align comments in multi-line lists of single-line expressions.
487 var txpix = [NCOL]draw.Color{
488 draw.Yellow, // yellow
490 draw.Green, // lime green
491 draw.GreyBlue, // slate
493 draw.GreyGreen, /* olive green */
494 draw.Blue, /* blue */
495 draw.Color(0xFF55AAFF), /* pink */
496 draw.Color(0xFFAAFFFF), /* lavender */
497 draw.Color(0xBB005DFF), /* maroon */
501 func same(t, u *Time) bool {
502 // respect source lines in multi-line expressions
503 return t.Year == u.Year &&
504 t.Month == u.Month &&
507 t.Minute == u.Minute &&
508 t.Second == u.Second &&
509 t.Weekday == u.Weekday &&
510 t.ZoneOffset == u.ZoneOffset &&
515 func (p *parser) charClass() {
516 // respect source lines in multi-line expressions
517 if cc.negate && len(cc.ranges) == 2 &&
518 cc.ranges[0] == '\n' && cc.ranges[1] == '\n' {
525 func addState(s []state, inst instr, match []int) {
526 // handle comments correctly in multi-line expressions
527 for i := 0; i < l; i++ {
528 if s[i].inst.index() == index && // same instruction
529 s[i].match[0] < pos { // earlier match already going; leftmost wins
535 func (self *T) foo(x int) *T { return self }
537 func _() { module.Func1().Func2() }
547 foo(2). // inline comments
550 _ = new(T).foo(1).foo(2).foo(3)
552 // handle multiline argument list correctly