<commit_before>/*
Copyright (c) 2016. The YARA Authors. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>

#include <yara.h>
#include "blob.h"
#include "util.h"


static void test_boolean_operators()
{
  assert_true_rule(
      "rule test { condition: true }", NULL);

  assert_true_rule(
      "rule test { condition: true or false }", NULL);

  assert_true_rule(
      "rule test { condition: true and true }", NULL);

  assert_true_rule(
      "rule test { condition: 0x1 and 0x2}", NULL);

  assert_false_rule(
      "rule test { condition: false }", NULL);

  assert_false_rule(
      "rule test { condition: true and false }", NULL);

  assert_false_rule(
      "rule test { condition: false or false }", NULL);
}


static void test_comparison_operators()
{
  assert_true_rule(
      "rule test { condition: 2 > 1 }", NULL);

  assert_true_rule(
      "rule test { condition: 1 < 2 }", NULL);

  assert_true_rule(
      "rule test { condition: 2 >= 1 }", NULL);

  assert_true_rule(
      "rule test { condition: 1 <= 1 }", NULL);

  assert_true_rule(
      "rule test { condition: 1 == 1 }", NULL);

  assert_true_rule(
      "rule test { condition: 1.5 == 1.5}", NULL);

  assert_true_rule(
      "rule test { condition: 1.0 == 1}", NULL);

  assert_true_rule(
      "rule test { condition: 1.5 >= 1.0}", NULL);

  assert_true_rule(
      "rule test { condition: 1.5 >= 1}", NULL);

  assert_true_rule(
      "rule test { condition: 1.0 >= 1}", NULL);

  assert_true_rule(
      "rule test { condition: 0.5 < 1}", NULL);

  assert_true_rule(
      "rule test { condition: 0.5 <= 1}", NULL);

  assert_true_rule(
      "rule rest { condition: 1.0 <= 1}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abc\" == \"abc\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abc\" <= \"abc\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abc\" >= \"abc\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"ab\" < \"abc\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abc\" > \"ab\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abc\" < \"abd\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abd\" > \"abc\"}", NULL);

  assert_false_rule(
      "rule test { condition: 1 != 1}", NULL);

  assert_false_rule(
      "rule test { condition: 1 != 1.0}", NULL);

  assert_false_rule(
      "rule test { condition: 2 > 3}", NULL);

  assert_false_rule(
      "rule test { condition: 2.1 < 2}", NULL);

  assert_false_rule(
      "rule test { condition: \"abc\" != \"abc\"}", NULL);

  assert_false_rule(
      "rule test { condition: \"abc\" > \"abc\"}", NULL);

  assert_false_rule(
      "rule test { condition: \"abc\" < \"abc\"}", NULL);

}

static void test_arithmetic_operators()
{
  assert_true_rule(
      "rule test { condition: (1 + 1) * 2 == (9 - 1) \\ 2 }", NULL);

  assert_true_rule(
      "rule test { condition: 5 % 2 == 1 }", NULL);

  assert_true_rule(
      "rule test { condition: 1.5 + 1.5 == 3}", NULL);

  assert_true_rule(
      "rule test { condition: 3 \\ 2 == 1}", NULL);

  assert_true_rule(
      "rule test { condition: 3.0 \\ 2 == 1.5}", NULL);

  assert_true_rule(
      "rule test { condition: 1 + -1 == 0}", NULL);

  assert_true_rule(
      "rule test { condition: -1 + -1 == -2}", NULL);

  assert_true_rule(
      "rule test { condition: 4 --2 * 2 == 8}", NULL);

  assert_true_rule(
      "rule test { condition: -1.0 * 1 == -1.0}", NULL);

  assert_true_rule(
      "rule test { condition: 1-1 == 0}", NULL);

  assert_true_rule(
      "rule test { condition: -2.0-3.0 == -5}", NULL);

  assert_true_rule(
      "rule test { condition: --1 == 1}", NULL);

  assert_true_rule(
      "rule test { condition: 1--1 == 2}", NULL);

  assert_true_rule(
      "rule test { condition: 2 * -2 == -4}", NULL);

  assert_true_rule(
      "rule test { condition: -4 * 2 == -8}", NULL);

  assert_true_rule(
      "rule test { condition: -4 * -4 == 16}", NULL);

  assert_true_rule(
      "rule test { condition: -0x01 == -1}", NULL);

  assert_true_rule(
      "rule test { condition: 0o10 == 8 }", NULL);

  assert_true_rule(
      "rule test { condition: 0o100 == 64 }", NULL);

  assert_true_rule(
      "rule test { condition: 0o755 == 493 }", NULL);

  // TODO: This should return ERROR_INTEGER_OVERFLOW, but right now it returns
  // ERROR_SYNTAX_ERROR because after the lexer aborts with ERROR_INTEGER_OVERFLOW
  // the parser finds an unexpected end fails with error: unexpected $end.
  assert_error(
      "rule test { condition: 9223372036854775808 > 0 }",
      ERROR_SYNTAX_ERROR);

  assert_error(
      "rule test { condition: 9007199254740992KB > 0 }",
      ERROR_SYNTAX_ERROR);

  assert_error(  // integer too long
      "rule test { condition: 8796093022208MB > 0 }",
      ERROR_SYNTAX_ERROR);

  assert_error(  // integer too long
     "rule test { condition: 0x8000000000000000 > 0 }",
     ERROR_SYNTAX_ERROR);

  assert_error(  // integer too long
     "rule test { condition: 0o1000000000000000000000 > 0 }",
     ERROR_SYNTAX_ERROR);

  assert_error(
     "rule test { condition: 0x7FFFFFFFFFFFFFFF + 1 > 0 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: 9223372036854775807 + 1 > 0 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: -9223372036854775807 - 2 > 0 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: -2 + -9223372036854775807 > 0 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: 1 - -9223372036854775807 > 0 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: 0x4000000000000000 * 2 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: 4611686018427387904 * 2 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: 4611686018427387904 * -2 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: -4611686018427387904 * 2 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: -4611686018427387904 * -2 }",
     ERROR_INTEGER_OVERFLOW);
}


static void test_bitwise_operators()
{
  assert_true_rule(
      "rule test { condition: 0x55 | 0xAA == 0xFF }",
      NULL);

  assert_true_rule(
      "rule test { condition: ~0xAA ^ 0x5A & 0xFF == (~0xAA) ^ (0x5A & 0xFF) }",
      NULL);

  assert_true_rule(
      "rule test { condition: ~0x55 & 0xFF == 0xAA }",
      NULL);

  assert_true_rule(
      "rule test { condition: 8 >> 2 == 2 }",
      NULL);

  assert_true_rule(
      "rule test { condition: 1 << 3 == 8 }",
      NULL);

  assert_true_rule(
      "rule test { condition: 1 << 64 == 0 }",
      NULL);

  assert_true_rule(
      "rule test { condition: 1 >> 64 == 0 }",
      NULL);

  assert_true_rule(
      "rule test { condition: 1 | 3 ^ 3 == 1 | (3 ^ 3) }",
      NULL);

  assert_false_rule(
      "rule test { condition: ~0xAA ^ 0x5A & 0xFF == 0x0F }",
      NULL);

  assert_false_rule(
      "rule test { condition: 1 | 3 ^ 3 == (1 | 3) ^ 3}",
      NULL);

}


static void test_syntax()
{
  assert_error(
      "rule test { strings: $a = \"a\" $a = \"a\" condition: all of them }",
      ERROR_DUPLICATED_STRING_IDENTIFIER);
}


static void test_anonymous_strings()
{
  assert_true_rule(
      "rule test { strings: $ = \"a\" $ = \"b\" condition: all of them }",
      "ab");
}


static void test_strings()
{
  char* str = "---- abc ---- xyz";
  uint8_t blob[] = "---- a\0b\0c\0 -\0-\0-\0-\0x\0y\0z\0";

  assert_true_rule(
      "rule test { strings: $a = \"a\" condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"ab\" condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"abc\" condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"xyz\" condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"abc\" nocase fullword condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"aBc\" nocase  condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"abc\" fullword condition: $a }",
      str);

  assert_false_rule(
      "rule test { strings: $a = \"a\" fullword condition: $a }",
      str);

  assert_false_rule(
      "rule test { strings: $a = \"ab\" fullword condition: $a }",
      str);

  assert_false_rule(
      "rule test { strings: $a = \"abc\" wide fullword condition: $a }",
      str);

  assert_true_rule_blob(
      "rule test { strings: $a = \"a\" wide condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"a\" wide ascii condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"ab\" wide condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"ab\" wide ascii condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"abc\" wide condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"abc\" wide nocase fullword condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"aBc\" wide nocase condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"aBc\" wide ascii nocase condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"---xyz\" wide nocase condition: $a }",
      blob);

  assert_true_rule(
      "rule test { strings: $a = \"abc\" fullword condition: $a }",
      "abc");

  assert_false_rule(
      "rule test { strings: $a = \"abc\" fullword condition: $a }",
      "xabcx");

  assert_false_rule(
      "rule test { strings: $a = \"abc\" fullword condition: $a }",
      "xabc");

  assert_false_rule(
      "rule test { strings: $a = \"abc\" fullword condition: $a }",
      "abcx");

  assert_false_rule(
      "rule test { strings: $a = \"abc\" ascii wide fullword condition: $a }",
      "abcx");
<commit_msg>Add test case for bug fixed in 2840fa7fbb3c78dba253b35a7e44ec6df398d8a9<commit_after>/*
Copyright (c) 2016. The YARA Authors. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>

#include <yara.h>
#include "blob.h"
#include "util.h"


static void test_boolean_operators()
{
  assert_true_rule(
      "rule test { condition: true }", NULL);

  assert_true_rule(
      "rule test { condition: true or false }", NULL);

  assert_true_rule(
      "rule test { condition: true and true }", NULL);

  assert_true_rule(
      "rule test { condition: 0x1 and 0x2}", NULL);

  assert_false_rule(
      "rule test { condition: false }", NULL);

  assert_false_rule(
      "rule test { condition: true and false }", NULL);

  assert_false_rule(
      "rule test { condition: false or false }", NULL);
}


static void test_comparison_operators()
{
  assert_true_rule(
      "rule test { condition: 2 > 1 }", NULL);

  assert_true_rule(
      "rule test { condition: 1 < 2 }", NULL);

  assert_true_rule(
      "rule test { condition: 2 >= 1 }", NULL);

  assert_true_rule(
      "rule test { condition: 1 <= 1 }", NULL);

  assert_true_rule(
      "rule test { condition: 1 == 1 }", NULL);

  assert_true_rule(
      "rule test { condition: 1.5 == 1.5}", NULL);

  assert_true_rule(
      "rule test { condition: 1.0 == 1}", NULL);

  assert_true_rule(
      "rule test { condition: 1.5 >= 1.0}", NULL);

  assert_true_rule(
      "rule test { condition: 1.5 >= 1}", NULL);

  assert_true_rule(
      "rule test { condition: 1.0 >= 1}", NULL);

  assert_true_rule(
      "rule test { condition: 0.5 < 1}", NULL);

  assert_true_rule(
      "rule test { condition: 0.5 <= 1}", NULL);

  assert_true_rule(
      "rule rest { condition: 1.0 <= 1}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abc\" == \"abc\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abc\" <= \"abc\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abc\" >= \"abc\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"ab\" < \"abc\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abc\" > \"ab\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abc\" < \"abd\"}", NULL);

  assert_true_rule(
      "rule rest { condition: \"abd\" > \"abc\"}", NULL);

  assert_false_rule(
      "rule test { condition: 1 != 1}", NULL);

  assert_false_rule(
      "rule test { condition: 1 != 1.0}", NULL);

  assert_false_rule(
      "rule test { condition: 2 > 3}", NULL);

  assert_false_rule(
      "rule test { condition: 2.1 < 2}", NULL);

  assert_false_rule(
      "rule test { condition: \"abc\" != \"abc\"}", NULL);

  assert_false_rule(
      "rule test { condition: \"abc\" > \"abc\"}", NULL);

  assert_false_rule(
      "rule test { condition: \"abc\" < \"abc\"}", NULL);

}

static void test_arithmetic_operators()
{
  assert_true_rule(
      "rule test { condition: (1 + 1) * 2 == (9 - 1) \\ 2 }", NULL);

  assert_true_rule(
      "rule test { condition: 5 % 2 == 1 }", NULL);

  assert_true_rule(
      "rule test { condition: 1.5 + 1.5 == 3}", NULL);

  assert_true_rule(
      "rule test { condition: 3 \\ 2 == 1}", NULL);

  assert_true_rule(
      "rule test { condition: 3.0 \\ 2 == 1.5}", NULL);

  assert_true_rule(
      "rule test { condition: 1 + -1 == 0}", NULL);

  assert_true_rule(
      "rule test { condition: -1 + -1 == -2}", NULL);

  assert_true_rule(
      "rule test { condition: 4 --2 * 2 == 8}", NULL);

  assert_true_rule(
      "rule test { condition: -1.0 * 1 == -1.0}", NULL);

  assert_true_rule(
      "rule test { condition: 1-1 == 0}", NULL);

  assert_true_rule(
      "rule test { condition: -2.0-3.0 == -5}", NULL);

  assert_true_rule(
      "rule test { condition: --1 == 1}", NULL);

  assert_true_rule(
      "rule test { condition: 1--1 == 2}", NULL);

  assert_true_rule(
      "rule test { condition: 2 * -2 == -4}", NULL);

  assert_true_rule(
      "rule test { condition: -4 * 2 == -8}", NULL);

  assert_true_rule(
      "rule test { condition: -4 * -4 == 16}", NULL);

  assert_true_rule(
      "rule test { condition: -0x01 == -1}", NULL);

  assert_true_rule(
      "rule test { condition: 0o10 == 8 }", NULL);

  assert_true_rule(
      "rule test { condition: 0o100 == 64 }", NULL);

  assert_true_rule(
      "rule test { condition: 0o755 == 493 }", NULL);

  // TODO: This should return ERROR_INTEGER_OVERFLOW, but right now it returns
  // ERROR_SYNTAX_ERROR because after the lexer aborts with ERROR_INTEGER_OVERFLOW
  // the parser finds an unexpected end fails with error: unexpected $end.
  assert_error(
      "rule test { condition: 9223372036854775808 > 0 }",
      ERROR_SYNTAX_ERROR);

  assert_error(
      "rule test { condition: 9007199254740992KB > 0 }",
      ERROR_SYNTAX_ERROR);

  assert_error(  // integer too long
      "rule test { condition: 8796093022208MB > 0 }",
      ERROR_SYNTAX_ERROR);

  assert_error(  // integer too long
     "rule test { condition: 0x8000000000000000 > 0 }",
     ERROR_SYNTAX_ERROR);

  assert_error(  // integer too long
     "rule test { condition: 0o1000000000000000000000 > 0 }",
     ERROR_SYNTAX_ERROR);

  assert_error(
     "rule test { condition: 0x7FFFFFFFFFFFFFFF + 1 > 0 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: 9223372036854775807 + 1 > 0 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: -9223372036854775807 - 2 > 0 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: -2 + -9223372036854775807 > 0 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: 1 - -9223372036854775807 > 0 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: 0x4000000000000000 * 2 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: 4611686018427387904 * 2 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: 4611686018427387904 * -2 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: -4611686018427387904 * 2 }",
     ERROR_INTEGER_OVERFLOW);

  assert_error(
     "rule test { condition: -4611686018427387904 * -2 }",
     ERROR_INTEGER_OVERFLOW);
}


static void test_bitwise_operators()
{
  assert_true_rule(
      "rule test { condition: 0x55 | 0xAA == 0xFF }",
      NULL);

  assert_true_rule(
      "rule test { condition: ~0xAA ^ 0x5A & 0xFF == (~0xAA) ^ (0x5A & 0xFF) }",
      NULL);

  assert_true_rule(
      "rule test { condition: ~0x55 & 0xFF == 0xAA }",
      NULL);

  assert_true_rule(
      "rule test { condition: 8 >> 2 == 2 }",
      NULL);

  assert_true_rule(
      "rule test { condition: 1 << 3 == 8 }",
      NULL);

  assert_true_rule(
      "rule test { condition: 1 << 64 == 0 }",
      NULL);

  assert_true_rule(
      "rule test { condition: 1 >> 64 == 0 }",
      NULL);

  assert_true_rule(
      "rule test { condition: 1 | 3 ^ 3 == 1 | (3 ^ 3) }",
      NULL);

  assert_false_rule(
      "rule test { condition: ~0xAA ^ 0x5A & 0xFF == 0x0F }",
      NULL);

  assert_false_rule(
      "rule test { condition: 1 | 3 ^ 3 == (1 | 3) ^ 3}",
      NULL);

}


static void test_syntax()
{
  assert_error(
      "rule test { strings: $a = \"a\" $a = \"a\" condition: all of them }",
      ERROR_DUPLICATED_STRING_IDENTIFIER);
}


static void test_anonymous_strings()
{
  assert_true_rule(
      "rule test { strings: $ = \"a\" $ = \"b\" condition: all of them }",
      "ab");
}


static void test_strings()
{
  char* str = "---- abc ---- xyz";
  uint8_t blob[] = "---- a\0b\0c\0 -\0-\0-\0-\0x\0y\0z\0";

  assert_true_rule(
      "rule test { strings: $a = \"a\" condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"ab\" condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"abc\" condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"xyz\" condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"abc\" nocase fullword condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"aBc\" nocase  condition: $a }",
      str);

  assert_true_rule(
      "rule test { strings: $a = \"abc\" fullword condition: $a }",
      str);

  assert_false_rule(
      "rule test { strings: $a = \"a\" fullword condition: $a }",
      str);

  assert_false_rule(
      "rule test { strings: $a = \"ab\" fullword condition: $a }",
      str);

  assert_false_rule(
      "rule test { strings: $a = \"abc\" wide fullword condition: $a }",
      str);

  assert_true_rule_blob(
      "rule test { strings: $a = \"a\" wide condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"a\" wide ascii condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"ab\" wide condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"ab\" wide ascii condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"abc\" wide condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"abc\" wide nocase fullword condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"aBc\" wide nocase condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"aBc\" wide ascii nocase condition: $a }",
      blob);

  assert_true_rule_blob(
      "rule test { strings: $a = \"---xyz\" wide nocase condition: $a }",
      blob);

  assert_true_rule(
      "rule test { strings: $a = \"abc\" fullword condition: $a }",
      "abc");

  assert_false_rule(
      "rule test { strings: $a = \"abc\" fullword condition: $a }",
      "xabcx");

  assert_false_rule(
      "rule test { strings: $a = \"abc\" fullword condition: $a }",
      "xabc");

  assert_false_rule(
      "rule test { strings: $a = \"abc\" fullword condition: $a }",
      "abcx");

  assert_false_rule_blob(
      "rule test { strings: $a = \"abc\" wide condition: $a }",
      "a\1b\0c\0d\0e\0f\0");

  assert_false_rule_blob(
      "rule test { strings: $a = \"abcdef\" wide condition: $a }",
      "a\0b\0c\0d\0e\0f\1");

  assert_false_rule(
      "rule test { strings: $a = \"abc\" ascii wide fullword condition: $a }",
      "abcx");

{'fraction_non_alphanumeric': 0.1434989089975613, 'fraction_numerical': 0.04235656526761648, 'mean_word_length': 2.8532805802835477, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, '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': '5749321', 'n_tokens_mistral': 8772, 'n_tokens_neox': 7795, 'n_words': 2379}