<commit_before><?php

use Keboola\Filter\Filter;

class FilterTest extends \PHPUnit_Framework_TestCase
{
    public function testStaticCompare()
    {
        $this->assertEquals(Filter::staticCompare("test!#$#%$%{}", "test!#$#%$%{}", "=="), true);
        $this->assertEquals(Filter::staticCompare("test", "test", "!="), false);
    }

    public function testCompare()
    {
        $filter = new Filter(".", ">", 1);
        $this->assertEquals($filter->compare(2), true);
        $this->assertEquals($filter->compare(0), false);
    }

    public function testCompareObject()
    {
        $filter = new Filter("field", "<=", 1);
        $object = new \stdClass();
        $object->field = 0;
        $this->assertEquals($filter->compareObject($object), true);
        $object->field = 2;
        $this->assertEquals($filter->compareObject($object), false);
    }

    public function testCompareString()
    {
        $object = new \stdClass();
        $object->field1 = 'test';
        $object->field2 = 'testing';
        $object->field3 = 'sometest';
        $object->field4 = 'sometesting';

        $filter = Filter::create("field1==test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2==test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field3==test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field4==test");
        $this->assertEquals($filter->compareObject($object), false);

        $filter = Filter::create("field1~~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2~~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field3~~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field4~~test");
        $this->assertEquals($filter->compareObject($object), false);

        $filter = Filter::create("field1~~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2~~%test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field2~~test%");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2~~%test%");
        $this->assertEquals($filter->compareObject($object), true);

        $filter = Filter::create("field3~~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field3~~test%");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field3~~%test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field3~~%test%");
        $this->assertEquals($filter->compareObject($object), true);

        $filter = Filter::create("field4~~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field4~~test%");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field4~~%test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field4~~%test%");
        $this->assertEquals($filter->compareObject($object), true);
    }


    public function testCompareNegString()
    {
        $object = new \stdClass();
        $object->field1 = 'test';
        $object->field2 = 'testing';
        $object->field3 = 'sometest';
        $object->field4 = 'sometesting';

        $filter = Filter::create("field1!=test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field2!=test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field3!=test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field4!=test");
        $this->assertEquals($filter->compareObject($object), true);

        $filter = Filter::create("field1!~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field2!~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field3!~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field4!~test");
        $this->assertEquals($filter->compareObject($object), true);

        $filter = Filter::create("field1!~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field2!~%test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2!~test%");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field2!~%test%");
        $this->assertEquals($filter->compareObject($object), false);

        $filter = Filter::create("field3!~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field3!~test%");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field3!~%test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field3!~%test%");
        $this->assertEquals($filter->compareObject($object), false);

        $filter = Filter::create("field4!~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field4!~test%");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field4!~~%test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field4!~%test%");
        $this->assertEquals($filter->compareObject($object), false);
    }
    
    public function testCompareStringComplex()
    {
        $object = new \stdClass();
        $object->field1 = 'test';
        $object->field2 = 'terrorist';

        $filter = Filter::create("field1~~te%st");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2~~te%st");
        $this->assertEquals($filter->compareObject($object), true);

        $object = new \stdClass();
        $object->field1 = 'testtesttest';
        $object->field2 = 'testtesttest';
        $filter = Filter::create("field1~~%st%st");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2~~te%te%");
        $this->assertEquals($filter->compareObject($object), true);
    }

    public function testCompareMulti()
    {
        // &
        $filter = Filter::create("field1==0&field2!=0");
<commit_msg>tests: added tests for null<commit_after><?php

use Keboola\Filter\Filter;

class FilterTest extends \PHPUnit_Framework_TestCase
{
    public function testStaticCompare()
    {
        $this->assertEquals(Filter::staticCompare("test!#$#%$%{}", "test!#$#%$%{}", "=="), true);
        $this->assertEquals(Filter::staticCompare("test", "test", "!="), false);
    }

    public function testCompare()
    {
        $filter = new Filter(".", ">", 1);
        $this->assertEquals($filter->compare(2), true);
        $this->assertEquals($filter->compare(0), false);
    }

    public function testCompareObject()
    {
        $filter = new Filter("field", "<=", 1);
        $object = new \stdClass();
        $object->field = 0;
        $this->assertEquals($filter->compareObject($object), true);
        $object->field = 2;
        $this->assertEquals($filter->compareObject($object), false);
    }

    public function testCompareNull()
    {
        $object = new \stdClass();
        $object->field2 = null;
        $object->field3 = 'null';

        $filter = Filter::create("field2==");
        $this->assertTrue($filter->compareObject($object));
        $filter = Filter::create("field2!=");
        $this->assertFalse($filter->compareObject($object));
        $filter = Filter::create("field3==null");
        $this->assertTrue($filter->compareObject($object));
    }

    public function testCompareString()
    {
        $object = new \stdClass();
        $object->field1 = 'test';
        $object->field2 = 'testing';
        $object->field3 = 'sometest';
        $object->field4 = 'sometesting';

        $filter = Filter::create("field1==test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2==test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field3==test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field4==test");
        $this->assertEquals($filter->compareObject($object), false);

        $filter = Filter::create("field1~~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2~~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field3~~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field4~~test");
        $this->assertEquals($filter->compareObject($object), false);

        $filter = Filter::create("field1~~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2~~%test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field2~~test%");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2~~%test%");
        $this->assertEquals($filter->compareObject($object), true);

        $filter = Filter::create("field3~~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field3~~test%");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field3~~%test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field3~~%test%");
        $this->assertEquals($filter->compareObject($object), true);

        $filter = Filter::create("field4~~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field4~~test%");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field4~~%test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field4~~%test%");
        $this->assertEquals($filter->compareObject($object), true);
    }


    public function testCompareNegString()
    {
        $object = new \stdClass();
        $object->field1 = 'test';
        $object->field2 = 'testing';
        $object->field3 = 'sometest';
        $object->field4 = 'sometesting';

        $filter = Filter::create("field1!=test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field2!=test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field3!=test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field4!=test");
        $this->assertEquals($filter->compareObject($object), true);

        $filter = Filter::create("field1!~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field2!~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field3!~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field4!~test");
        $this->assertEquals($filter->compareObject($object), true);

        $filter = Filter::create("field1!~test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field2!~%test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2!~test%");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field2!~%test%");
        $this->assertEquals($filter->compareObject($object), false);

        $filter = Filter::create("field3!~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field3!~test%");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field3!~%test");
        $this->assertEquals($filter->compareObject($object), false);
        $filter = Filter::create("field3!~%test%");
        $this->assertEquals($filter->compareObject($object), false);

        $filter = Filter::create("field4!~test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field4!~test%");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field4!~~%test");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field4!~%test%");
        $this->assertEquals($filter->compareObject($object), false);
    }

    public function testCompareStringComplex()
    {
        $object = new \stdClass();
        $object->field1 = 'test';
        $object->field2 = 'terrorist';

        $filter = Filter::create("field1~~te%st");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2~~te%st");
        $this->assertEquals($filter->compareObject($object), true);

        $object = new \stdClass();
        $object->field1 = 'testtesttest';
        $object->field2 = 'testtesttest';
        $filter = Filter::create("field1~~%st%st");
        $this->assertEquals($filter->compareObject($object), true);
        $filter = Filter::create("field2~~te%te%");
        $this->assertEquals($filter->compareObject($object), true);
    }

    public function testCompareMulti()
    {
        // &
        $filter = Filter::create("field1==0&field2!=0");

{'fraction_non_alphanumeric': 0.19917412250516173, 'fraction_numerical': 0.0094287680660702, 'mean_word_length': 3.5911532385466036, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 237, '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': '4105969', 'n_tokens_mistral': 3970, 'n_tokens_neox': 3920, 'n_words': 565}