More Testing
Introduction
How about some GO code?
1// Copyright 2019 The Hugo Authors. All rights reserved.
2// Some functions in this file (see comments) is based on the Go source code,
3// copyright The Go Authors and governed by a BSD-style license.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16// Package codegen contains helpers for code generation.
17package codegen
18
19import (
20 "fmt"
21 "go/ast"
22 "go/parser"
23 "go/token"
24 "os"
25 "path"
26 "path/filepath"
27 "reflect"
28 "regexp"
29 "slices"
30 "sort"
31 "strings"
32 "sync"
33)
34
35// Make room for insertions
36const weightWidth = 1000
37
38// NewInspector creates a new Inspector given a source root.
39func NewInspector(root string) *Inspector {
40 return &Inspector{ProjectRootDir: root}
41}
42
43// Inspector provides methods to help code generation. It uses a combination
44// of reflection and source code AST to do the heavy lifting.
45type Inspector struct {
46 ProjectRootDir string
47
48 init sync.Once
49
50 // Determines method order. Go's reflect sorts lexicographically, so
51 // we must parse the source to preserve this order.
52 methodWeight map[string]map[string]int
53}