2023-06-07 12:45:48 +02:00
|
|
|
package bfcodegen
|
|
|
|
|
|
|
|
import (
|
2023-08-14 18:39:22 +02:00
|
|
|
_ "embed"
|
2023-10-31 22:58:28 +01:00
|
|
|
"fmt"
|
2023-08-14 18:39:22 +02:00
|
|
|
"gogs.mikescher.com/BlackForestBytes/goext/cmdext"
|
|
|
|
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
|
|
|
"gogs.mikescher.com/BlackForestBytes/goext/tst"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2023-06-07 12:45:48 +02:00
|
|
|
"testing"
|
2023-08-14 18:39:22 +02:00
|
|
|
"time"
|
2023-06-07 12:45:48 +02:00
|
|
|
)
|
|
|
|
|
2023-12-07 17:57:06 +01:00
|
|
|
//go:embed _test_example_1.tgz
|
|
|
|
var EnumExampleModels1 []byte
|
|
|
|
|
|
|
|
//go:embed _test_example_2.tgz
|
|
|
|
var EnumExampleModels2 []byte
|
2023-06-07 12:45:48 +02:00
|
|
|
|
2023-08-14 18:39:22 +02:00
|
|
|
func TestGenerateEnumSpecs(t *testing.T) {
|
|
|
|
|
|
|
|
tmpFile := filepath.Join(t.TempDir(), langext.MustHexUUID()+".tgz")
|
|
|
|
|
|
|
|
tmpDir := filepath.Join(t.TempDir(), langext.MustHexUUID())
|
|
|
|
|
2023-12-07 17:57:06 +01:00
|
|
|
err := os.WriteFile(tmpFile, EnumExampleModels1, 0o777)
|
2023-08-14 18:39:22 +02:00
|
|
|
tst.AssertNoErr(t, err)
|
|
|
|
|
|
|
|
t.Cleanup(func() { _ = os.Remove(tmpFile) })
|
|
|
|
|
|
|
|
err = os.Mkdir(tmpDir, 0o777)
|
|
|
|
tst.AssertNoErr(t, err)
|
|
|
|
|
|
|
|
t.Cleanup(func() { _ = os.RemoveAll(tmpFile) })
|
|
|
|
|
|
|
|
_, err = cmdext.Runner("tar").Arg("-xvzf").Arg(tmpFile).Arg("-C").Arg(tmpDir).FailOnExitCode().FailOnTimeout().Timeout(time.Minute).Run()
|
|
|
|
tst.AssertNoErr(t, err)
|
|
|
|
|
2024-03-10 12:49:31 +01:00
|
|
|
s1, cs1, _, err := _generateEnumSpecs(tmpDir, "", "N/A", true, true)
|
2023-12-07 17:57:06 +01:00
|
|
|
tst.AssertNoErr(t, err)
|
|
|
|
|
2024-03-10 12:49:31 +01:00
|
|
|
s2, cs2, _, err := _generateEnumSpecs(tmpDir, "", "N/A", true, true)
|
2023-12-07 17:57:06 +01:00
|
|
|
tst.AssertNoErr(t, err)
|
|
|
|
|
|
|
|
tst.AssertEqual(t, cs1, cs2)
|
|
|
|
tst.AssertEqual(t, s1, s2)
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("=====================================================================================================")
|
|
|
|
fmt.Println(s1)
|
|
|
|
fmt.Println("=====================================================================================================")
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenerateEnumSpecsData(t *testing.T) {
|
|
|
|
|
|
|
|
tmpFile := filepath.Join(t.TempDir(), langext.MustHexUUID()+".tgz")
|
|
|
|
|
|
|
|
tmpDir := filepath.Join(t.TempDir(), langext.MustHexUUID())
|
|
|
|
|
|
|
|
err := os.WriteFile(tmpFile, EnumExampleModels2, 0o777)
|
|
|
|
tst.AssertNoErr(t, err)
|
|
|
|
|
|
|
|
t.Cleanup(func() { _ = os.Remove(tmpFile) })
|
|
|
|
|
|
|
|
err = os.Mkdir(tmpDir, 0o777)
|
|
|
|
tst.AssertNoErr(t, err)
|
|
|
|
|
|
|
|
t.Cleanup(func() { _ = os.RemoveAll(tmpFile) })
|
|
|
|
|
|
|
|
_, err = cmdext.Runner("tar").Arg("-xvzf").Arg(tmpFile).Arg("-C").Arg(tmpDir).FailOnExitCode().FailOnTimeout().Timeout(time.Minute).Run()
|
2023-08-14 18:39:22 +02:00
|
|
|
tst.AssertNoErr(t, err)
|
|
|
|
|
2024-03-10 12:49:31 +01:00
|
|
|
s1, _, _, err := _generateEnumSpecs(tmpDir, "", "", true, true)
|
2023-08-14 18:39:22 +02:00
|
|
|
tst.AssertNoErr(t, err)
|
2023-06-07 12:45:48 +02:00
|
|
|
|
2023-10-31 22:58:28 +01:00
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("=====================================================================================================")
|
2023-12-07 17:57:06 +01:00
|
|
|
fmt.Println(s1)
|
2023-10-31 22:58:28 +01:00
|
|
|
fmt.Println("=====================================================================================================")
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println()
|
2023-06-07 12:45:48 +02:00
|
|
|
}
|