Debian Codegraph @

gopls/internal/test/marker/testdata/hover/const.txt

raw
1 This test checks hovering over constants.
2
3 -- go.mod --
4 module mod.com
5
6 go 1.17
7
8 -- c.go --
9 package c
10
11 import (
12 "math"
13 "time"
14 )
15
16 const X = 0 //@hover("X", "X", bX)
17
18 // dur is a constant of type time.Duration.
19 const dur = 15*time.Minute + 10*time.Second + 350*time.Millisecond //@hover("dur", "dur", dur)
20
21 const _ = dur // pacify unusedfunc
22
23 // MaxFloat32 is used in another package.
24 const MaxFloat32 = 0x1p127 * (1 + (1 - 0x1p-23))
25
26 // Numbers.
27 func _() {
28 const hex, bin = 0xe34e, 0b1001001
29
30 const (
31 // no inline comment
32 decimal = 153
33
34 numberWithUnderscore int64 = 10_000_000_000
35 octal = 0o777
36 expr = 2 << (0b111&0b101 - 2)
37 boolean = (55 - 3) == (26 * 2)
38 )
39
40 _ = decimal //@hover("decimal", "decimal", decimalConst)
41 _ = hex //@hover("hex", "hex", hexConst)
42 _ = bin //@hover("bin", "bin", binConst)
43 _ = numberWithUnderscore //@hover("numberWithUnderscore", "numberWithUnderscore", numberWithUnderscoreConst)
44 _ = octal //@hover("octal", "octal", octalConst)
45 _ = expr //@hover("expr", "expr", exprConst)
46 _ = boolean //@hover("boolean", "boolean", boolConst)
47
48 const ln10 = 2.30258509299404568401799145468436420760110148862877297603332790
49
50 _ = ln10 //@hover("ln10", "ln10", ln10Const)
51 }
52
53 // Iota.
54 func _() {
55 const (
56 a = 1 << iota
57 b
58 )
59
60 _ = a //@hover("a", "a", aIota)
61 _ = b //@hover("b", "b", bIota)
62 }
63
64 // Strings.
65 func _() {
66 const (
67 str = "hello" + " " + "world"
68 longStr = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eget ipsum non nunc
69 molestie mattis id quis augue. Mauris dictum tincidunt ipsum, in auctor arcu congue eu.
70 Morbi hendrerit fringilla libero commodo varius. Vestibulum in enim rutrum, rutrum tellus
71 aliquet, luctus enim. Nunc sem ex, consectetur id porta nec, placerat vel urna.`
72 )
73
74 _ = str //@hover("str", "str", strConst)
75 _ = longStr //@hover("longStr", "longStr", longStrConst)
76 }
77
78 // Constants from other packages.
79 func _() {
80 _ = math.Log2E //@hover("Log2E", "Log2E", log2eConst)
81 }
82
83 -- @bX --
84 ```go
85 const X untyped int = 0
86 ```
87
88 ---
89
90 @hover("X", "X", bX)
91
92
93 ---
94
95 [`c.X` on pkg.go.dev](https://pkg.go.dev/mod.com#X)
96 -- @dur --
97 ```go
98 const dur time.Duration = 15*time.Minute + 10*time.Second + 350*time.Millisecond // 15m10.35s
99 ```
100
101 ---
102
103 dur is a constant of type time.Duration.
104 -- @decimalConst --
105 ```go
106 const decimal untyped int = 153
107 ```
108
109 ---
110
111 no inline comment
112 -- @hexConst --
113 ```go
114 const hex untyped int = 0xe34e // 58190
115 ```
116 -- @binConst --
117 ```go
118 const bin untyped int = 0b1001001 // 73
119 ```
120 -- @numberWithUnderscoreConst --
121 ```go
122 const numberWithUnderscore int64 = 10_000_000_000 // 10000000000
123 ```
124 -- @octalConst --
125 ```go
126 const octal untyped int = 0o777 // 511
127 ```
128 -- @exprConst --
129 ```go
130 const expr untyped int = 2 << (0b111&0b101 - 2) // 16
131 ```
132 -- @boolConst --
133 ```go
134 const boolean untyped bool = (55 - 3) == (26 * 2) // true
135 ```
136 -- @ln10Const --
137 ```go
138 const ln10 untyped float = 2.30258509299404568401799145468436420760110148862877297603332790 // 2.30259
139 ```
140 -- @aIota --
141 ```go
142 const a untyped int = 1 << iota // 1
143 ```
144 -- @bIota --
145 ```go
146 const b untyped int = 2
147 ```
148 -- @strConst --
149 ```go
150 const str untyped string = "hello world"
151 ```
152 -- @longStrConst --
153 ```go
154 const longStr untyped string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur e...
155 ```
156 -- @log2eConst --
157 ```go
158 const math.Log2E untyped float = 1 / Ln2 // 1.4427
159 ```
160
161 ---
162
163 Mathematical constants.
164
165
166 ---
167
168 [`math.Log2E` on pkg.go.dev](https://pkg.go.dev/math#Log2E)