/
fmt.go
64 lines (54 loc) 路 2.17 KB
/
fmt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package mocks
import (
"context"
"encoding/json"
"go/ast"
"github.com/1pkg/gopium/collections"
"github.com/1pkg/gopium/gopium"
)
// Bytes defines mock fmtio bytes implementation
type Bytes struct {
Err error `gopium:"filter_pads,memory_pack,cache_rounding_cpu_l1_discrete,struct_annotate_comment,add_tag_group_force"`
} // struct size: 16 bytes; struct align: 8 bytes; struct aligned size: 16 bytes; - 馃尯 gopium @1pkg
// Bytes mock implementation
func (fmt Bytes) Bytes(sts []gopium.Struct) ([]byte, error) {
// in case we have error
// return it back
if fmt.Err != nil {
return nil, fmt.Err
}
// otherwise use json bytes impl
return json.MarshalIndent(sts, "", "\t")
}
// Ast defines mock ast type spec implementation
type Ast struct {
Err error `gopium:"filter_pads,memory_pack,cache_rounding_cpu_l1_discrete,struct_annotate_comment,add_tag_group_force"`
} // struct size: 16 bytes; struct align: 8 bytes; struct aligned size: 16 bytes; - 馃尯 gopium @1pkg
// Ast mock implementation
func (fmt Ast) Ast(*ast.TypeSpec, gopium.Struct) error {
return fmt.Err
}
// Diff defines mock diff implementation
type Diff struct {
Err error `gopium:"filter_pads,memory_pack,cache_rounding_cpu_l1_discrete,struct_annotate_comment,add_tag_group_force"`
} // struct size: 16 bytes; struct align: 8 bytes; struct aligned size: 16 bytes; - 馃尯 gopium @1pkg
// Diff mock implementation
func (fmt Diff) Diff(o gopium.Categorized, r gopium.Categorized) ([]byte, error) {
// in case we have error
// return it back
if fmt.Err != nil {
return nil, fmt.Err
}
// otherwise use json bytes impl
fo, fr := collections.Flat(o.Full()), collections.Flat(r.Full())
data := [][]gopium.Struct{fo.Sorted(), fr.Sorted()}
return json.MarshalIndent(data, "", "\t")
}
// Apply defines mock apply implementation
type Apply struct {
Err error `gopium:"filter_pads,memory_pack,cache_rounding_cpu_l1_discrete,struct_annotate_comment,add_tag_group_force"`
} // struct size: 16 bytes; struct align: 8 bytes; struct aligned size: 16 bytes; - 馃尯 gopium @1pkg
// Apply mock implementation
func (a Apply) Apply(context.Context, *ast.Package, gopium.Locator, gopium.Categorized) (*ast.Package, error) {
return nil, a.Err
}