From 43a123c1ae6613b3efeed291fa552ecd909d3acf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 16 Apr 2024 21:23:18 +0200 Subject: Adding upstream version 1.20.14. Signed-off-by: Daniel Baumann --- src/go/printer/testdata/expressions.raw | 743 ++++++++++++++++++++++++++++++++ 1 file changed, 743 insertions(+) create mode 100644 src/go/printer/testdata/expressions.raw (limited to 'src/go/printer/testdata/expressions.raw') diff --git a/src/go/printer/testdata/expressions.raw b/src/go/printer/testdata/expressions.raw new file mode 100644 index 0000000..058fded --- /dev/null +++ b/src/go/printer/testdata/expressions.raw @@ -0,0 +1,743 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package expressions + +type T struct { + x, y, z int +} + +var ( + a, b, c, d, e int + under_bar int + longIdentifier1, longIdentifier2, longIdentifier3 int + t0, t1, t2 T + s string + p *int +) + +func _() { + // no spaces around simple or parenthesized expressions + _ = (a + 0) + _ = a + b + _ = a + b + c + _ = a + b - c + _ = a - b - c + _ = a + (b * c) + _ = a + (b / c) + _ = a - (b % c) + _ = 1 + a + _ = a + 1 + _ = a + b + 1 + _ = s[a] + _ = s[a:] + _ = s[:b] + _ = s[1:2] + _ = s[a:b] + _ = s[0:len(s)] + _ = s[0] << 1 + _ = (s[0] << 1) & 0xf + _ = s[0]<<2 | s[1]>>4 + _ = "foo" + s + _ = s + "foo" + _ = 'a' + 'b' + _ = len(s) / 2 + _ = len(t0.x) / a + + // spaces around expressions of different precedence or expressions containing spaces + _ = a + -b + _ = a - ^b + _ = a / *p + _ = a + b*c + _ = 1 + b*c + _ = a + 2*c + _ = a + c*2 + _ = 1 + 2*3 + _ = s[1 : 2*3] + _ = s[a : b-c] + _ = s[0:] + _ = s[a+b] + _ = s[:b-c] + _ = s[a+b:] + _ = a[a< b + _ = a >= b + _ = a < b + _ = a <= b + _ = a < b && c > d + _ = a < b || c > d + + // spaces around "long" operands + _ = a + longIdentifier1 + _ = longIdentifier1 + a + _ = longIdentifier1 + longIdentifier2*longIdentifier3 + _ = s + "a longer string" + + // some selected cases + _ = a + t0.x + _ = a + t0.x + t1.x*t2.x + _ = a + b + c + d + e + 2*3 + _ = a + b + c + 2*3 + d + e + _ = (a + b + c) * 2 + _ = a - b + c - d + (a + b + c) + d&e + _ = under_bar - 1 + _ = Open(dpath+"/file", O_WRONLY|O_CREAT, 0666) + _ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx) + + // test case for issue 8021 + // want: + // ([]bool{})[([]int{})[((1)+(((1)+((((1)*(((1)+(1))+(1)))+(1))*(1)))+(1)))]] + _ = ([]bool{})[([]int{})[((1)+(((1)+((((1)*(((1)+(1))+(1)))+(1))*(1)))+(1)))]] + + // the parser does not restrict expressions that may appear as statements + true + 42 + "foo" + x + (x) + a + b + a + b + c + a + (b * c) + a + (b / c) + 1 + a + a + 1 + s[a] + x << 1 + (s[0] << 1) & 0xf + "foo" + s + x == y + x < y || z > 42 +} + +// slice expressions with cap +func _() { + _ = x[a:b:c] + _ = x[a : b : c+d] + _ = x[a : b+d : c] + _ = x[a : b+d : c+d] + _ = x[a+d : b : c] + _ = x[a+d : b : c+d] + _ = x[a+d : b+d : c] + _ = x[a+d : b+d : c+d] + + _ = x[:b:c] + _ = x[: b : c+d] + _ = x[: b+d : c] + _ = x[: b+d : c+d] +} + +func issue22111() { + _ = x[:] + + _ = x[:b] + _ = x[:b+1] + + _ = x[a:] + _ = x[a+1:] + + _ = x[a:b] + _ = x[a+1 : b] + _ = x[a : b+1] + _ = x[a+1 : b+1] + + _ = x[:b:c] + _ = x[: b+1 : c] + _ = x[: b : c+1] + _ = x[: b+1 : c+1] + + _ = x[a:b:c] + _ = x[a+1 : b : c] + _ = x[a : b+1 : c] + _ = x[a+1 : b+1 : c] + _ = x[a : b : c+1] + _ = x[a+1 : b : c+1] + _ = x[a : b+1 : c+1] + _ = x[a+1 : b+1 : c+1] +} + +func _() { + _ = a + b + _ = a + b + c + _ = a + b*c + _ = a + (b * c) + _ = (a + b) * c + _ = a + (b * c * d) + _ = a + (b*c + d) + + _ = 1 << x + _ = -1 << x + _ = 1<>4 + + b.buf = b.buf[0 : b.off+m+n] + b.buf = b.buf[0 : b.off+m*n] + f(b.buf[0 : b.off+m+n]) + + signed += ' ' * 8 + tw.octal(header[148:155], chksum) + + _ = x > 0 && i >= 0 + + x1, x0 := x>>w2, x&m2 + z0 = t1<>w2) >> w2 + q1, r1 := x1/d1, x1%d1 + r1 = r1*b2 | x0>>w2 + x1 = (x1 << z) | (x0 >> (uint(w) - z)) + x1 = x1<>(uint(w)-z) + + _ = buf[0 : len(buf)+1] + _ = buf[0 : n+1] + + a, b = b, a + a = b + c + a = b*c + d + _ = a*b + c + _ = a - b - c + _ = a - (b - c) + _ = a - b*c + _ = a - (b * c) + _ = a * b / c + _ = a / *b + _ = x[a|^b] + _ = x[a / *b] + _ = a & ^b + _ = a + +b + _ = a - -b + _ = x[a*-b] + _ = x[a + +b] + _ = x ^ y ^ z + _ = b[a>>24] ^ b[(a>>16)&0xFF] ^ b[(a>>8)&0xFF] ^ b[a&0xFF] + _ = len(longVariableName) * 2 + + _ = token(matchType + xlength<