feat(comment): add support for: interface methods, struct fields, variables (#123)
* refactor(comment): dont use unnecessary function * chore: quick way to open vim in dev mode * feat(comment): add comment on on interface method * feat(comment): add comment on a struct field * feat(comment): add comment on a variable * docs: add note about the generate function * docs: gopher.TsResult * fix(utils): handle case when indentation is wrong
This commit is contained in:
parent
295e21e637
commit
1e7af1b212
20 changed files with 250 additions and 33 deletions
6
spec/fixtures/comment/interface_many_method_input.go
vendored
Normal file
6
spec/fixtures/comment/interface_many_method_input.go
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package main
|
||||
|
||||
type Testinger interface {
|
||||
Get(id string) int
|
||||
Set(id string, val int)
|
||||
}
|
||||
7
spec/fixtures/comment/interface_many_method_output.go
vendored
Normal file
7
spec/fixtures/comment/interface_many_method_output.go
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
type Testinger interface {
|
||||
Get(id string) int
|
||||
// Set
|
||||
Set(id string, val int)
|
||||
}
|
||||
5
spec/fixtures/comment/interface_method_input.go
vendored
Normal file
5
spec/fixtures/comment/interface_method_input.go
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package main
|
||||
|
||||
type Testinger interface {
|
||||
Method(input string) error
|
||||
}
|
||||
6
spec/fixtures/comment/interface_method_output.go
vendored
Normal file
6
spec/fixtures/comment/interface_method_output.go
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package main
|
||||
|
||||
type Testinger interface {
|
||||
// Method
|
||||
Method(input string) error
|
||||
}
|
||||
18
spec/fixtures/comment/many_structs_fields_input.go
vendored
Normal file
18
spec/fixtures/comment/many_structs_fields_input.go
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
type (
|
||||
TestOne struct {
|
||||
Asdf string
|
||||
ID int
|
||||
}
|
||||
|
||||
TestTwo struct {
|
||||
Fesa int
|
||||
A bool
|
||||
}
|
||||
|
||||
TestThree struct {
|
||||
Asufj int
|
||||
Fs string
|
||||
}
|
||||
)
|
||||
19
spec/fixtures/comment/many_structs_fields_output.go
vendored
Normal file
19
spec/fixtures/comment/many_structs_fields_output.go
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
type (
|
||||
TestOne struct {
|
||||
Asdf string
|
||||
ID int
|
||||
}
|
||||
|
||||
TestTwo struct {
|
||||
// Fesa
|
||||
Fesa int
|
||||
A bool
|
||||
}
|
||||
|
||||
TestThree struct {
|
||||
Asufj int
|
||||
Fs string
|
||||
}
|
||||
)
|
||||
7
spec/fixtures/comment/struct_fields_input.go
vendored
Normal file
7
spec/fixtures/comment/struct_fields_input.go
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
type CommentStruct struct {
|
||||
Name string
|
||||
Address string
|
||||
Aliases []string
|
||||
}
|
||||
8
spec/fixtures/comment/struct_fields_output.go
vendored
Normal file
8
spec/fixtures/comment/struct_fields_output.go
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
type CommentStruct struct {
|
||||
Name string
|
||||
// Address
|
||||
Address string
|
||||
Aliases []string
|
||||
}
|
||||
5
spec/fixtures/comment/svar_input.go
vendored
Normal file
5
spec/fixtures/comment/svar_input.go
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package main
|
||||
|
||||
func varTest() {
|
||||
s := "something"
|
||||
}
|
||||
6
spec/fixtures/comment/svar_output.go
vendored
Normal file
6
spec/fixtures/comment/svar_output.go
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package main
|
||||
|
||||
func varTest() {
|
||||
// s
|
||||
s := "something"
|
||||
}
|
||||
5
spec/fixtures/comment/var_input.go
vendored
Normal file
5
spec/fixtures/comment/var_input.go
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package main
|
||||
|
||||
func test() {
|
||||
var imAVar string
|
||||
}
|
||||
6
spec/fixtures/comment/var_output.go
vendored
Normal file
6
spec/fixtures/comment/var_output.go
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package main
|
||||
|
||||
func test() {
|
||||
// imAVar
|
||||
var imAVar string
|
||||
}
|
||||
8
spec/fixtures/comment/var_struct_fields_input.go
vendored
Normal file
8
spec/fixtures/comment/var_struct_fields_input.go
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
func main() {
|
||||
var s struct {
|
||||
API string
|
||||
Key string
|
||||
}
|
||||
}
|
||||
9
spec/fixtures/comment/var_struct_fields_output.go
vendored
Normal file
9
spec/fixtures/comment/var_struct_fields_output.go
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package main
|
||||
|
||||
func main() {
|
||||
var s struct {
|
||||
API string
|
||||
// Key
|
||||
Key string
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,18 @@ comment["should add comment to struct"] = function()
|
|||
do_the_test("struct", { 4, 1 })
|
||||
end
|
||||
|
||||
comment["should add a comment on struct field"] = function()
|
||||
do_the_test("struct_fields", { 5, 8 })
|
||||
end
|
||||
|
||||
comment["should add a comment on var struct field"] = function()
|
||||
do_the_test("var_struct_fields", { 6, 4 })
|
||||
end
|
||||
|
||||
comment["should add a comment on one field of many structs"] = function()
|
||||
do_the_test("many_structs_fields", { 10, 4 })
|
||||
end
|
||||
|
||||
comment["should add comment to function"] = function()
|
||||
do_the_test("func", { 3, 1 })
|
||||
end
|
||||
|
|
@ -30,6 +42,22 @@ comment["should add comment to interface"] = function()
|
|||
do_the_test("interface", { 3, 6 })
|
||||
end
|
||||
|
||||
comment["should add comment on interface method"] = function()
|
||||
do_the_test("interface_method", { 4, 2 })
|
||||
end
|
||||
|
||||
comment["should add a comment on interface with many method"] = function()
|
||||
do_the_test("interface_many_method", { 5, 2 })
|
||||
end
|
||||
|
||||
comment["should add a comment on a var"] = function()
|
||||
do_the_test("var", { 4, 2 })
|
||||
end
|
||||
|
||||
comment["should add a comment on a short declared var"] = function()
|
||||
do_the_test("svar", { 4, 8 })
|
||||
end
|
||||
|
||||
comment["otherwise should add // above cursor"] = function()
|
||||
do_the_test("empty", { 1, 1 })
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,4 +22,28 @@ utils["should .trimend()"] = function()
|
|||
t.eq(u.trimend " hi ", " hi")
|
||||
end
|
||||
|
||||
utils["should add .indent() spaces"] = function()
|
||||
local u = require "gopher._utils"
|
||||
local line = " func Test() error {"
|
||||
local indent = 4
|
||||
|
||||
t.eq(" ", u.indent(line, indent))
|
||||
end
|
||||
|
||||
utils["should add .indent() a tab"] = function()
|
||||
local u = require "gopher._utils"
|
||||
local line = "\tfunc Test() error {"
|
||||
local indent = 1
|
||||
|
||||
t.eq("\t", u.indent(line, indent))
|
||||
end
|
||||
|
||||
utils["should add .indent() 2 tabs"] = function()
|
||||
local u = require "gopher._utils"
|
||||
local line = "\t\tfunc Test() error {"
|
||||
local indent = 2
|
||||
|
||||
t.eq("\t\t", u.indent(line, indent))
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue