Skip to content

Commit

Permalink
Document all macros, remove unsupported tests. (google#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
JimLarson authored Jan 13, 2020
1 parent ccff5b8 commit 9cd7432
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
11 changes: 11 additions & 0 deletions doc/langdef.md
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,17 @@ macros are:
if the predicate of exactly one element/key evaluates to `true`, and the
rest to `false`. Any other combination of boolean results evaluates to
`false`, and any predicate error causes the macro to raise an error.
* `e.map(x, t)` transforms a list `e` by taking each element `x` to the
element given by the expression `t`, which can use the variable `x`. For
instance, `[1, 2, 3].map(n, n * n)` evaluates to `[1, 4, 9]`. Any
evaluation error for any element causes the macro to raise an error. The
`map()` macro is not supported when `e` is a map.
* `e.filter(x, p)` returns the sublist of all elements `x` of list `e` which
evaluate to `true` in the predicate expression `p` (which can use variable
`x`). For instance, `[1, 2, 3].filter(i, i % 2 > 0)` evaluates to `[1, 3]`.
If no elements evaluate to `true`, the result is an empty list. Any
evaluation error for any element causes the macro to raise an error. The
`filter()` macro is not supported on maps.

### Field Selection

Expand Down
21 changes: 2 additions & 19 deletions tests/simple/testdata/macros.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,7 @@ section {
errors: { message: "divide by zero" }
}
}
test {
name: "map_many"
expr: "{1: 1, 2: 4, 3: 9}.map(x, x * x)"
value: { list_value {
values: { int64_value: 1 }
values: { int64_value: 4 }
values: { int64_value: 9 }
}
}
}
# The map() macro is currently not supported for maps.
}
section {
name: "filter"
Expand Down Expand Up @@ -270,13 +261,5 @@ section {
errors: { message: "divide by zero" }
}
}
test {
name: "map_some"
expr: "{0: 10, 1: 11, 2: 12, 3: 13, 4: 14}.filter(x, x % 2 == 1)"
value: { list_value {
values: { int64_value: 1 }
values: { int64_value: 3 }
}
}
}
# The filter() macro is currently not supported for maps.
}

0 comments on commit 9cd7432

Please sign in to comment.