MCPcopy Create free account
hub / github.com/dolthub/doltgresql / UnsetVariables

Function UnsetVariables

testing/generation/utils/statement_generator.go:692–726  ·  view source on GitHub ↗

UnsetVariables returns the name of all variables that do not have a definition. Sorted in ascending order.

(gen StatementGenerator)

Source from the content-addressed store, hash-verified

690
691// UnsetVariables returns the name of all variables that do not have a definition. Sorted in ascending order.
692func UnsetVariables(gen StatementGenerator) ([]string, error) {
693 varNames := make(map[string]struct{})
694 switch gen := gen.(type) {
695 case *CollectionGen:
696 for _, child := range gen.children {
697 children, err := UnsetVariables(child)
698 if err != nil {
699 return nil, err
700 }
701 for _, childName := range children {
702 varNames[childName] = struct{}{}
703 }
704 }
705 case *OptionalGen:
706 return UnsetVariables(gen.children)
707 case *OrGen:
708 return UnsetVariables(Collection(gen.children...))
709 case *TextGen:
710 // Nothing to do here
711 case *VariableGen:
712 if gen.options == nil {
713 return []string{gen.name}, nil
714 } else {
715 return UnsetVariables(gen.options)
716 }
717 default:
718 return nil, fmt.Errorf("unknown generator encountered: %T", gen)
719 }
720 var varNamesSlice []string
721 for varName := range varNames {
722 varNamesSlice = append(varNamesSlice, varName)
723 }
724 sort.Strings(varNamesSlice)
725 return varNamesSlice, nil
726}
727
728// copyGenerators returns a full copy of the given slice of generators. Each generator will be in its original state.
729func copyGenerators(gens []StatementGenerator) []StatementGenerator {

Callers 2

Calls 2

CollectionFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected