aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <mattn.jp@gmail.com>2020-01-23 12:16:30 +0900
committerYasuhiro Matsumoto <mattn.jp@gmail.com>2020-01-23 12:16:30 +0900
commit670b6a9aa93ca98e45c15ddd1a4590aabc4a635b (patch)
tree9609dbc331edc0ee6c9f05faf82fe3d075c4aa2c
parentfbb650c33bd1dd791cc2e79b5b034301b7abbbe3 (diff)
downloadvim-sonictemplate-670b6a9aa93ca98e45c15ddd1a4590aabc4a635b.tar.gz
vim-sonictemplate-670b6a9aa93ca98e45c15ddd1a4590aabc4a635b.tar.bz2
vim-sonictemplate-670b6a9aa93ca98e45c15ddd1a4590aabc4a635b.zip
Add some templates
-rw-r--r--template/go/base-test-bench.go13
-rw-r--r--template/go/snip-abs.go6
-rw-r--r--template/go/snip-benchmark-case.go5
-rw-r--r--template/go/snip-max-slice.go9
-rw-r--r--template/go/snip-max-two.go6
-rw-r--r--template/go/snip-min-slice.go9
-rw-r--r--template/go/snip-min-two.go6
7 files changed, 54 insertions, 0 deletions
diff --git a/template/go/base-test-bench.go b/template/go/base-test-bench.go
new file mode 100644
index 0000000..0960dc8
--- /dev/null
+++ b/template/go/base-test-bench.go
@@ -0,0 +1,13 @@
+package {{_expr_:substitute('{{_name_}}', '_test', '', '')}}
+
+import (
+ "testing"
+)
+
+func BenchmarkSimple(b *testing.B) {
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ {{_cursor_}}
+ }
+}
+{{_filter_:benchmark}}
diff --git a/template/go/snip-abs.go b/template/go/snip-abs.go
new file mode 100644
index 0000000..63f75a2
--- /dev/null
+++ b/template/go/snip-abs.go
@@ -0,0 +1,6 @@
+func abs(v {{_input_:type}}) {{_input_:type}} {
+ if v < 0 {
+ return -v
+ }
+ return v
+}
diff --git a/template/go/snip-benchmark-case.go b/template/go/snip-benchmark-case.go
new file mode 100644
index 0000000..da08f29
--- /dev/null
+++ b/template/go/snip-benchmark-case.go
@@ -0,0 +1,5 @@
+func Benchmark{{_cursor_}}(b *testing.B) {
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ }
+}
diff --git a/template/go/snip-max-slice.go b/template/go/snip-max-slice.go
new file mode 100644
index 0000000..4a022ba
--- /dev/null
+++ b/template/go/snip-max-slice.go
@@ -0,0 +1,9 @@
+func max(a []{{_input_:type}}) {{_input_:type}} {
+ m := a[0]
+ for _, v := range a {
+ if v > m {
+ m = v
+ }
+ }
+ return m
+}
diff --git a/template/go/snip-max-two.go b/template/go/snip-max-two.go
new file mode 100644
index 0000000..3fc716c
--- /dev/null
+++ b/template/go/snip-max-two.go
@@ -0,0 +1,6 @@
+func max(a, b {{_input_:type}}) {{_input_:type}} {
+ if a > b {
+ return a
+ }
+ return b
+}
diff --git a/template/go/snip-min-slice.go b/template/go/snip-min-slice.go
new file mode 100644
index 0000000..733bcdc
--- /dev/null
+++ b/template/go/snip-min-slice.go
@@ -0,0 +1,9 @@
+func min(a []{{_input_:type}}) {{_input_:type}} {
+ m := a[0]
+ for _, v := range a {
+ if v < m {
+ m = v
+ }
+ }
+ return m
+}
diff --git a/template/go/snip-min-two.go b/template/go/snip-min-two.go
new file mode 100644
index 0000000..29f8d48
--- /dev/null
+++ b/template/go/snip-min-two.go
@@ -0,0 +1,6 @@
+func min(a, b {{_input_:type}}) {{_input_:type}} {
+ if a < b {
+ return a
+ }
+ return b
+}