<commit_before>#include "emeus-test-utils.h"

#include "emeus-expression-private.h"
#include "emeus-simplex-solver-private.h"
#include "emeus-types-private.h"
#include "emeus-variable-private.h"
#include "emeus-vfl-parser-private.h"

static struct {
  const char *id;
  const char *expression;
} vfl_valid[] = {
  { "standard-space", "[button]-[textField]", },
  { "width-constraint", "[button(>=50)]", },
  { "connection-superview", "|-50-[purpleBox]-50-|", },
  { "vertical-layout", "V:[topField]-10-[bottomField]", },
  { "flush-views", "[maroonView][blueView]", },
  { "priority", "[button(100@strong)]", },
  { "equal-widths", "[button1(==button2)]", },
  { "multiple-predicates", "[flexibleButton(>=70,<=100)]", },
  { "complete-line", "|-[find]-[findNext]-[findField(>=20)]-|", },
  { "dot-name", "[button1(==button2.width)]", },
  { "grid-1", "H:|-8-[view1(==view2)]-12-[view2]-8-|", },
  { "grid-2", "H:|-8-[view3]-8-|", },
  { "grid-3", "V:|-8-[view1]-12-[view3(==view1,view2)]-8-|", },
  { "predicate-spacing-1", "|-(>=0)-[view]-(>=0)-|", },
};

static struct {
  const char *id;
  const char *expression;
  VflError error_id;
} vfl_invalid[] = {
  { "orientation-invalid", "V|[backgroundBox]|", VFL_ERROR_INVALID_SYMBOL, },
  { "missing-view-terminator", "[backgroundBox)", VFL_ERROR_INVALID_SYMBOL, },
  { "invalid-predicate", "[backgroundBox(]", VFL_ERROR_INVALID_SYMBOL, },
  { "invalid-view", "[[", VFL_ERROR_INVALID_VIEW, },
  { "invalid-super-view", "[view]|", VFL_ERROR_INVALID_SYMBOL, },
  { "trailing-spacing", "[view]-", VFL_ERROR_INVALID_SYMBOL, },
  { "leading-spacing", "-[view]", VFL_ERROR_INVALID_SYMBOL, },
  { "view-invalid-identifier-1", "[9ab]", VFL_ERROR_INVALID_VIEW, },
  { "view-invalid-identifier-2", "[-a]", VFL_ERROR_INVALID_VIEW, },
  { "predicate-wrong-relation", "[view(>30)]", VFL_ERROR_INVALID_RELATION, },
  { "predicate-wrong-priority", "[view(>=30@foo)]", VFL_ERROR_INVALID_PRIORITY, },
  { "predicate-wrong-attribute", "[view1(==view2.height)]", VFL_ERROR_INVALID_ATTRIBUTE, },
};

static void
vfl_parser_valid (gconstpointer data)
{
  int idx = GPOINTER_TO_INT (data);
  VflParser *parser = vfl_parser_new ();
  GError *error = NULL;
  VflConstraint *constraints;
  int n_constraints = 0;

  g_test_message ("Parsing [valid]: '%s'", vfl_valid[idx].expression);

  vfl_parser_parse_line (parser, vfl_valid[idx].expression, -1, &error);
  g_assert_no_error (error);

  constraints = vfl_parser_get_constraints (parser, &n_constraints);
  g_assert (constraints != NULL);
  g_assert (n_constraints != 0);<commit_msg>tests: Use appropriate assertion macros<commit_after>#include "emeus-test-utils.h"

#include "emeus-expression-private.h"
#include "emeus-simplex-solver-private.h"
#include "emeus-types-private.h"
#include "emeus-variable-private.h"
#include "emeus-vfl-parser-private.h"

static struct {
  const char *id;
  const char *expression;
} vfl_valid[] = {
  { "standard-space", "[button]-[textField]", },
  { "width-constraint", "[button(>=50)]", },
  { "connection-superview", "|-50-[purpleBox]-50-|", },
  { "vertical-layout", "V:[topField]-10-[bottomField]", },
  { "flush-views", "[maroonView][blueView]", },
  { "priority", "[button(100@strong)]", },
  { "equal-widths", "[button1(==button2)]", },
  { "multiple-predicates", "[flexibleButton(>=70,<=100)]", },
  { "complete-line", "|-[find]-[findNext]-[findField(>=20)]-|", },
  { "dot-name", "[button1(==button2.width)]", },
  { "grid-1", "H:|-8-[view1(==view2)]-12-[view2]-8-|", },
  { "grid-2", "H:|-8-[view3]-8-|", },
  { "grid-3", "V:|-8-[view1]-12-[view3(==view1,view2)]-8-|", },
  { "predicate-spacing-1", "|-(>=0)-[view]-(>=0)-|", },
};

static struct {
  const char *id;
  const char *expression;
  VflError error_id;
} vfl_invalid[] = {
  { "orientation-invalid", "V|[backgroundBox]|", VFL_ERROR_INVALID_SYMBOL, },
  { "missing-view-terminator", "[backgroundBox)", VFL_ERROR_INVALID_SYMBOL, },
  { "invalid-predicate", "[backgroundBox(]", VFL_ERROR_INVALID_SYMBOL, },
  { "invalid-view", "[[", VFL_ERROR_INVALID_VIEW, },
  { "invalid-super-view", "[view]|", VFL_ERROR_INVALID_SYMBOL, },
  { "trailing-spacing", "[view]-", VFL_ERROR_INVALID_SYMBOL, },
  { "leading-spacing", "-[view]", VFL_ERROR_INVALID_SYMBOL, },
  { "view-invalid-identifier-1", "[9ab]", VFL_ERROR_INVALID_VIEW, },
  { "view-invalid-identifier-2", "[-a]", VFL_ERROR_INVALID_VIEW, },
  { "predicate-wrong-relation", "[view(>30)]", VFL_ERROR_INVALID_RELATION, },
  { "predicate-wrong-priority", "[view(>=30@foo)]", VFL_ERROR_INVALID_PRIORITY, },
  { "predicate-wrong-attribute", "[view1(==view2.height)]", VFL_ERROR_INVALID_ATTRIBUTE, },
};

static void
vfl_parser_valid (gconstpointer data)
{
  int idx = GPOINTER_TO_INT (data);
  VflParser *parser = vfl_parser_new ();
  GError *error = NULL;
  VflConstraint *constraints;
  int n_constraints = 0;

  g_test_message ("Parsing [valid]: '%s'", vfl_valid[idx].expression);

  vfl_parser_parse_line (parser, vfl_valid[idx].expression, -1, &error);
  g_assert_no_error (error);

  constraints = vfl_parser_get_constraints (parser, &n_constraints);
  g_assert_nonnull (constraints);
  g_assert_cmpint (n_constraints, !=, 0);
{'fraction_non_alphanumeric': 0.2283220174587779, 'fraction_numerical': 0.02250242483026188, 'mean_word_length': 5.534854245880862, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5412027', 'n_tokens_mistral': 2058, 'n_tokens_neox': 1965, 'n_words': 276}