MCPcopy Create free account
hub / github.com/segmentio/encoding / tokenize

Function tokenize

json/token_test.go:44–72  ·  view source on GitHub ↗
(t *testing.T, b []byte)

Source from the content-addressed store, hash-verified

42}
43
44func tokenize(t *testing.T, b []byte) (tokens []token) {
45 tok := NewTokenizer(b)
46
47 for tok.Next() {
48 end := len(b) - tok.Remaining()
49 start := end - len(tok.Value)
50 if end > len(b) {
51 t.Fatalf("token position too far [%d:%d], len(b) is %d", start, end, len(b))
52 }
53 if !bytes.Equal(b[start:end], tok.Value) {
54 t.Fatalf("token position is wrong [%d:%d]", start, end)
55 }
56
57 tokens = append(tokens, token{
58 delim: tok.Delim,
59 value: tok.Value,
60 err: tok.Err,
61 depth: tok.Depth,
62 index: tok.Index,
63 isKey: tok.IsKey,
64 })
65 }
66
67 if tok.Err != nil {
68 t.Fatal(tok.Err)
69 }
70
71 return
72}
73
74func TestTokenizer(t *testing.T) {
75 tests := []struct {

Callers 1

TestTokenizerFunction · 0.85

Calls 3

NextMethod · 0.95
RemainingMethod · 0.95
NewTokenizerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…