still testing

This commit is contained in:
Jeff Carr 2025-01-10 23:55:12 -06:00
parent f3297022a8
commit 51a326c5d7
4 changed files with 40 additions and 18 deletions

View File

@ -1,6 +1,8 @@
VERSION = $(shell git describe --tags) VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M) BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
hmm: test
simple: build simple: build
# make -C example clean simpleMutexGlobal goimports vet # make -C example clean simpleMutexGlobal goimports vet
make -C example clean simpleMutexProtoc goimports vet make -C example clean simpleMutexProtoc goimports vet
@ -40,8 +42,8 @@ auto:
# rm -f auto.sort.pb.go auto.newsort.pb.go # auto.marshal.pb.go # rm -f auto.sort.pb.go auto.newsort.pb.go # auto.marshal.pb.go
test: test:
make -C example rawproto
make -C example modproto make -C example modproto
make -C example rawproto
junk: junk:
cd example; rm -f go.* *.pb.go cd example; rm -f go.* *.pb.go

View File

@ -29,13 +29,16 @@ func main() {
fruit := &Fruit{ fruit := &Fruit{
Brand: "mom", Brand: "mom",
City: "New NewYork", City: "New NewYork",
UPC: "2000",
} }
testAppend(fruit) testAppend(fruit)
appendByUPC(fruit) appendByUPC()
}
if err := pb.saveBasket(); err != nil {
badExit(err)
} }
if pb == nil { if pb == nil {
log.Info("This should not have happened") badExit(fmt.Errorf("pb == nil This should not have happened"))
os.Exit(-1)
} }
pb.printTable() pb.printTable()
pb.addThings() pb.addThings()
@ -44,6 +47,11 @@ func main() {
pb.sortTable(100) pb.sortTable(100)
} }
func badExit(err error) {
log.Info("autogenpb error:", err)
os.Exit(-1)
}
/* /*
x := new(Fruit) x := new(Fruit)
x = &Fruit{ x = &Fruit{
@ -112,8 +120,7 @@ func (pb *Fruits) addThings() {
if pb.AppendUniqueByBrand(tmp) { if pb.AppendUniqueByBrand(tmp) {
// log.Printf("AppendUniqueBrand() ok len=%s %s %d\n", tmp.Brand, tmp.City, pb.Len()) // log.Printf("AppendUniqueBrand() ok len=%s %s %d\n", tmp.Brand, tmp.City, pb.Len())
} else { } else {
log.Printf("AppendUniqueByBrand() ERROR len=%s %s %d\n", tmp.Brand, tmp.City, pb.Len()) badExit(fmt.Errorf("AppendUniqueByBrand() ERROR len=%s %s %d\n", tmp.Brand, tmp.City, pb.Len()))
os.Exit(-1)
} }
pb.Append(tmp) pb.Append(tmp)
added += 1 added += 1
@ -127,27 +134,27 @@ func testAppend(fruit *Fruit) {
if pb.AppendUnique(fruit) { if pb.AppendUnique(fruit) {
log.Info("AppendUnique() test1 ok", fruit.Brand, fruit.City) log.Info("AppendUnique() test1 ok", fruit.Brand, fruit.City)
} else { } else {
log.Info("AppendUnique() test1 failed", fruit.Brand, fruit.City) badExit(fmt.Errorf("AppendUnique test1 failed %s %s %d\n", fruit.Brand, fruit.City, pb.Len()))
os.Exit(-1)
} }
if pb.AppendUnique(fruit) { if pb.AppendUnique(fruit) {
log.Info("AppendUnique() test2 worked but should not have", fruit.Brand, fruit.City) badExit(fmt.Errorf("AppendUnique() test2 worked but should not have %s %s", fruit.Brand, fruit.City))
os.Exit(-1)
} else { } else {
log.Info("AppendUnique() test2 failed ok", fruit.Brand, fruit.City) log.Info("AppendUnique() test2 failed ok", fruit.Brand, fruit.City)
} }
} }
func appendByUPC(fruit *Fruit) { func appendByUPC() {
if pb.AppendUniqueUPC(fruit) { fruit := new(Fruit)
fruit.UPC = "blah331"
fruit.City = "fry"
fruit.City = "paris"
if pb.AppendUniqueByUPC(fruit) {
log.Info("AppendUnique() test1 ok", fruit.Brand, fruit.City) log.Info("AppendUnique() test1 ok", fruit.Brand, fruit.City)
} else { } else {
log.Info("AppendUnique() test1 failed", fruit.Brand, fruit.City) badExit(fmt.Errorf("AppendUniqueByUPC test1 failed %s %s %d\n", fruit.Brand, fruit.City, pb.Len()))
os.Exit(-1)
} }
if pb.AppendUniqueUPC(fruit) { if pb.AppendUniqueByUPC(fruit) {
log.Info("AppendUnique() test2 worked but should not have", fruit.Brand, fruit.City) badExit(fmt.Errorf("AppendUniqueByUPC() test2 worked but should not have %s %s", fruit.Brand, fruit.City))
os.Exit(-1)
} else { } else {
log.Info("AppendUnique() test2 failed ok", fruit.Brand, fruit.City) log.Info("AppendUnique() test2 failed ok", fruit.Brand, fruit.City)
} }

12
sort.go
View File

@ -47,6 +47,8 @@ func (pb *Files) makeNewSortfile(pf *File) error {
pf.findFunc(wFind) pf.findFunc(wFind)
*/ */
pf.specialBases(wSort, wFind)
// attempt to add sort functions for pf.Base // attempt to add sort functions for pf.Base
if err := pf.processMessage(pf.Bases, wSort, wFind); err != nil { if err := pf.processMessage(pf.Bases, wSort, wFind); err != nil {
return err return err
@ -57,6 +59,15 @@ func (pb *Files) makeNewSortfile(pf *File) error {
return nil return nil
} }
func (pf *File) specialBases(wSort, wFind io.Writer) {
var FRUIT string = cases.Title(language.English, cases.NoLower).String(pf.Bases.Name)
var APPLES string = cases.Title(language.English, cases.NoLower).String(pf.Bases.Name)
var APPLE string = cases.Title(language.English, cases.NoLower).String(pf.Base.Name)
pf.Bases.simpleAppend(wFind, FRUIT, APPLES, APPLE)
}
// to simplify being able to read the code, FRUIT, APPLES and APPLE are used // to simplify being able to read the code, FRUIT, APPLES and APPLE are used
// FRUIT == the string name of the message in the protobuf file // FRUIT == the string name of the message in the protobuf file
// APPLE == the type of the repeated variable // APPLE == the type of the repeated variable
@ -93,7 +104,6 @@ func (pf *File) processMessage(msg *MsgName, wSort, wFind io.Writer) error {
log.Printf("FOUND: %s %s for %s\n", APPLES, APPLE, FRUIT) log.Printf("FOUND: %s %s for %s\n", APPLES, APPLE, FRUIT)
found.simpleAppend(wFind, FRUIT, APPLES, APPLE)
found.addAppendByMsg(wFind, FRUIT, APPLES, APPLE) found.addAppendByMsg(wFind, FRUIT, APPLES, APPLE)
found.addDeleteByMsg(wFind, FRUIT, APPLES, APPLE) found.addDeleteByMsg(wFind, FRUIT, APPLES, APPLE)
found.addInsertByMsg(wFind, FRUIT, APPLES, APPLE) // new idea found.addInsertByMsg(wFind, FRUIT, APPLES, APPLE) // new idea

View File

@ -3,6 +3,8 @@ package main
import ( import (
"fmt" "fmt"
"io" "io"
"go.wit.com/log"
) )
func (msg *MsgName) getLockname(s string) string { func (msg *MsgName) getLockname(s string) string {
@ -18,6 +20,7 @@ func (msg *MsgName) getLockname(s string) string {
func (msg *MsgName) simpleAppend(w io.Writer, FRUIT, APPLES, APPLE string) { func (msg *MsgName) simpleAppend(w io.Writer, FRUIT, APPLES, APPLE string) {
LOCK := msg.getLockname("x") LOCK := msg.getLockname("x")
log.Printf("\t\t(x %s) APPEND(%s)\n", FRUIT, APPLE)
// append -- no check at all // append -- no check at all
fmt.Fprintln(w, "// TESTING 2") fmt.Fprintln(w, "// TESTING 2")
fmt.Fprintln(w, "// just a simple Append() shortcut (but still uses the mutex lock)") fmt.Fprintln(w, "// just a simple Append() shortcut (but still uses the mutex lock)")