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
42 _ = s[0] << 2 | s[1] >> 4
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)
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
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}
227 _ = struct{ s struct { int } }{struct{ int}{0} }
232 // do not modify literals
233 _ = "tab1 tab2 tab3 end" // string contains 3 tabs
234 _ = "tab1 tab2 tab3 end" // same string with 3 blanks - may be unaligned because editors see tabs in strings
235 _ = "" // this comment should be aligned with the one on the previous line
241 _ = `three spaces before the end of the line starting here:
242 they must not be removed`
247 // smart handling of indentation for multi-line raw strings
259 // the next line should not be indented
269 // the next line should not be indented
274 var _ = /* comment */ ``
275 var _ = /* comment */ `foo`
276 var _ = /* comment */ `foo
280 var _ = /* comment */
282 var _ = /* comment */
284 var _ = /* comment */
285 // the next line should not be indented
307 // the next line should not be indented
326 // one-line function literals (body is on a single line)
328 _ = func() int { return 0 }
329 _ = func(x, y int) bool { m := (x+y)/2; return m < 0 }
331 // multi-line function literals (body is not on one line)
337 _ = func(x, y int) bool {
338 m := (x+y)/2; return x < y }
345 f(func(x, y int) bool {
346 m := (x+y)/2; return x < y })
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 "-"];`
393 `datafmt "datafmt";` +
396 `datafmt.T3 = s {" " a a / ","};`
399 const _ = `datafmt "datafmt";` +
402 `datafmt.T3 = s {" " a a / ","};`
409 `datafmt.T2 = s ["-" p "-"];`
412 `datafmt "datafmt";` +
415 `datafmt.T3 = s {" " a a / ","};`
417 _ = `datafmt "datafmt";` +
420 `datafmt.T3 = s {" " a a / ","};`
425 // respect source lines in multi-line expressions
431 _ = "933262154439441526816992388562667004907159682643816214685929" +
432 "638952175999932299156089414639761565182862536979208272237582" +
433 "51185210916864000000000000000000000000" // 100!
434 _ = "170141183460469231731687303715884105727" // prime
438 // Alignment after overlong lines
441 _ = "2432902008176640000" // 20!
442 _ = "933262154439441526816992388562667004907159682643816214685929" +
443 "638952175999932299156089414639761565182862536979208272237582" +
444 "51185210916864000000000000000000000000" // 100!
445 _ = "170141183460469231731687303715884105727" // prime
449 // Correct placement of operators and comments in multi-line expressions
457 _ = "ba0408" + "7265717569726564" // field 71, encoding 2, string "required"
461 // Correct placement of terminating comma/closing parentheses in multi-line calls.
487 // Align comments in multi-line lists of single-line expressions.
488 var txpix = [NCOL]draw.Color{
489 draw.Yellow, // yellow
491 draw.Green, // lime green
492 draw.GreyBlue, // slate
494 draw.GreyGreen, /* olive green */
495 draw.Blue, /* blue */
496 draw.Color(0xFF55AAFF), /* pink */
497 draw.Color(0xFFAAFFFF), /* lavender */
498 draw.Color(0xBB005DFF), /* maroon */
502 func same(t, u *Time) bool {
503 // respect source lines in multi-line expressions
504 return t.Year == u.Year &&
505 t.Month == u.Month &&
508 t.Minute == u.Minute &&
509 t.Second == u.Second &&
510 t.Weekday == u.Weekday &&
511 t.ZoneOffset == u.ZoneOffset &&
516 func (p *parser) charClass() {
517 // respect source lines in multi-line expressions
518 if cc.negate && len(cc.ranges) == 2 &&
519 cc.ranges[0] == '\n' && cc.ranges[1] == '\n' {
526 func addState(s []state, inst instr, match []int) {
527 // handle comments correctly in multi-line expressions
528 for i := 0; i < l; i++ {
529 if s[i].inst.index() == index && // same instruction
530 s[i].match[0] < pos { // earlier match already going; leftmost wins
536 func (self *T) foo(x int) *T { return self }
538 func _() { module.Func1().Func2() }
548 foo(2). // inline comments
551 _ = new(T).foo(1).foo(2).foo(3)
553 // handle multiline argument list correctly