Starting to goof around with a Go implementation of Aspen
This commit is contained in:
parent
5d5ada2dfc
commit
bfc7c0cdc6
16
gotime/smplt/Makefile
Normal file
16
gotime/smplt/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
TARGETS = \
|
||||
github.com/meatballhat/box-o-sand/gotime/smplt
|
||||
|
||||
test: build
|
||||
go test -x -v $(TARGETS)
|
||||
|
||||
build: deps
|
||||
go install -x $(TARGETS)
|
||||
|
||||
deps:
|
||||
go get -n -x $(TARGETS)
|
||||
|
||||
clean:
|
||||
go clean -x -i $(TARGETS)
|
||||
|
||||
.PHONY: test build clean fmt
|
35
gotime/smplt/simplate.go
Normal file
35
gotime/smplt/simplate.go
Normal file
@ -0,0 +1,35 @@
|
||||
package smplt
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
SIMPLATE_TYPE_RENDERED = "rendered"
|
||||
SIMPLATE_TYPE_STATIC = "static"
|
||||
SIMPLATE_TYPE_NEGOTIATED = "negotiated"
|
||||
)
|
||||
|
||||
type Simplate struct {
|
||||
Type string
|
||||
}
|
||||
|
||||
func SimplateFromString(filename, content string) *Simplate {
|
||||
nbreaks := strings.Count(content, "")
|
||||
|
||||
s := &Simplate{
|
||||
Type: SIMPLATE_TYPE_STATIC,
|
||||
}
|
||||
|
||||
if nbreaks == 2 {
|
||||
s.Type = SIMPLATE_TYPE_RENDERED
|
||||
return s
|
||||
}
|
||||
|
||||
if nbreaks > 2 {
|
||||
s.Type = SIMPLATE_TYPE_NEGOTIATED
|
||||
return s
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
43
gotime/smplt/smplt_test.go
Normal file
43
gotime/smplt/smplt_test.go
Normal file
@ -0,0 +1,43 @@
|
||||
package smplt_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/meatballhat/box-o-sand/gotime/smplt"
|
||||
)
|
||||
|
||||
const BASIC_RENDERED_TXT_SIMPLATE = `
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Dance struct {
|
||||
Who string
|
||||
When time.Time
|
||||
}
|
||||
|
||||
d := &Dance{
|
||||
Who: "Everybody",
|
||||
When: time.Now(),
|
||||
}
|
||||
|
||||
{{d.Who}} Dance {{d.When}}!
|
||||
`
|
||||
|
||||
const BASIC_STATIC_TXT_SIMPLATE = `
|
||||
Everybody Dance Now!
|
||||
`
|
||||
|
||||
func TestDetectsRenderedSimplate(t *testing.T) {
|
||||
s := SimplateFromString("basic-rendered.txt", BASIC_RENDERED_TXT_SIMPLATE)
|
||||
if s.Type != SIMPLATE_TYPE_RENDERED {
|
||||
t.Errorf("Simplate detected as %s instead of %s", s.Type, SIMPLATE_TYPE_RENDERED)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectsStaticSimplate(t *testing.T) {
|
||||
s := SimplateFromString("basic-static.txt", BASIC_STATIC_TXT_SIMPLATE)
|
||||
if s.Type != SIMPLATE_TYPE_STATIC {
|
||||
t.Errorf("Simplate detected as %s instead of %s", s.Type, SIMPLATE_TYPE_STATIC)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user