| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package json |
| 6 |
|
| 7 |
import ( |
| 8 |
"os" |
| 9 |
"os/exec" |
| 10 |
"strings" |
| 11 |
"testing" |
| 12 |
) |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
var testInline = os.Getenv("TEST_INLINE") != "" |
| 20 |
|
| 21 |
func TestInline(t *testing.T) { |
| 22 |
if !testInline { |
| 23 |
t.SkipNow() |
| 24 |
} |
| 25 |
|
| 26 |
fncs := func() map[string]bool { |
| 27 |
m := make(map[string]bool) |
| 28 |
for _, s := range []string{ |
| 29 |
"Encoder.needFlush", |
| 30 |
"Decoder.ReadValue", |
| 31 |
"decodeBuffer.needMore", |
| 32 |
"consumeWhitespace", |
| 33 |
"consumeNull", |
| 34 |
"consumeFalse", |
| 35 |
"consumeTrue", |
| 36 |
"consumeSimpleString", |
| 37 |
"consumeString", |
| 38 |
"consumeSimpleNumber", |
| 39 |
"consumeNumber", |
| 40 |
"unescapeStringMayCopy", |
| 41 |
"hasSuffixByte", |
| 42 |
"trimSuffixByte", |
| 43 |
"trimSuffixString", |
| 44 |
"trimSuffixWhitespace", |
| 45 |
"stateMachine.appendLiteral", |
| 46 |
"stateMachine.appendNumber", |
| 47 |
"stateMachine.appendString", |
| 48 |
"stateMachine.depth", |
| 49 |
"stateMachine.reset", |
| 50 |
"stateMachine.mayAppendDelim", |
| 51 |
"stateMachine.needDelim", |
| 52 |
"stateMachine.popArray", |
| 53 |
"stateMachine.popObject", |
| 54 |
"stateMachine.pushArray", |
| 55 |
"stateMachine.pushObject", |
| 56 |
"stateEntry.increment", |
| 57 |
"stateEntry.decrement", |
| 58 |
"stateEntry.isArray", |
| 59 |
"stateEntry.isObject", |
| 60 |
"stateEntry.length", |
| 61 |
"stateEntry.needImplicitColon", |
| 62 |
"stateEntry.needImplicitComma", |
| 63 |
"stateEntry.needObjectName", |
| 64 |
"stateEntry.needObjectValue", |
| 65 |
"objectNameStack.reset", |
| 66 |
"objectNameStack.length", |
| 67 |
"objectNameStack.getUnquoted", |
| 68 |
"objectNameStack.push", |
| 69 |
"objectNameStack.replaceLastQuotedOffset", |
| 70 |
"objectNameStack.replaceLastUnquotedName", |
| 71 |
"objectNameStack.pop", |
| 72 |
"objectNameStack.ensureCopiedBuffer", |
| 73 |
"objectNamespace.insertQuoted", |
| 74 |
"objectNamespace.insertUnquoted", |
| 75 |
"Token.String", |
| 76 |
"foldName", |
| 77 |
"hash64", |
| 78 |
} { |
| 79 |
m[s] = true |
| 80 |
} |
| 81 |
return m |
| 82 |
}() |
| 83 |
|
| 84 |
cmd := exec.Command("go", "build", "-gcflags=-m") |
| 85 |
b, err := cmd.CombinedOutput() |
| 86 |
if err != nil { |
| 87 |
t.Fatalf("exec.Command error: %v\n\n%s", err, b) |
| 88 |
} |
| 89 |
for _, line := range strings.Split(string(b), "\n") { |
| 90 |
const phrase = ": can inline " |
| 91 |
if i := strings.Index(line, phrase); i >= 0 { |
| 92 |
fnc := line[i+len(phrase):] |
| 93 |
fnc = strings.ReplaceAll(fnc, "(", "") |
| 94 |
fnc = strings.ReplaceAll(fnc, "*", "") |
| 95 |
fnc = strings.ReplaceAll(fnc, ")", "") |
| 96 |
delete(fncs, fnc) |
| 97 |
} |
| 98 |
} |
| 99 |
for fnc := range fncs { |
| 100 |
t.Errorf("%v is not inlineable, expected it to be", fnc) |
| 101 |
} |
| 102 |
} |