aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--jbo/namcu/doc.go2
-rw-r--r--jbo/namcu/namcu.go45
-rw-r--r--jbo/namcu/namcu_test.go36
-rw-r--r--xcontext/time.go25
6 files changed, 114 insertions, 0 deletions
diff --git a/go.mod b/go.mod
index 55fe2f5..0c28d27 100644
--- a/go.mod
+++ b/go.mod
@@ -51,6 +51,8 @@ require (
github.com/kr/pretty v0.1.0
github.com/layeh/gopher-luar v1.0.4
github.com/mitchellh/mapstructure v1.1.2 // indirect
+ github.com/mndrix/golog v0.0.0-20170330170653-a28e2a269775
+ github.com/mndrix/ps v0.0.0-20170330174427-18e65badd6ab // indirect
github.com/olekukonko/tablewriter v0.0.0-20180912035003-be2c049b30cc // indirect
github.com/otm/gluaflag v0.0.0-20160113203828-078088de6891
github.com/otm/gluash v0.0.0-20151226163409-e145c563986f
diff --git a/go.sum b/go.sum
index 86b55ca..5236294 100644
--- a/go.sum
+++ b/go.sum
@@ -140,6 +140,10 @@ github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp
github.com/microcosm-cc/bluemonday v1.0.0/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
+github.com/mndrix/golog v0.0.0-20170330170653-a28e2a269775 h1:KPqf9x/eMg3ZnHATLXcM1OgQMNVkPUv1QcGv6zTRMRg=
+github.com/mndrix/golog v0.0.0-20170330170653-a28e2a269775/go.mod h1:Q4YHYl483MNk6wwg3g8YsINpKe5S2UzUJCRSRlFaSU0=
+github.com/mndrix/ps v0.0.0-20170330174427-18e65badd6ab h1:fPrYMvMnWuED0MLhLyrny1fLaHhtiXK30pNyBGrk9Gs=
+github.com/mndrix/ps v0.0.0-20170330174427-18e65badd6ab/go.mod h1:dHgTaDInzkAqJv67VaX1IkK449M2UoBY68CZeI/bNCU=
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
github.com/olekukonko/tablewriter v0.0.0-20180912035003-be2c049b30cc h1:rQ1O4ZLYR2xXHXgBCCfIIGnuZ0lidMQw2S5n1oOv+Wg=
diff --git a/jbo/namcu/doc.go b/jbo/namcu/doc.go
new file mode 100644
index 0000000..56123e8
--- /dev/null
+++ b/jbo/namcu/doc.go
@@ -0,0 +1,2 @@
+// Package namcu allows for the convenient encoding and decoding of lojban numbers.
+package namcu
diff --git a/jbo/namcu/namcu.go b/jbo/namcu/namcu.go
new file mode 100644
index 0000000..7742dde
--- /dev/null
+++ b/jbo/namcu/namcu.go
@@ -0,0 +1,45 @@
+package namcu
+
+// Digits
+const (
+ Zero = "no"
+ One = "pa"
+ Two = "re"
+ Three = "ci"
+ Four = "vo"
+ Five = "mu"
+ Six = "xa"
+ Seven = "ze"
+ Eight = "bi"
+ Nine = "so"
+)
+
+func lojbanDigit(i int) string {
+ switch i {
+ case 0:
+ return Zero
+ case 1:
+ return One
+ case 2:
+ return Two
+ case 3:
+ return Three
+ case 4:
+ return Four
+ case 5:
+ return Five
+ case 6:
+ return Six
+ case 7:
+ return Seven
+ case 8:
+ return Eight
+ case 9:
+ return Nine
+ default:
+ rem := i % 10
+ iter := i / 10
+
+ return lojbanDigit(iter) + lojbanDigit(rem)
+ }
+}
diff --git a/jbo/namcu/namcu_test.go b/jbo/namcu/namcu_test.go
new file mode 100644
index 0000000..c4d4138
--- /dev/null
+++ b/jbo/namcu/namcu_test.go
@@ -0,0 +1,36 @@
+package namcu
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestLojbanDigit(t *testing.T) {
+ cases := []struct {
+ input int
+ output string
+ }{
+ {
+ input: 1,
+ output: "pa",
+ },
+ {
+ input: 10,
+ output: "pano",
+ },
+ {
+ input: 1337,
+ output: "pacicize",
+ },
+ }
+
+ for _, cs := range cases {
+ t.Run(fmt.Sprint(cs), func(t *testing.T) {
+ result := lojbanDigit(cs.input)
+
+ if result != cs.output {
+ t.Errorf("expected %[1]d -> %[2]q, got: %[1]d -> %[3]q", cs.input, cs.output, result)
+ }
+ })
+ }
+}
diff --git a/xcontext/time.go b/xcontext/time.go
new file mode 100644
index 0000000..d01b410
--- /dev/null
+++ b/xcontext/time.go
@@ -0,0 +1,25 @@
+package xcontext
+
+import (
+ "context"
+ "time"
+)
+
+type ctxKey int
+
+const timeKkey ctxKey = iota
+
+// WithTime stores a mock time in a context for testing timeouts and other operations.
+func WithTime(ctx context.Context, t time.Time) context.Context {
+ return context.WithValue(ctx, timeKey, t)
+}
+
+func TimeFuncFrom(ctx context.Context) func() time.Time {
+ t, ok := ctx.Value(timeKey).(time.Time)
+
+ if !ok {
+ return time.Now
+ }
+
+ return func() time.Time { return t }
+}