ResetDSL resets the global expression state for testing and initializes a default API. This function should be called before running any DSL that modifies the global Root or GeneratedResultTypes variables. Usage in tests: func TestMyDSL(t *testing.T) { // Option 1: Use expr.RunDSL which call
(t *testing.T)
| 87 | // Note: RunDSL and RunInvalidDSL automatically call ResetDSL, so you |
| 88 | // only need to call it manually when executing DSL code directly. |
| 89 | func ResetDSL(t *testing.T) { |
| 90 | t.Helper() |
| 91 | // reset all roots and codegen data structures |
| 92 | eval.Reset() |
| 93 | Root = new(RootExpr) |
| 94 | GeneratedResultTypes = new(ResultTypesRoot) |
| 95 | require.NoError(t, eval.Register(Root)) |
| 96 | require.NoError(t, eval.Register(GeneratedResultTypes)) |
| 97 | |
| 98 | // Initialize default API for DSL execution |
| 99 | Root.API = NewAPIExpr("test api", func() {}) |
| 100 | Root.API.Servers = []*ServerExpr{Root.API.DefaultServer()} |
| 101 | } |
no test coverage detected