diff --git a/transpile/mapping.go b/transpile/mapping.go index 8b3dc7a..d3200c5 100644 --- a/transpile/mapping.go +++ b/transpile/mapping.go @@ -58,4 +58,12 @@ var mapping = map[string]string{ "wifi.StatusScanCompleted": "WL_SCAN_COMPLETED", "Loop": "void loop", "Setup": "void setup", + "arduino.A0": "A0", + "arduino.A1": "A1", + "arduino.A2": "A2", + "arduino.A3": "A3", + "arduino.A4": "A4", + "arduino.A5": "A5", + "arduino.A6": "A6", + "arduino.A7": "A7", } diff --git a/transpile/service.go b/transpile/service.go index a316c7e..f195af9 100644 --- a/transpile/service.go +++ b/transpile/service.go @@ -439,6 +439,8 @@ func handleValueSpecValues(values []ast.Expr) string { switch v := value.(type) { case *ast.BasicLit: code += handleBasicLit(v) + case *ast.SelectorExpr: + code += handleSelectorExpr(value) } } return code diff --git a/transpile/service_test.go b/transpile/service_test.go index 0c48a80..c1292e8 100644 --- a/transpile/service_test.go +++ b/transpile/service_test.go @@ -5,6 +5,7 @@ import ( "strings" "testing" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -32,6 +33,17 @@ func Validate(source, expected string, t *testing.T) { ExpectWithOffset(1, tgot).To(Be(texpected)) } +func Compare(source, expected string) { + var in, out bytes.Buffer + in.WriteString(source) + service := NewService(&in, &out) + err := service.Start() + got := out.String() + tgot, texpected := Trim(got), Trim(expected) + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + ExpectWithOffset(1, tgot).To(Be(texpected)) +} + func Test_Empty_Package(t *testing.T) { source := `package test` expected := `void loop(){} @@ -480,4 +492,53 @@ func Test_WiFiWebClient(t *testing.T) { Validate(source, expected, t) } +func TestUtils(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Go Translator") +} + +func NDescribe(s string, i func()) int { return 0 } +func NIt(s string, i func()) int { return 0 } +func NIt_async(s string, i func(done Done), timeout float64) int { return 0 } + var Be = Equal + +func BeCalled(called bool) { + ExpectWithOffset(1, called).To(BeTrue()) +} + +func NoErr(err error) { + ExpectWithOffset(1, err).NotTo(HaveOccurred()) +} + +var Ok = NoErr + +func ErrBe(err error, must error) { + if must != nil { + Ω(err).To(Be(must)) + } else { + Ω(err).To(BeNil()) + } +} + +func ToBeTrue(arg bool) { + Ω(arg).To(BeTrue()) +} + +var _ = Describe("Go Translator", func() { + Describe("Arduino", func() { + It("Maps constants", func() { + source := `package test + var analogInPin int = arduino.A0 + func Setup() error {} + func Loop() error {} + ` + expected := ` + int analogInPin = A0; + void setup() {} + void loop() {} + ` + Compare(source, expected) + }) + }) +})