this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

doc/ref/spec: reflect reality w.r.t. octal numbers

0123:
- cue/parser|scanner: not accepted (done)
- cue: accepted if present in AST (done)
- cue/format: accepted but convert

Also added a test for multiline label acceptance.
This is also tested in another package.

Change-Id: If3cf3892e03020528840cedca760dea9552df84c
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3442
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>

+50 -2
+39
cue/format/format_test.go
··· 226 226 } 227 227 } 228 228 229 + // TestNodes tests nodes that are that are invalid CUE, but are accepted by 230 + // format. 231 + func TestNodes(t *testing.T) { 232 + testCases := []struct { 233 + name string 234 + in ast.Node 235 + out string 236 + }{{ 237 + name: "old-style octal numbers", 238 + in: &ast.BasicLit{Kind: token.INT, Value: "0123"}, 239 + out: "0o123", 240 + }, { 241 + name: "labels with multi-line strings", 242 + in: &ast.Field{ 243 + Label: &ast.BasicLit{ 244 + Kind: token.STRING, 245 + Value: `""" 246 + foo 247 + bar 248 + """`, 249 + }, 250 + Value: ast.NewIdent("goo"), 251 + }, 252 + out: `"foo\nbar": goo`, 253 + }} 254 + for _, tc := range testCases { 255 + t.Run(tc.name, func(t *testing.T) { 256 + b, err := Node(tc.in) 257 + if err != nil { 258 + t.Fatal(err) 259 + } 260 + if got := string(b); got != tc.out { 261 + t.Errorf("\ngot: %v; want: %v", got, tc.out) 262 + } 263 + }) 264 + } 265 + 266 + } 267 + 229 268 // Verify that the printer doesn't crash if the AST contains BadXXX nodes. 230 269 func TestBadNodes(t *testing.T) { 231 270 const src = "package p\n("
+9
cue/format/printer.go
··· 107 107 108 108 case *ast.BasicLit: 109 109 data = x.Value 110 + switch x.Kind { 111 + case token.INT: 112 + if len(data) > 1 && 113 + data[0] == '0' && 114 + data[1] >= '0' && data[1] <= '9' { 115 + data = "0o" + data[1:] 116 + } 117 + } 118 + 110 119 isLit = true 111 120 impliedComma = true 112 121 p.lastTok = x.Kind
+2 -2
doc/ref/spec.md
··· 302 302 ### Integer literals 303 303 304 304 An integer literal is a sequence of digits representing an integer value. 305 - An optional prefix sets a non-decimal base: 0 for octal, 305 + An optional prefix sets a non-decimal base: 0o for octal, 306 306 0x or 0X for hexadecimal, and 0b for binary. 307 307 In hexadecimal literals, letters a-f and A-F represent values 10 through 15. 308 308 All integers allow interstitial underscores "_"; ··· 321 321 "." decimals multiplier . 322 322 binary_lit = "0b" binary_digit { binary_digit } . 323 323 hex_lit = "0" ( "x" | "X" ) hex_digit { [ "_" ] hex_digit } . 324 - octal_lit = "0" [ "o" ] octal_digit { [ "_" ] octal_digit } . 324 + octal_lit = "0o" octal_digit { [ "_" ] octal_digit } . 325 325 multiplier = ( "K" | "M" | "G" | "T" | "P" | "E" | "Y" | "Z" ) [ "i" ] 326 326 327 327 float_lit = decimals "." [ decimals ] [ exponent ] |