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

Function TestEvalApplyFn

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

Source from the content-addressed store, hash-verified

406}
407
408func TestEvalApplyFn(t *testing.T) {
409 tests := []struct {
410 name string
411 expr ast.ApplyFn
412 want ast.Constant
413 }{
414 {
415 name: "construct a pair",
416 expr: ast.ApplyFn{symbols.Pair, []ast.BaseTerm{ast.String("hello"), ast.Number(2)}},
417 want: *pair(ast.String("hello"), ast.Number(2)),
418 },
419 {
420 name: "construct a tuple, case pair",
421 expr: ast.ApplyFn{symbols.Tuple, []ast.BaseTerm{ast.String("hello"), ast.Number(2)}},
422 want: *pair(ast.String("hello"), ast.Number(2)),
423 },
424 {
425 name: "construct a tuple, case single-element tuple",
426 expr: ast.ApplyFn{symbols.Tuple, []ast.BaseTerm{ast.String("hello")}},
427 want: ast.String("hello"),
428 },
429 {
430 name: "construct a tuple, case more than two elements",
431 expr: ast.ApplyFn{symbols.Tuple, []ast.BaseTerm{ast.String("hello"), ast.Number(2), ast.Number(32)}},
432 want: *pair(ast.String("hello"), *pair(ast.Number(2), ast.Number(32))),
433 },
434 {
435 name: "construct a list",
436 expr: ast.ApplyFn{symbols.List, []ast.BaseTerm{ast.String("hello"), ast.Number(2), ast.Number(32)}},
437 want: ast.List([]ast.Constant{ast.String("hello"), ast.Number(2), ast.Number(32)}),
438 },
439 {
440 name: "get element of list",
441 expr: ast.ApplyFn{symbols.ListGet, []ast.BaseTerm{
442 ast.List([]ast.Constant{ast.String("hello"), ast.Number(2), ast.Number(32)}),
443 ast.Number(2)}},
444 want: ast.Number(32),
445 },
446 {
447 name: "min of number list",
448 expr: ast.ApplyFn{symbols.Min, []ast.BaseTerm{
449 ast.List([]ast.Constant{ast.Number(2), ast.Number(5), ast.Number(32)})}},
450 want: ast.Number(2),
451 },
452 {
453 name: "sum of number list",
454 expr: ast.ApplyFn{symbols.Sum, []ast.BaseTerm{
455 ast.List([]ast.Constant{ast.Number(2), ast.Number(5), ast.Number(32)})}},
456 want: ast.Number(39),
457 },
458 {
459 name: "floatmax of float64 list",
460 expr: ast.ApplyFn{symbols.FloatMax, []ast.BaseTerm{
461 ast.List([]ast.Constant{ast.Float64(2.0), ast.Float64(5.0), ast.Float64(32.0)})}},
462 want: ast.Float64(32.0),
463 },
464 {
465 name: "append element to empty list",

Callers

nothing calls this directly

Calls 12

StringFunction · 0.92
NumberFunction · 0.92
ListFunction · 0.92
Float64Function · 0.92
ListConsFunction · 0.92
MapFunction · 0.92
StructFunction · 0.92
EvalApplyFnFunction · 0.85
pairFunction · 0.70
ptrFunction · 0.70
nameFunction · 0.70
EqualsMethod · 0.65

Tested by

no test coverage detected