Добавлена поддержка маппинга выражений с правой стороны знака равно и arduino.A0 в частности

Этот коммит содержится в:
Softonik 2021-10-03 23:17:29 +03:00 коммит произвёл Nobody
родитель 7f10cf1cba
коммит b5f6d61dde
3 изменённых файлов: 71 добавлений и 0 удалений

Просмотреть файл

@ -58,4 +58,12 @@ var mapping = map[string]string{
"wifi.StatusScanCompleted": "WL_SCAN_COMPLETED", "wifi.StatusScanCompleted": "WL_SCAN_COMPLETED",
"Loop": "void loop", "Loop": "void loop",
"Setup": "void setup", "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",
} }

Просмотреть файл

@ -439,6 +439,8 @@ func handleValueSpecValues(values []ast.Expr) string {
switch v := value.(type) { switch v := value.(type) {
case *ast.BasicLit: case *ast.BasicLit:
code += handleBasicLit(v) code += handleBasicLit(v)
case *ast.SelectorExpr:
code += handleSelectorExpr(value)
} }
} }
return code return code

Просмотреть файл

@ -5,6 +5,7 @@ import (
"strings" "strings"
"testing" "testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
@ -32,6 +33,17 @@ func Validate(source, expected string, t *testing.T) {
ExpectWithOffset(1, tgot).To(Be(texpected)) 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) { func Test_Empty_Package(t *testing.T) {
source := `package test` source := `package test`
expected := `void loop(){} expected := `void loop(){}
@ -480,4 +492,53 @@ func Test_WiFiWebClient(t *testing.T) {
Validate(source, expected, 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 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)
})
})
})