MCPcopy
hub / github.com/google/mangle / TestCollectToMapIntegration

Function TestCollectToMapIntegration

functional/functional_test.go:983–1019  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

981}
982
983func TestCollectToMapIntegration(t *testing.T) {
984 // Test that our new CollectToMap works with the broader function evaluation system
985
986 // Create some test data representing key-value pairs
987 keyVals := []ast.Constant{
988 name("/key1"), ast.Number(100),
989 name("/key2"), ast.Number(200),
990 name("/key3"), ast.Number(300),
991 }
992
993 // Create a map using the Map function
994 mapExpr := ast.ApplyFn{symbols.Map, []ast.BaseTerm{
995 keyVals[0], keyVals[1],
996 keyVals[2], keyVals[3],
997 keyVals[4], keyVals[5],
998 }}
999
1000 result, err := EvalApplyFn(mapExpr, ast.ConstSubstMap{})
1001 if err != nil {
1002 t.Fatalf("Failed to create map: %v", err)
1003 }
1004
1005 if result.Type != ast.MapShape {
1006 t.Errorf("Expected map, got %v", result.Type)
1007 }
1008
1009 // Test that we can look up values in the created map
1010 lookup1 := ast.ApplyFn{symbols.MapGet, []ast.BaseTerm{result, keyVals[0]}}
1011 val1, err := EvalApplyFn(lookup1, ast.ConstSubstMap{})
1012 if err != nil {
1013 t.Fatalf("Failed to lookup key: %v", err)
1014 }
1015
1016 if !val1.Equals(keyVals[1]) {
1017 t.Errorf("Expected %v, got %v", keyVals[1], val1)
1018 }
1019}
1020
1021func TestReducerCollectToMapErrors(t *testing.T) {
1022 tests := []struct {

Callers

nothing calls this directly

Calls 4

NumberFunction · 0.92
EvalApplyFnFunction · 0.85
nameFunction · 0.70
EqualsMethod · 0.65

Tested by

no test coverage detected