Debian Codegraph @

pkg/makefile/parser_test.go

raw symbols SCIP
1 // Copyright (c) Bartłomiej Płotka @bwplotka
2 // Licensed under the Apache License 2.0.
3
4 package makefile
5
6 import (
7 "fmt"
8 "strings"
9 )
10
11 func ExampleParser_Parse_withComments() {
12 contents := `
13 include github.com/tj/foo
14 # Stuff here:
15 #
16 # :)
17 #
18 # Start the dev server.
19 start:
20 @gopherjs -m -v serve --http :3000 github.com/tj/docs/client
21 .PHONY: start
22 # Start the API server.
23 api:
24 @go run server/cmd/api/api.go
25 .PHONY: api
26 # Display dependency graph.
27 deps:
28 @godepgraph github.com/tj/docs/client | dot -Tsvg | browser
29 .PHONY: deps
30 # Display size of dependencies.
31 #
32 # - foo
33 # - bar
34 # - baz
35 #
36 size:
37 @gopherjs build client/*.go -m -o /tmp/out.js
38 @du -h /tmp/out.js
39 @gopher-count /tmp/out.js | sort -nr
40 .PHONY: size
41 .PHONY: dummy
42 # Just a comment.
43 # Just another comment.
44 dummy:
45 @ls
46 `
47
48 nodes, err := Parse(strings.NewReader(contents))
49 if err != nil {
50 panic(err)
51 }
52
53 for _, node := range nodes {
54 fmt.Printf("%#v\n", node)
55 }
56
57 // Output:
58 // makefile.Include{node:makefile.node{lines:[]int{1}}, Value:"github.com/tj/foo"}
59 // makefile.Comment{node:makefile.node{lines:[]int{7}}, Target:"start", Value:"Stuff here:\n\n :)\n\nStart the dev server.", Default:false}
60 // makefile.Comment{node:makefile.node{lines:[]int{8, 11}}, Target:"api", Value:"Start the API server.", Default:false}
61 // makefile.Comment{node:makefile.node{lines:[]int{15}}, Target:"deps", Value:"Display dependency graph.", Default:false}
62 // makefile.Comment{node:makefile.node{lines:[]int{24}}, Target:"size", Value:"Display size of dependencies.\n\n- foo\n- bar\n- baz", Default:false}
63 // makefile.Comment{node:makefile.node{lines:[]int{32}}, Target:"dummy", Value:"Just a comment.\nJust another comment.", Default:false}
64 }
65
66 func ExampleParser_Parse_withoutComments() {
67 contents := `
68 include github.com/tj/foo
69 include github.com/tj/bar
70 include github.com/tj/something/here
71 start:
72 @gopherjs -m -v serve --http :3000 github.com/tj/docs/client
73 .PHONY: start
74 api:
75 @go run server/cmd/api/api.go
76 .PHONY: api
77 deps:
78 @godepgraph github.com/tj/docs/client | dot -Tsvg | browser
79 .PHONY: deps
80 `
81
82 nodes, err := Parse(strings.NewReader(contents))
83 if err != nil {
84 panic(err)
85 }
86
87 for _, node := range nodes {
88 fmt.Printf("%#v\n", node)
89 }
90
91 // Output:
92 // makefile.Include{node:makefile.node{lines:[]int{1}}, Value:"github.com/tj/foo"}
93 // makefile.Include{node:makefile.node{lines:[]int{2}}, Value:"github.com/tj/bar"}
94 // makefile.Include{node:makefile.node{lines:[]int{3}}, Value:"github.com/tj/something/here"}
95 }