Commit 20fd7057 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

update all test cases to the new syntax

parent c8daa4d8
Loading
Loading
Loading
Loading
+20 −51
Original line number Diff line number Diff line
@@ -139,39 +139,28 @@ ReturnCode color_map_read_gradient(
    const Context* ctx,
    const Expr* expr,
    ColorMap* color_map) {
  std::vector<std::pair<double, Color>> gradient;
  auto args = expr_collect(expr);

  for (; expr; expr = expr_next(expr)) {
    if (!expr_is_list(expr)) {
      return errorf(
          ERROR,
          "invalid argument to 'gradient'; expected a 2-tuple, but got: '{}'",
          expr_inspect(expr));
    }

    auto args = expr_collect(expr_get_list(expr));
    if (args.size() != 2) {
  if (args.size() % 2 != 0) {
      return errorf(
          ERROR,
          "invalid argument to 'gradient'; expected a 2-tuple, but got: '{}'",
          "invalid argument to 'gradient'; not a list of pairs: '{}'",
          expr_inspect(expr));
  }

  std::vector<std::pair<double, Color>> gradient;
  for (size_t i = 0; i + 1 < args.size(); i += 2) {
    double step;
    if (auto rc = expr_to_ratio(args[0], &step); !rc) {
    if (auto rc = expr_to_ratio(args[i], &step); !rc) {
      return rc;
    }

    Color color;
    if (auto rc = color_read(ctx, args[1], &color); !rc) {
    if (auto rc = color_read(ctx, args[i + 1], &color); !rc) {
      return rc;
    }

    gradient.emplace_back(step, color);

    if (!expr_has_next(expr)) {
      break;
    }
  }

  *color_map = color_map_gradient(gradient);
@@ -182,39 +171,28 @@ ReturnCode color_map_read_steps(
    const Context* ctx,
    const Expr* expr,
    ColorMap* color_map) {
  std::vector<std::pair<double, Color>> steps;

  for (; expr; expr = expr_next(expr)) {
    if (!expr_is_list(expr)) {
      return errorf(
          ERROR,
          "invalid argument to 'steps'; expected a 2-tuple, but got: '{}'",
          expr_inspect(expr));
    }
  auto args = expr_collect(expr);

    auto args = expr_collect(expr_get_list(expr));
    if (args.size() != 2) {
  if (args.size() % 2 != 0) {
      return errorf(
          ERROR,
          "invalid argument to 'steps'; expected a 2-tuple, but got: '{}'",
          "invalid argument to 'gradient'; not a list of pairs: '{}'",
          expr_inspect(expr));
  }

  std::vector<std::pair<double, Color>> steps;
  for (size_t i = 0; i + 1 < args.size(); i += 2) {
    double step;
    if (auto rc = expr_to_ratio(args[0], &step); !rc) {
    if (auto rc = expr_to_ratio(args[i], &step); !rc) {
      return rc;
    }

    Color color;
    if (auto rc = color_read(ctx, args[1], &color); !rc) {
    if (auto rc = color_read(ctx, args[i + 1], &color); !rc) {
      return rc;
    }

    steps.emplace_back(step, color);

    if (!expr_has_next(expr)) {
      break;
    }
  }

  *color_map = color_map_steps(steps);
@@ -225,21 +203,12 @@ ReturnCode color_map_read(
    const Context* ctx,
    const Expr* expr,
    ColorMap* color_map) {
  if (!expr || !expr_is_list(expr)) {
    return errorf(
        ERROR,
        "invalid argument to <color-map>; expected a list, but got: '{}'",
        expr_inspect(expr));
  }

  expr = expr_get_list(expr);

  if (expr_is_value(expr, "gradient")) {
    return color_map_read_gradient(ctx, expr_next(expr), color_map);
  if (expr_is_list(expr, "gradient")) {
    return color_map_read_gradient(ctx, expr_get_list_tail(expr), color_map);
  }

  if (expr_is_value(expr, "steps")) {
    return color_map_read_steps(ctx, expr_next(expr), color_map);
  if (expr_is_list(expr, "steps")) {
    return color_map_read_steps(ctx, expr_get_list_tail(expr), color_map);
  }

  return errorf(
+9 −27
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ ReturnCode data_load_strings_csv(
    return errorf(
        ERROR,
        "invalid number of arguments to 'csv'; expected: 2, got: {}",
        "..."); // FIXME
        args.size());
  }


@@ -212,22 +212,13 @@ ReturnCode data_load_csv(
}

ReturnCode data_load_strings(
    const Expr* expr,
    const Expr* args,
    std::vector<std::string>* values) {
  if (!expr || !expr_is_list(expr)) {
    return errorf(
        ERROR,
        "argument error; expected a value, got: {}",
        "..."); // FIXME
  }

  auto args = expr_get_list(expr);

  if (args && expr_is_value_literal(args, "csv")) {
    return data_load_strings_csv(expr_next(args), values);
  if (args && expr_is_list(args, "csv")) {
    return data_load_strings_csv(expr_get_list_tail(args), values);
  }

  return expr_to_strings(expr, values);
  return expr_to_strings(args, values);
}

ReturnCode data_load_simple_inline(
@@ -295,19 +286,10 @@ ReturnCode data_load_simple_csv(
}

ReturnCode data_load_simple(
    const Expr* expr,
    const Expr* args,
    DataBuffer* values) {
  if (!expr || !expr_is_list(expr)) {
    return errorf(
        ERROR,
        "argument error; expected a list, got: {}",
        expr_inspect(expr));
  }

  auto args = expr_get_list(expr);

  if (args && expr_is_value_literal(args, "csv")) {
    return data_load_simple_csv(expr_next(args), values);
  if (args && expr_is_list(args, "csv")) {
    return data_load_simple_csv(expr_get_list_tail(args), values);
  }

  return data_load_simple_inline(args, values);
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ ReturnCode draw_eval(
  const auto& layer = *layer_get(ctx);

  ExprStorage unparsed;
  return expr_walk_commands(expr, nullptr, {
  return expr_walk_map(expr, nullptr, {
    {"text", std::bind(&draw::text_eval, ctx, _1)},
    {"rectangle", std::bind(&draw::rectangle, ctx, _1)},
  });
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ ReturnCode eval(
  std::string module_name = "plot";
  ExprStorage module_args;

  auto rc = expr_walk_commands(expr, &module_args, {
  auto rc = expr_walk_map(expr, &module_args, {
    {"class", std::bind(&expr_to_string, _1, &module_name)},
    {"size", std::bind(&layer_resize_cmd, ctx, _1)},
    {"dpi", std::bind(&layer_set_dpi_cmd, ctx, _1)},
+2 −13
Original line number Diff line number Diff line
@@ -387,17 +387,10 @@ ReturnCode legend_configure_position(
    const Expr* expr,
    HAlign* position_horiz,
    VAlign* position_vert) {
  if (!expr || !expr_is_list(expr)) {
    return errorf(
        ERROR,
        "invalid argument; expected a list but got: {}",
        expr_inspect(expr));
  }

  bool position_horiz_set = false;
  bool position_vert_set = false;

  for (expr = expr_get_list(expr); expr; expr = expr_next(expr)) {
  for (; expr; expr = expr_next(expr)) {
    if (expr_is_value(expr, "top")) {
      *position_vert = VAlign::TOP;
      position_vert_set = true;
@@ -438,12 +431,8 @@ ReturnCode configure_item(
    Context* ctx,
    const Expr* expr,
    std::vector<LegendItem>* items) {
  if (!expr_is_list(expr)) {
    return {ERROR, "expected a list"};
  }

  LegendItem item;
  if (auto rc = legend_item_configure(ctx, expr_get_list(expr), &item); !rc) {
  if (auto rc = legend_item_configure(ctx, expr, &item); !rc) {
    return rc;
  }

Loading