Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Android/build/build/blueprint/proptools/   (Android Betriebssystem Version 17©)  Datei vom 26.5.2026 mit Größe 2 kB image not shown  

Quelle  configurable_test.go   Sprache: unbekannt

 
Spracherkennung für: .go vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

package proptools

import (
 "fmt"
 "reflect"
 "testing"
)

func TestPostProcessor(t *testing.T) {
 // Same as the ascii art example in Configurable.evaluate()
 prop := NewConfigurable[[]string](nil, nil)
 prop.AppendSimpleValue([]string{"a"})
 prop.AppendSimpleValue([]string{"b"})
 prop.AddPostProcessor(addToElementsProcessor{"1"})

 prop2 := NewConfigurable[[]string](nil, nil)
 prop2.AppendSimpleValue([]string{"c"})

 prop3 := NewConfigurable[[]string](nil, nil)
 prop3.AppendSimpleValue([]string{"d"})
 prop3.AppendSimpleValue([]string{"e"})
 prop3.AddPostProcessor(addToElementsProcessor{"2"})

 prop4 := NewConfigurable[[]string](nil, nil)
 prop4.AppendSimpleValue([]string{"f"})

 prop5 := NewConfigurable[[]string](nil, nil)
 prop5.AppendSimpleValue([]string{"g"})
 prop5.AddPostProcessor(addToElementsProcessor{"3"})

 prop2.Append(prop3)
 prop2.AddPostProcessor(addToElementsProcessor{"z"})

 prop.Append(prop2)
 prop.AddPostProcessor(addToElementsProcessor{"y"})
 prop.Append(prop4)
 prop.Append(prop5)

 expected := []string{"a1y", "b1y", "czy", "d2zy", "e2zy", "f", "g3"}
 x := prop.Get(&configurableEvalutorForTesting{})
 if !reflect.DeepEqual(x.Get(), expected) {
  t.Fatalf("Expected %v, got %v", expected, x.Get())
 }

 _, err := CalculateHashReflection(prop)
 if err != nil {
  t.Errorf("Error calculating hash of configurable after AddPostProcessor: %s", err.Error())
 }
}

func TestPostProcessorWhenPassedToHelperFunction(t *testing.T) {
 prop := NewConfigurable[[]string](nil, nil)
 prop.AppendSimpleValue([]string{"a"})
 prop.AppendSimpleValue([]string{"b"})

 helper := func(p Configurable[[]string]) {
  p.AddPostProcessor(addToElementsProcessor{"1"})
 }

 helper(prop)

 expected := []string{"a1", "b1"}
 x := prop.Get(&configurableEvalutorForTesting{})
 if !reflect.DeepEqual(x.Get(), expected) {
  t.Fatalf("Expected %v, got %v", expected, x.Get())
 }
}

type addToElementsProcessor struct {
 s string
}

func (p addToElementsProcessor) PostProcess(arr []string) []string {
 for i := range arr {
  arr[i] = arr[i] + p.s
 }
 return arr
}

type configurableEvalutorForTesting struct {
 vars map[string]string
}

func (e *configurableEvalutorForTesting) EvaluateConfiguration(condition ConfigurableCondition, property string) ConfigurableValue {
 if condition.functionName != "f" {
  panic("Expected functionName to be f")
 }
 if len(condition.args) != 1 {
  panic("Expected exactly 1 arg")
 }
 val, ok := e.vars[condition.args[0]]
 if ok {
  return ConfigurableValueString(val)
 }
 return ConfigurableValueUndefined()
}

func (e *configurableEvalutorForTesting) PropertyErrorf(property, fmtString string, args ...interface{}) {
 panic(fmt.Sprintf(fmtString, args...))
}

var _ ConfigurableEvaluator = (*configurableEvalutorForTesting)(nil)

[Dauer der Verarbeitung: 0.20 Sekunden, vorverarbeitet 2026-06-28]