Browse Source

Refactored md2gmi.go for testing, added basic test

Signed-off-by: gryffyn <me@neveris.one>
main
gryffyn 5 months ago
parent
commit
8f2e2c52f3
Signed by: gryffyn GPG Key ID: 6948DD6514D02BEF
  1. 6
      .drone.yml
  2. 17
      go.mod
  3. 13
      md2gmi.go
  4. 14
      md2gmi_test.go

6
.drone.yml

@ -4,6 +4,10 @@ type: exec
name: default
steps:
- name: test
commands:
- go test
- name: build
commands:
- go build
@ -26,6 +30,6 @@ trigger:
event: tag
---
kind: signature
hmac: fa155397ecc713ba495922446fe65007f58817e0253288d626aa7114d16d74dd
hmac: fc6332756e4c7f221f840ee6f2e64efe8fd420f23e94fb6de95b5c952fe40ffc
...

17
go.mod

@ -2,4 +2,19 @@ module git.neveris.one/gryffyn/md2gmi
go 1.15
require github.com/alexflint/go-arg v1.3.0
require (
github.com/alexflint/go-arg v1.3.0
github.com/dgraph-io/ristretto v0.0.3 // indirect
github.com/google/uuid v1.1.4 // indirect
github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/mapstructure v1.4.0 // indirect
github.com/ory/go-acc v0.2.6 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/spf13/afero v1.5.1 // indirect
github.com/spf13/cobra v1.1.1 // indirect
golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061 // indirect
golang.org/x/text v0.3.5 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

13
md2gmi.go

@ -22,11 +22,7 @@ func ofile(filename, str string) error {
return err
}
func md2gmi(in, out string) error {
// opens file for writing
md, err := ifile(in)
func md2gmi(md string) string {
// defines regexes and compiles them
reg_html := regexp.MustCompile(`<.+?>.+?<\/.+?>`)
reg_cite := regexp.MustCompile(`\[\^.+?\]\(.+?\)`)
@ -45,7 +41,12 @@ func md2gmi(in, out string) error {
parts := reg_link.FindStringSubmatch(m)
return "\n=> " + parts[2] + " " + parts[1] + "\n"
})
return res
}
func inout(in, out string) error {
md, err := ifile(in)
res := md2gmi(md)
err = ofile(out, res)
return err
}
@ -66,7 +67,7 @@ func main() {
} else if args.Output == "" && !(args.V) {
parse.Fail("You must provide both INPUT and OUTPUT.")
}
err := md2gmi(args.Input, args.Output)
err := inout(args.Input, args.Output)
if err != nil {
panic(err)
}

14
md2gmi_test.go

@ -0,0 +1,14 @@
package main
import (
"strings"
"testing"
)
func TestMd2gmi(t *testing.T) {
testlink := `hello [link](example.com) other stuff`
_testlink := md2gmi(testlink)
if strings.Contains(_testlink, "=>") {
t.Errorf("Failed refactoring links - got: %d", _testlink)
}
}
Loading…
Cancel
Save