Add initial filds to the builder

This commit is contained in:
2022-12-29 20:05:50 +01:00
parent c2c95ea130
commit 57bb9ba17c
8 changed files with 298 additions and 1 deletions

9
pkg/types/omp/bpc.go Normal file
View File

@ -0,0 +1,9 @@
package omp
type BPC struct {
}
func (s BPC) Init() {
}

20
pkg/types/omp/header.go Normal file
View File

@ -0,0 +1,20 @@
package omp
type Header struct {
Data []byte
}
func (h *Header) Init() {
h.Data = []byte(`; OM File Header - Saved 2022/12/29 14:43:16
; (6.19 :patc (om-make-point 10 10) (om-make-point 50 50) (om-make-point 500 400) "" 183 0 "2022/12/29 14:43:16" "2022/12/29 14:43:16")
; End File Header
`)
}
func (h *Header) GetData() []byte {
return h.Data
}
func (h *Header) DataToString() string {
return string(h.Data)
}

View File

@ -0,0 +1,21 @@
package omp_test
import (
"goids/pkg/types/omp"
"testing"
)
const headerExample = `; OM File Header - Saved 2022/12/29 14:43:16
; (6.19 :patc (om-make-point 10 10) (om-make-point 50 50) (om-make-point 500 400) "" 183 0 "2022/12/29 14:43:16" "2022/12/29 14:43:16")
; End File Header
`
func TestAbs(t *testing.T) {
header := &omp.Header{}
header.Init()
str := header.DataToString()
if str != headerExample {
t.Errorf("Header is wrong\nwant:\n%s \n\ngot \n%s", headerExample, str)
}
}

37
pkg/types/omp/omp.go Normal file
View File

@ -0,0 +1,37 @@
package omp
import "bytes"
type OMP struct {
Header Header
Data Data
}
func (s OMP) Build() []byte {
buff := bytes.NewBufferString("")
buff.Write(s.Header.GetData())
buff.Write(s.Data.GetIntro())
buff.Write(s.Data.GetLibFor())
return buff.Bytes()
}
type Data struct {
Intro []byte
LibFor []byte
}
func (s *Data) GetIntro() []byte {
return s.Intro
}
func (s *Data) SetIntro() {
s.Intro = []byte("(in-package :om)")
}
func (s *Data) GetLibFor() []byte {
return s.LibFor
}
func (s *Data) SetLibFor() {
s.LibFor = []byte("(load-lib-for (quote nil))")
}

23
pkg/types/omp/omp_test.go Normal file
View File

@ -0,0 +1,23 @@
package omp_test
import (
"goids/pkg/types/omp"
"testing"
)
const ompExample = `; OM File Header - Saved 2022/12/29 14:43:16
; (6.19 :patc (om-make-point 10 10) (om-make-point 50 50) (om-make-point 500 400) "" 183 0 "2022/12/29 14:43:16" "2022/12/29 14:43:16")
; End File Header
(in-package :om)(load-lib-for (quote nil))`
func TestOmpBuilder(t *testing.T) {
header := &omp.OMP{}
header.Data.SetIntro()
header.Data.SetLibFor()
header.Header.Init()
str := string(header.Build())
if str != ompExample {
t.Errorf("Header is wrong\nwant:\n%s \n\ngot \n%s", ompExample, str)
}
}