sublimehq / Packages

Syntax highlighting files shipped with Sublime Text and Sublime Merge
https://sublimetext.com
Other
2.95k stars 587 forks source link

[Go] Definitions for indexed fmt verbs are incorrect #4044

Open kortschak opened 16 hours ago

kortschak commented 16 hours ago

What happened?

The definitions for indexed fmt verbs are incorrect; this is driven by the test cases being incorrect. The correct syntax for an indexed fmt verb has the argument indexing immediately before the verb. This is not what the definitions are tested against.

For example, https://github.com/sublimehq/Packages/blob/bc9e712e859054d5d6d82d09755ef559dfe4455c/Go/tests/syntax_test_go.go#L4503 and https://github.com/sublimehq/Packages/blob/bc9e712e859054d5d6d82d09755ef559dfe4455c/Go/tests/syntax_test_go.go#L4506

The syntax shown in the tests can be demonstrated to be incorrect by running the following program (or reading the fmt docs, but this is quicker). In the two examples, the syntax corresponding to the tests here gives incorrect output.

package main

import "fmt"

func main() {
    fmt.Printf("incorrect: %[1]+v\n", map[string]int{})
    fmt.Printf("correct:   %+[1]v\n", map[string]int{})
    fmt.Printf("incorrect: %[1]1.2d\n", 1)
    fmt.Printf("correct:   %1.2[1]d\n", 1)
}

https://go.dev/play/p/LIFcr4GbQZj output:

incorrect: map[]v
correct:   map[]
incorrect: %!d(BADINDEX)
correct:   01

The tests should look like this (with other tests that should also pass added).

diff --git a/Go/tests/syntax_test_go.go b/Go/tests/syntax_test_go.go
index be5985f3..de540103 100644
--- a/Go/tests/syntax_test_go.go
+++ b/Go/tests/syntax_test_go.go
@@ -4490,6 +4490,9 @@ by accident, but if necessary, such support could be sacrificed.
 //       ^^ constant.other.placeholder.go
     "one %+v two"
 //  ^^^^^^^^^^^^^ meta.string.go string.quoted.double.go
+//       ^^^ constant.other.placeholder.go
+    "one %#v two"
+//  ^^^^^^^^^^^^^ meta.string.go string.quoted.double.go
 //       ^^^ constant.other.placeholder.go
     "one %1.2d two"
 //  ^^^^^^^^^^^^^^^ meta.string.go string.quoted.double.go
@@ -4500,10 +4503,13 @@ by accident, but if necessary, such support could be sacrificed.
     "one %[1]v two"
 //  ^^^^^^^^^^^^^^^ meta.string.go string.quoted.double.go
 //       ^^^^^ constant.other.placeholder.go
-    "one %[1]+v two"
+    "one %+[1]v two"
+//  ^^^^^^^^^^^^^^^^ meta.string.go string.quoted.double.go
+//       ^^^^^^ constant.other.placeholder.go
+    "one %#[1]v two"
 //  ^^^^^^^^^^^^^^^^ meta.string.go string.quoted.double.go
 //       ^^^^^^ constant.other.placeholder.go
-    "one %[1]1.2d two"
+    "one %1.2[1]d two"
 //  ^^^^^^^^^^^^^^^^^^ meta.string.go string.quoted.double.go
 //       ^^^^^^^^ constant.other.placeholder.go
     "foo %*f bar"

It's been at least a couple of years since I made a contribution here, and I have no recollection of where to get the testing tools from, and I don't see it in the README.

michaelblyons commented 14 hours ago

I have no recollection of where to get the testing tools from,

It's built in. Run a build from the syntax file.

kortschak commented 8 hours ago

It's built in. Run a build from the syntax file.

Is there some documentation?