text:
<?php

namespace Illuminate\Tests\Support;

use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Stringable;
use PHPUnit\Framework\TestCase;

class SupportStringableTest extends TestCase
{
    /**
     * @param  string  $string
     * @return \Illuminate\Support\Stringable
     */
    protected function stringable($string = '')
    {
        return new Stringable($string);
    }

    public function testClassBasename()
    {
        $this->assertEquals(
            class_basename(static::class),
            $this->stringable(static::class)->classBasename()
        );
    }

    public function testIsAscii()
    {
        $this->assertTrue($this->stringable('A')->isAscii());
        $this->assertFalse($this->stringable('ù')->isAscii());
    }

    public function testIsUuid()
    {
        $this->assertTrue($this->stringable('2cdc7039-65a6-4ac7-8e5d-d554a98e7b15')->isUuid());
        $this->assertFalse($this->stringable('2cdc7039-65a6-4ac7-8e5d-d554a98')->isUuid());
    }

    public function testIsJson()
    {
        $this->assertTrue($this->stringable('1')->isJson());
        $this->assertTrue($this->stringable('[1,2,3]')->isJson());
        $this->assertTrue($this->stringable('[1,   2,   3]')->isJson());
        $this->assertTrue($this->stringable('{"first": "John", "last": "Doe"}')->isJson());
        $this->assertTrue($this->stringable('[{"first": "John", "last": "Doe"}, {"first": "Jane", "last": "Doe"}]')->isJson());

        $this->assertFalse($this->stringable('1,')->isJson());
        $this->assertFalse($this->stringable('[1,2,3')->isJson());
        $this->assertFalse($this->stringable('[1,   2   3]')->isJson());
        $this->assertFalse($this->stringable('{first: "John"}')->isJson());
        $this->assertFalse($this->stringable('[{first: "John"}, {first: "Jane"}]')->isJson());
        $this->assertFalse($this->stringable('')->isJson());
        $this->assertFalse($this->stringable(null)->isJson());
    }

    public function testIsEmpty()
    {
        $this->assertTrue($this->stringable('')->isEmpty());
        $this->assertFalse($this->stringable('A')->isEmpty());
        $this->assertFalse($this->stringable('0')->isEmpty());
    }

    public function testIsNotEmpty()
    {
        $this->assertFalse($this->stringable('')->isNotEmpty());
        $this->assertTrue($this->stringable('A')->isNotEmpty());
    }

    public function testPluralStudly()
    {
        $this->assertSame('LaraCon', (string) $this->stringable('LaraCon')->pluralStudly(1));
        $this->assertSame('LaraCons', (string) $this->stringable('LaraCon')->pluralStudly(2));
        $this->assertSame('LaraCon', (string) $this->stringable('LaraCon')->pluralStudly(-1));
        $this->assertSame('LaraCons', (string) $this->stringable('LaraCon')->pluralStudly(-2));
    }

    public function testMatch()
    {
        $stringable = $this->stringable('foo bar');

        $this->assertSame('bar', (string) $stringable->match('/bar/'));
        $this->assertSame('bar', (string) $stringable->match('/foo (.*)/'));
        $this->assertTrue($stringable->match('/nothing/')->isEmpty());

        $this->assertEquals(['bar', 'bar'], $this->stringable('bar foo bar')->matchAll('/bar/')->all());

        $stringable = $this->stringable('bar fun bar fly');

        $this->assertEquals(['un', 'ly'], $stringable->matchAll('/f(\w*)/')->all());
        $this->assertTrue($stringable->matchAll('/nothing/')->isEmpty());
    }

    public function testTest()
    {
        $stringable = $this->stringable('foo bar');

        $this->assertTrue($stringable->test('/bar/'));
        $this->assertTrue($stringable->test('/foo (.*)/'));
    }

    public function testTrim()
    {
        $this->assertSame('foo', (string) $this->stringable(' foo ')->trim());
    }

    public function testLtrim()
    {
        $this->assertSame('foo ', (string) $this->stringable(' foo ')->ltrim());
    }

    public function testRtrim()
    {
        $this->assertSame(' foo', (string) $this->stringable(' foo ')->rtrim());
    }

    public function testCanBeLimitedByWords()
    {
        $this->assertSame('Taylor...', (string) $this->stringable('Taylor Otwell')->words(1));
        $this->assertSame('Taylor___', (string) $this->stringable('Taylor Otwell')->words(1, '___'));
        $this->assertSame('Taylor Otwell', (string) $this->stringable('Taylor Otwell')->words(3));
    }

    public function testUnless()
    {
        $this->assertSame('unless false', (string) $this->stringable('unless')->unless(false, function ($stringable, $value) {
            return $stringable->append(' false');
        }));

        $this->assertSame('unless true fallbacks to default', (string) $this->stringable('unless')->unless(true, function ($stringable, $value) {
            return $stringable->append($value);
        }, function ($stringable) {
            return $stringable->append(' true fallbacks to default');
        }));
    }

    public function testWhenContains()
    {
        $this->assertSame('Tony Stark', (string) $this->stringable('stark')->whenContains('tar', function ($stringable) {
            return $stringable->prepend('Tony ')->title();
        }, function ($stringable) {
            return $stringable->prepend('Arno ')->title();
        }));

        $this->assertSame('stark', (string) $this->stringable('stark')->whenContains('xxx', function ($stringable) {
            return $stringable->prepend('Tony ')->title();
        }));

        $this->assertSame('Arno Stark', (string) $this->stringable('stark')->whenContains('xxx', function ($stringable) {
            return $stringable->prepend('Tony ')->title();
        }, function ($stringable) {
            return $stringable->prepend('Arno ')->title();
        }));
    }

    public function testWhenContainsAll()
    {
        $this->assertSame('Tony Stark', (string) $this->stringable('tony stark')->whenContainsAll(['tony', 'stark'], function ($stringable) {
            return $stringable->title();
        }, function ($stringable) {
            return $stringable->studly();
        }));

        $this->assertSame('tony stark', (string) $this->stringable('tony stark')->whenContainsAll(['xxx'], function ($stringable) {
            return $stringable->title();
        }));

        $this->assertSame('TonyStark', (string) $this->stringable('tony stark')->whenContainsAll(['tony', 'xxx'], function ($stringable) {
            return $stringable->title();
        }, function ($stringable) {
            return $stringable->studly();
        }));
    }

    public function testDirname()
    {
        $this->assertSame('/framework/tests', (string) $this->stringable('/framework/tests/Support')->dirname());
        $this->assertSame('/framework', (string) $this->stringable('/framework/tests/Support')->dirname(2));

        $this->assertSame('/', (string) $this->stringable('/framework/')->dirname());

        $this->assertSame('/', (string) $this->stringable('/')->dirname());
        $this->assertSame('.', (string) $this->stringable('.')->dirname());

        //  without slash
        $this->assertSame('.', (string) $this->stringable('framework')->dirname());
    }

    public function testUcsplitOnStringable()
    {
        $this->assertSame(['Taylor', 'Otwell'], $this->stringable('TaylorOtwell')->ucsplit()->toArray());
        $this->assertSame(['Hello', 'From', 'Laravel'], $this->stringable('HelloFromLaravel')->ucsplit()->toArray());
        $this->assertSame(['He_llo_', 'World'], $this->stringable('He_llo_World')->ucsplit()->toArray());
    }

    public function testWhenEndsWith()
    {
        $this->assertSame('Tony Stark', (string) $this->stringable('tony stark')->whenEndsWith('ark', function ($stringable) {
            return $stringable->title();
        }, function ($stringable) {
            return $stringable->studly();
        }));

        $this->assertSame('Tony Stark', (string) $this->stringable('tony stark')->whenEndsWith(['kra', 'ark'], function ($stringable) {
            return $stringable->title();
        }, function ($stringable) {
            return $stringable->studly();
        }));

        $this->assertSame('tony stark', (string) $this->stringable('tony stark')->whenEndsWith(['xxx'], function ($stringable) {
            return $stringable->title();
        }));

        $this->assertSame('TonyStark', (string) $this->stringable('tony stark')->whenEndsWith(['tony', 'xxx'], function ($stringable) {
            return $stringable->title();
        }, function ($stringable) {
            return $stringable->studly();
        }));
    }

    public function testWhenExactly()
    {
        $this->assertSame('Nailed it...!', (string) $this->stringable('Tony Stark')->whenExactly('Tony Stark', function ($stringable) {
            return 'Nailed it...!';
        }, function ($stringable) {
            return 'Swing and a miss...!';
        }));

        $this->assertSame('Swing and a miss...!', (string) $this->stringable('Tony Stark')->whenExactly('Iron Man', function ($stringable) {
            return 'Nailed it...!';
        }, function ($stringable) {
            return 'Swing and a miss...!';
        }));

        $this->assertSame('Tony Stark', (string) $this->stringable('Tony Stark')->whenExactly('Iron Man', function ($stringable) {
            return 'Nailed it...!';
        }));
    }

    public function testWhenNotExactly()
    {
        $this->assertSame(
            'Iron Man',
            (string) $this->stringable('Tony')->whenNotExactly('Tony Stark', function ($stringable) {
                return 'Iron Man';
            }));

        $this->assertSame(
            'Swing and a miss...!',
            (string) $this->stringable('Tony Stark')->whenNotExactly('Tony Stark', function ($stringable) {
                return 'Iron Man';
            }, function ($stringable) {
                return 'Swing and a miss...!';
            }));
    }

    public function testWhenIs()
    {
        $this->assertSame('Winner: /', (string) $this->stringable('/')->whenIs('/', function ($stringable) {
            return $stringable->prepend('Winner: ');
        }, function ($stringable) {
            return 'Try again';
        }));

        $this->assertSame('/', (string) $this->stringable('/')->whenIs(' /', function ($stringable) {
            return $stringable->prepend('Winner: ');
        }));

        $this->assertSame('Try again', (string) $this->stringable('/')->whenIs(' /', function ($stringable) {
            return $stringable->prepend('Winner: ');
        }, function ($stringable) {
            return 'Try again';
        }));

        $this->assertSame('Winner: foo/bar/baz', (string) $this->stringable('foo/bar/baz')->whenIs('foo/*', function ($stringable) {
            return $stringable->prepend('Winner: ');
        }));
    }

    public function testWhenIsAscii()
    {
        $this->assertSame('Ascii: A', (string) $this->stringable('A')->whenIsAscii(function ($stringable) {
            return $stringable->prepend('Ascii: ');
        }, function ($stringable) {
            return $stringable->prepend('Not Ascii: ');
        }));

        $this->assertSame('ù', (string) $this->stringable('ù')->whenIsAscii(function ($stringable) {
            return $stringable->prepend('Ascii: ');
        }));

        $this->assertSame('Not Ascii: ù', (string) $this->stringable('ù')->whenIsAscii(function ($stringable) {
            return $stringable->prepend('Ascii: ');
        }, function ($stringable) {
            return $stringable->prepend('Not Ascii: ');
        }));
    }

    public function testWhenIsUuid()
    {
        $this->assertSame('Uuid: 2cdc7039-65a6-4ac7-8e5d-d554a98e7b15', (string) $this->stringable('2cdc7039-65a6-4ac7-8e5d-d554a98e7b15')->whenIsUuid(function ($stringable) {
            return $stringable->prepend('Uuid: ');
        }, function ($stringable) {
            return $stringable->prepend('Not Uuid: ');
        }));

        $this->assertSame('2cdc7039-65a6-4ac7-8e5d-d554a98', (string) $this->stringable('2cdc7039-65a6-4ac7-8e5d-d554a98')->whenIsUuid(function ($stringable) {
            return $stringable->prepend('Uuid: ');
        }));

        $this->assertSame('Not Uuid: 2cdc7039-65a6-4ac7-8e5d-d554a98', (string) $this->stringable('2cdc7039-65a6-4ac7-8e5d-d554a98')->whenIsUuid(function ($stringable) {
            return $stringable->prepend('Uuid: ');
        }, function ($stringable) {
            return $stringable->prepend('Not Uuid: ');
        }));
    }

    public function testWhenTest()
    {
        $this->assertSame('Winner: foo bar', (string) $this->stringable('foo bar')->whenTest('/bar/', function ($stringable) {
            return $stringable->prepend('Winner: ');
        }, function ($stringable) {
            return 'Try again';
        }));

        $this->assertSame('Try again', (string) $this->stringable('foo bar')->whenTest('/link/', function ($stringable) {
            return $stringable->prepend('Winner: ');
        }, function ($stringable) {
            return 'Try again';
        }));

        $this->assertSame('foo bar', (string) $this->stringable('foo bar')->whenTest('/link/', function ($stringable) {
            return $stringable->prepend('Winner: ');
        }));
    }

    public function testWhenStartsWith()
    {
        $this->assertSame('Tony Stark', (string) $this->stringable('tony stark')->whenStartsWith('ton', function ($stringable) {
            return $stringable->title();
        }, function ($stringable) {
            return $stringable->studly();
        }));

        $this->assertSame('Tony Stark', (string) $this->stringable('tony stark')->whenStartsWith(['ton', 'not'], function ($stringable) {
            return $stringable->title();
        }, function ($stringable) {
            return $stringable->studly();
        }));

        $this->assertSame('tony stark', (string) $this->stringable('tony stark')->whenStartsWith(['xxx'], function ($stringable) {
            return $stringable->title();
        }));

        $this->assertSame('Tony Stark', (string) $this->stringable('tony stark')->whenStartsWith(['tony', 'xxx'], function ($stringable) {
            return $stringable->title();
        }, function ($stringable) {
            return $stringable->studly();
        }));
    }

    public function testWhenEmpty()
    {
        tap($this->stringable(), function ($stringable) {
            $this->assertSame($stringable, $stringable->whenEmpty(function () {
                //
            }));
        });

        $this->assertSame('empty', (string) $this->stringable()->whenEmpty(function () {
            return 'empty';
        }));

        $this->assertSame('not-empty', (string) $this->stringable('not-empty')->whenEmpty(function () {
            return 'empty';
        }));
    }

    public function testWhenNotEmpty()
    {
        tap($this->stringable(), function ($stringable) {
            $this->assertSame($stringable, $stringable->whenNotEmpty(function ($stringable) {
                return $stringable.'.';
            }));
        });

        $this->assertSame('', (string) $this->stringable()->whenNotEmpty(function ($stringable) {
            return $stringable.'.';
        }));

        $this->assertSame('Not empty.', (string) $this->stringable('Not empty')->whenNotEmpty(function ($stringable) {
            return $stringable.'.';
        }));
    }

    public function testWhenFalse()
    {
        $this->assertSame('when', (string) $this->stringable('when')->when(false, function ($stringable, $value) {
            return $stringable->append($value)->append('false');
        }));

        $this->assertSame('when false fallbacks to default', (string) $this->stringable('when false ')->when(false, function ($stringable, $value) {
            return $stringable->append($value);
        }, function ($stringable) {
            return $stringable->append('fallbacks to default');
        }));
    }

    public function testWhenTrue()
    {
        $this->assertSame('when true', (string) $this->stringable('when ')->when(true, function ($stringable) {
            return $stringable->append('true');
        }));

        $this->assertSame('gets a value from if', (string) $this->stringable('gets a value ')->when('from if', function ($stringable, $value) {
            return $stringable->append($value);
        }, function ($stringable) {
            return $stringable->append('fallbacks to default');
        }));
    }

    public function testUnlessTruthy()
    {
        $this->assertSame('unless', (string) $this->stringable('unless')->unless(1, function ($stringable, $value) {
            return $stringable->append($value)->append('true');
        }));

        $this->assertSame('unless true fallbacks to default with value 1',
            (string) $this->stringable('unless true ')->unless(1, function ($stringable, $value) {
                return $stringable->append($value);
            }, function ($stringable, $value) {
                return $stringable->append('fallbacks to default with value ')->append($value);
            }));
    }

    public function testUnlessFalsy()
    {
        $this->assertSame('unless 0', (string) $this->stringable('unless ')->unless(0, function ($stringable, $value) {
            return $stringable->append($value);
        }));

        $this->assertSame('gets the value 0',
            (string) $this->stringable('gets the value ')->unless(0, function ($stringable, $value) {
                return $stringable->append($value);
            }, function ($stringable) {
                return $stringable->append('fallbacks to default');
            }));
    }

    public function testTrimmedOnlyWhereNecessary()
    {
        $this->assertSame(' Taylor Otwell ', (string) $this->stringable(' Taylor Otwell ')->words(3));
        $this->assertSame(' Taylor...', (string) $this->stringable(' Taylor Otwell ')->words(1));
    }

    public function testTitle()
    {
        $this->assertSame('Jefferson Costella', (string) $this->stringable('jefferson costella')->title());
        $this->assertSame('Jefferson Costella', (string) $this->stringable('jefFErson coSTella')->title());
    }

    public function testWithoutWordsDoesntProduceError()
    {
        $nbsp = chr(0xC2).chr(0xA0);
        $this->assertSame(' ', (string) $this->stringable(' ')->words());
        $this->assertEquals($nbsp, (string) $this->stringable($nbsp)->words());
    }

    public function testAscii()
    {
        $this->assertSame('@', (string) $this->stringable('@')->ascii());
        $this->assertSame('u', (string) $this->stringable('ü')->ascii());
    }

    public function testNewLine()
    {
        $this->assertSame('Laravel'.PHP_EOL, (string) $this->stringable('Laravel')->newLine());
        $this->assertSame('foo'.PHP_EOL.PHP_EOL.'bar', (string) $this->stringable('foo')->newLine(2)->append('bar'));
    }

    public function testAsciiWithSpecificLocale()
    {
        $this->assertSame('h H sht Sht a A ia yo', (string) $this->stringable('х Х щ Щ ъ Ъ иа йо')->ascii('bg'));
        $this->assertSame('ae oe ue Ae Oe Ue', (string) $this->stringable('ä ö ü Ä Ö Ü')->ascii('de'));
    }

    public function testStartsWith()
    {
        $this->assertTrue($this->stringable('jason')->startsWith('jas'));
        $this->assertTrue($this->stringable('jason')->startsWith('jason'));
        $this->assertTrue($this->stringable('jason')->startsWith(['jas']));
        $this->assertTrue($this->stringable('jason')->startsWith(['day', 'jas']));
        $this->assertTrue($this->stringable('jason')->startsWith(collect(['day', 'jas'])));
        $this->assertFalse($this->stringable('jason')->startsWith('day'));
        $this->assertFalse($this->stringable('jason')->startsWith(['day']));
        $this->assertFalse($this->stringable('jason')->startsWith(null));
        $this->assertFalse($this->stringable('jason')->startsWith([null]));
        $this->assertFalse($this->stringable('0123')->startsWith([null]));
        $this->assertTrue($this->stringable('0123')->startsWith(0));
        $this->assertFalse($this->stringable('jason')->startsWith('J'));
        $this->assertFalse($this->stringable('jason')->startsWith(''));
        $this->assertFalse($this->stringable('7')->startsWith(' 7'));
        $this->assertTrue($this->stringable('7a')->startsWith('7'));
        $this->assertTrue($this->stringable('7a')->startsWith(7));
        $this->assertTrue($this->stringable('7.12a')->startsWith(7.12));
        $this->assertFalse($this->stringable('7.12a')->startsWith(7.13));
        $this->assertTrue($this->stringable(7.123)->startsWith('7'));
        $this->assertTrue($this->stringable(7.123)->startsWith('7.12'));
        $this->assertFalse($this->stringable(7.123)->startsWith('7.13'));
        // Test for multibyte string support
        $this->assertTrue($this->stringable('Jönköping')->startsWith('Jö'));
        $this->assertTrue($this->stringable('Malmö')->startsWith('Malmö'));
        $this->assertFalse($this->stringable('Jönköping')->startsWith('Jonko'));
        $this->assertFalse($this->stringable('Malmö')->startsWith('Malmo'));
    }

    public function testEndsWith()
    {
        $this->assertTrue($this->stringable('jason')->endsWith('on'));
        $this->assertTrue($this->stringable('jason')->endsWith('jason'));
        $this->assertTrue($this->stringable('jason')->endsWith(['on']));
        $this->assertTrue($this->stringable('jason')->endsWith(['no', 'on']));
        $this->assertTrue($this->stringable('jason')->endsWith(collect(['no', 'on'])));
        $this->assertFalse($this->stringable('jason')->endsWith('no'));
        $this->assertFalse($this->stringable('jason')->endsWith(['no']));
        $this->assertFalse($this->stringable('jason')->endsWith(''));
        $this->assertFalse($this->stringable('jason')->endsWith([null]));
        $this->assertFalse($this->stringable('jason')->endsWith(null));
        $this->assertFalse($this->stringable('jason')->endsWith('N'));
        $this->assertFalse($this->stringable('7')->endsWith(' 7'));
        $this->assertTrue($this->stringable('a7')->endsWith('7'));
        $this->assertTrue($this->stringable('a7')->endsWith(7));
        $this->assertTrue($this->stringable('a7.12')->endsWith(7.12));
        $this->assertFalse($this->stringable('a7.12')->endsWith(7.13));
        $this->assertTrue($this->stringable(0.27)->endsWith('7'));
        $this->assertTrue($this->stringable(0.27)->endsWith('0.27'));
        $this->assertFalse($this->stringable(0.27)->endsWith('8'));
        // Test for multibyte string support
        $this->assertTrue($this->stringable('Jönköping')->endsWith('öping'));
        $this->assertTrue($this->stringable('Malmö')->endsWith('mö'));
        $this->assertFalse($this->stringable('Jönköping')->endsWith('oping'));
        $this->assertFalse($this->stringable('Malmö')->endsWith('mo'));
    }

    public function testExcerpt()
    {
        $this->assertSame('...is a beautiful morn...', (string) $this->stringable('This is a beautiful morning')->excerpt('beautiful', ['radius' => 5]));
    }

    public function testBefore()
    {
        $this->assertSame('han', (string) $this->stringable('hannah')->before('nah'));
        $this->assertSame('ha', (string) $this->stringable('hannah')->before('n'));
        $this->assertSame('ééé ', (string) $this->stringable('ééé hannah')->before('han'));
        $this->assertSame('hannah', (string) $this->stringable('hannah')->before('xxxx'));
        $this->assertSame('hannah', (string) $this->stringable('hannah')->before(''));
        $this->assertSame('han', (string) $this->stringable('han0nah')->before('0'));
        $this->assertSame('han', (string) $this->stringable('han0nah')->before(0));
        $this->assertSame('han', (string) $this->stringable('han2nah')->before(2));
    }

    public function testBeforeLast()
    {
        $this->assertSame('yve', (string) $this->stringable('yvette')->beforeLast('tte'));
        $this->assertSame('yvet', (string) $this->stringable('yvette')->beforeLast('t'));
        $this->assertSame('ééé ', (string) $this->stringable('ééé yvette')->beforeLast('yve'));
        $this->assertSame('', (string) $this->stringable('yvette')->beforeLast('yve'));
        $this->assertSame('yvette', (string) $this->stringable('yvette')->beforeLast('xxxx'));
        $this->assertSame('yvette', (string) $this->stringable('yvette')->beforeLast(''));
        $this->assertSame('yv0et', (string) $this->stringable('yv0et0te')->beforeLast('0'));
        $this->assertSame('yv0et', (string) $this->stringable('yv0et0te')->beforeLast(0));
        $this->assertSame('yv2et', (string) $this->stringable('yv2et2te')->beforeLast(2));
    }

    public function testBetween()
    {
        $this->assertSame('abc', (string) $this->stringable('abc')->between('', 'c'));
        $this->assertSame('abc', (string) $this->stringable('abc')->between('a', ''));
        $this->assertSame('abc', (string) $this->stringable('abc')->between('', ''));
        $this->assertSame('b', (string) $this->stringable('abc')->between('a', 'c'));
        $this->assertSame('b', (string) $this->stringable('dddabc')->between('a', 'c'));
        $this->assertSame('b', (string) $this->stringable('abcddd')->between('a', 'c'));
        $this->assertSame('b', (string) $this->stringable('dddabcddd')->between('a', 'c'));
        $this->assertSame('nn', (string) $this->stringable('hannah')->between('ha', 'ah'));
        $this->assertSame('a]ab[b', (string) $this->stringable('[a]ab[b]')->between('[', ']'));
        $this->assertSame('foo', (string) $this->stringable('foofoobar')->between('foo', 'bar'));
        $this->assertSame('bar', (string) $this->stringable('foobarbar')->between('foo', 'bar'));
    }

    public function testBetweenFirst()
    {
        $this->assertSame('abc', (string) $this->stringable('abc')->betweenFirst('', 'c'));
        $this->assertSame('abc', (string) $this->stringable('abc')->betweenFirst('a', ''));
        $this->assertSame('abc', (string) $this->stringable('abc')->betweenFirst('', ''));
        $this->assertSame('b', (string) $this->stringable('abc')->betweenFirst('a', 'c'));
        $this->assertSame('b', (string) $this->stringable('dddabc')->betweenFirst('a', 'c'));
        $this->assertSame('b', (string) $this->stringable('abcddd')->betweenFirst('a', 'c'));
        $this->assertSame('b', (string) $this->stringable('dddabcddd')->betweenFirst('a', 'c'));
        $this->assertSame('nn', (string) $this->stringable('hannah')->betweenFirst('ha', 'ah'));
        $this->assertSame('a', (string) $this->stringable('[a]ab[b]')->betweenFirst('[', ']'));
        $this->assertSame('foo', (string) $this->stringable('foofoobar')->betweenFirst('foo', 'bar'));
        $this->assertSame('', (string) $this->stringable('foobarbar')->betweenFirst('foo', 'bar'));
    }

    public function testAfter()
    {
        $this->assertSame('nah', (string) $this->stringable('hannah')->after('han'));
        $this->assertSame('nah', (string) $this->stringable('hannah')->after('n'));
        $this->assertSame('nah', (string) $this->stringable('ééé hannah')->after('han'));
        $this->assertSame('hannah', (string) $this->stringable('hannah')->after('xxxx'));
        $this->assertSame('hannah', (string) $this->stringable('hannah')->after(''));
        $this->assertSame('nah', (string) $this->stringable('han0nah')->after('0'));
        $this->assertSame('nah', (string) $this->stringable('han0nah')->after(0));
        $this->assertSame('nah', (string) $this->stringable('han2nah')->after(2));
    }

    public function testAfterLast()
    {
        $this->assertSame('tte', (string) $this->stringable('yvette')->afterLast('yve'));
        $this->assertSame('e', (string) $this->stringable('yvette')->afterLast('t'));
        $this->assertSame('e', (string) $this->stringable('ééé yvette')->afterLast('t'));
        $this->assertSame('', (string) $this->stringable('yvette')->afterLast('tte'));
        $this->assertSame('yvette', (string) $this->stringable('yvette')->afterLast('xxxx'));
        $this->assertSame('yvette', (string) $this->stringable('yvette')->afterLast(''));
        $this->assertSame('te', (string) $this->stringable('yv0et0te')->afterLast('0'));
        $this->assertSame('te', (string) $this->stringable('yv0et0te')->afterLast(0));
        $this->assertSame('te', (string) $this->stringable('yv2et2te')->afterLast(2));
        $this->assertSame('foo', (string) $this->stringable('----foo')->afterLast('---'));
    }

    public function testContains()
    {
        $this->assertTrue($this->stringable('taylor')->contains('ylo'));
        $this->assertTrue($this->stringable('taylor')->contains('taylor'));
        $this->assertTrue($this->stringable('taylor')->contains(['ylo']));
        $this->assertTrue($this->stringable('taylor')->contains(['xxx', 'ylo']));
        $this->assertTrue($this->stringable('taylor')->contains(collect(['xxx', 'ylo'])));
        $this->assertTrue($this->stringable('taylor')->contains(['LOR'], true));
        $this->assertFalse($this->stringable('taylor')->contains('xxx'));
        $this->assertFalse($this->stringable('taylor')->contains(['xxx']));
        $this->assertFalse($this->stringable('taylor')->contains(''));
    }

    public function testContainsAll()
    {
        $this->assertTrue($this->stringable('taylor otwell')->containsAll(['taylor', 'otwell']));
        $this->assertTrue($this->stringable('taylor otwell')->containsAll(['TAYLOR', 'OTWELL'], true));
        $this->assertTrue($this->stringable('taylor otwell')->containsAll(collect(['taylor', 'otwell'])));
        $this->assertTrue($this->stringable('taylor otwell')->containsAll(['taylor']));
        $this->assertFalse($this->stringable('taylor otwell')->containsAll(['taylor', 'xxx']));
    }

    public function testParseCallback()
    {
        $this->assertEquals(['Class', 'method'], $this->stringable('Class@method')->parseCallback('foo'));
        $this->assertEquals(['Class', 'foo'], $this->stringable('Class')->parseCallback('foo'));
        $this->assertEquals(['Class', null], $this->stringable('Class')->parseCallback());
    }

    public function testSlug()
    {
        $this->assertSame('hello-world', (string) $this->stringable('hello world')->slug());
        $this->assertSame('hello-world', (string) $this->stringable('hello-world')->slug());
        $this->assertSame('hello-world', (string) $this->stringable('hello_world')->slug());
        $this->assertSame('hello_world', (string) $this->stringable('hello_world')->slug('_'));
        $this->assertSame('user-at-host', (string) $this->stringable('user@host')->slug());
        $this->assertSame('سلام-دنیا', (string) $this->stringable('سلام دنیا')->slug('-', null));
        $this->assertSame('sometext', (string) $this->stringable('some text')->slug(''));
        $this->assertSame('', (string) $this->stringable('')->slug(''));
        $this->assertSame('', (string) $this->stringable('')->slug());
    }

    public function testSquish()
    {
        $this->assertSame('words with spaces', (string) $this->stringable(' words  with   spaces ')->squish());
        $this->assertSame('words with spaces', (string) $this->stringable("words\t\twith\n\nspaces")->squish());
        $this->assertSame('words with spaces', (string) $this->stringable('
            words
            with
            spaces
        ')->squish());
        $this->assertSame('laravel php framework', (string) $this->stringable('   laravel   php   framework   ')->squish());
        $this->assertSame('123', (string) $this->stringable('   123    ')->squish());
        $this->assertSame('だ', (string) $this->stringable('だ')->squish());
        $this->assertSame('ム', (string) $this->stringable('ム')->squish());
        $this->assertSame('だ', (string) $this->stringable('   だ    ')->squish());
        $this->assertSame('ム', (string) $this->stringable('   ム    ')->squish());
        $this->assertSame('ム', (string) $this->stringable('   ム    ')->squish());
    }

    public function testStart()
    {
        $this->assertSame('/test/string', (string) $this->stringable('test/string')->start('/'));
        $this->assertSame('/test/string', (string) $this->stringable('/test/string')->start('/'));
        $this->assertSame('/test/string', (string) $this->stringable('//test/string')->start('/'));
    }

    public function testFinish()
    {
        $this->assertSame('abbc', (string) $this->stringable('ab')->finish('bc'));
        $this->assertSame('abbc', (string) $this->stringable('abbcbc')->finish('bc'));
        $this->assertSame('abcbbc', (string) $this->stringable('abcbbcbc')->finish('bc'));
    }

    public function testIs()
    {
        $this->assertTrue($this->stringable('/')->is('/'));
        $this->assertFalse($this->stringable('/')->is(' /'));
        $this->assertFalse($this->stringable('/a')->is('/'));
        $this->assertTrue($this->stringable('foo/bar/baz')->is('foo/*'));

        $this->assertTrue($this->stringable('App\Class@method')->is('*@*'));
        $this->assertTrue($this->stringable('app\Class@')->is('*@*'));
        $this->assertTrue($this->stringable('@method')->is('*@*'));

        // is case sensitive
        $this->assertFalse($this->stringable('foo/bar/baz')->is('*BAZ*'));
        $this->assertFalse($this->stringable('foo/bar/baz')->is('*FOO*'));
        $this->assertFalse($this->stringable('a')->is('A'));

        // Accepts array of patterns
        $this->assertTrue($this->stringable('a/')->is(['a*', 'b*']));
        $this->assertTrue($this->stringable('b/')->is(['a*', 'b*']));
        $this->assertFalse($this->stringable('f/')->is(['a*', 'b*']));

        // numeric values and patterns
        $this->assertFalse($this->stringable(123)->is(['a*', 'b*']));
        $this->assertTrue($this->stringable(11211)->is(['*2*', 'b*']));

        $this->assertTrue($this->stringable('blah/baz/foo')->is('*/foo'));

        $valueObject = new StringableObjectStub('foo/bar/baz');
        $patternObject = new StringableObjectStub('foo/*');

        $this->assertTrue($this->stringable($valueObject)->is('foo/bar/baz'));
        $this->assertTrue($this->stringable($valueObject)->is($patternObject));

        // empty patterns
        $this->assertFalse($this->stringable('test')->is([]));
    }

    public function testKebab()
    {
        $this->assertSame('laravel-php-framework', (string) $this->stringable('LaravelPhpFramework')->kebab());
    }

    public function testLower()
    {
        $this->assertSame('foo bar baz', (string) $this->stringable('FOO BAR BAZ')->lower());
        $this->assertSame('foo bar baz', (string) $this->stringable('fOo Bar bAz')->lower());
    }

    public function testUpper()
    {
        $this->assertSame('FOO BAR BAZ', (string) $this->stringable('foo bar baz')->upper());
        $this->assertSame('FOO BAR BAZ', (string) $this->stringable('foO bAr BaZ')->upper());
    }

    public function testLimit()
    {
        $this->assertSame('Laravel is...',
            (string) $this->stringable('Laravel is a free, open source PHP web application framework.')->limit(10)
        );
        $this->assertSame('这是一...', (string) $this->stringable('这是一段中文')->limit(6));

        $string = 'The PHP framework for web artisans.';
        $this->assertSame('The PHP...', (string) $this->stringable($string)->limit(7));
        $this->assertSame('The PHP', (string) $this->stringable($string)->limit(7, ''));
        $this->assertSame('The PHP framework for web artisans.', (string) $this->stringable($string)->limit(100));

        $nonAsciiString = '这是一段中文';
        $this->assertSame('这是一...', (string) $this->stringable($nonAsciiString)->limit(6));
        $this->assertSame('这是一', (string) $this->stringable($nonAsciiString)->limit(6, ''));
    }

    public function testLength()
    {
        $this->assertSame(11, $this->stringable('foo bar baz')->length());
        $this->assertSame(11, $this->stringable('foo bar baz')->length('UTF-8'));
    }

    public function testReplace()
    {
        $this->assertSame('foo/foo/foo', (string) $this->stringable('?/?/?')->replace('?', 'foo'));
        $this->assertSame('bar/bar', (string) $this->stringable('?/?')->replace('?', 'bar'));
        $this->assertSame('?/?/?', (string) $this->stringable('? ? ?')->replace(' ', '/'));
        $this->assertSame('foo/bar/baz/bam', (string) $this->stringable('?1/?2/?3/?4')->replace(['?1', '?2', '?3', '?4'], ['foo', 'bar', 'baz', 'bam']));
        $this->assertSame('foo/bar/baz/bam', (string) $this->stringable('?1/?2/?3/?4')->replace(collect(['?1', '?2', '?3', '?4']), collect(['foo', 'bar', 'baz', 'bam'])));
    }

    public function testReplaceArray()
    {
        $this->assertSame('foo/bar/baz', (string) $this->stringable('?/?/?')->replaceArray('?', ['foo', 'bar', 'baz']));
        $this->assertSame('foo/bar/baz/?', (string) $this->stringable('?/?/?/?')->replaceArray('?', ['foo', 'bar', 'baz']));
        $this->assertSame('foo/bar', (string) $this->stringable('?/?')->replaceArray('?', ['foo', 'bar', 'baz']));
        $this->assertSame('?/?/?', (string) $this->stringable('?/?/?')->replaceArray('x', ['foo', 'bar', 'baz']));
        $this->assertSame('foo?/bar/baz', (string) $this->stringable('?/?/?')->replaceArray('?', ['foo?', 'bar', 'baz']));
        $this->assertSame('foo/bar', (string) $this->stringable('?/?')->replaceArray('?', [1 => 'foo', 2 => 'bar']));
        $this->assertSame('foo/bar', (string) $this->stringable('?/?')->replaceArray('?', ['x' => 'foo', 'y' => 'bar']));
        $this->assertSame('foo/bar', (string) $this->stringable('?/?')->replaceArray('?', collect(['x' => 'foo', 'y' => 'bar'])));
    }

    public function testReplaceFirst()
    {
        $this->assertSame('fooqux foobar', (string) $this->stringable('foobar foobar')->replaceFirst('bar', 'qux'));
        $this->assertSame('foo/qux? foo/bar?', (string) $this->stringable('foo/bar? foo/bar?')->replaceFirst('bar?', 'qux?'));
        $this->assertSame('foo foobar', (string) $this->stringable('foobar foobar')->replaceFirst('bar', ''));
        $this->assertSame('foobar foobar', (string) $this->stringable('foobar foobar')->replaceFirst('xxx', 'yyy'));
        $this->assertSame('foobar foobar', (string) $this->stringable('foobar foobar')->replaceFirst('', 'yyy'));
        // Test for multibyte string support
        $this->assertSame('Jxxxnköping Malmö', (string) $this->stringable('Jönköping Malmö')->replaceFirst('ö', 'xxx'));
        $this->assertSame('Jönköping Malmö', (string) $this->stringable('Jönköping Malmö')->replaceFirst('', 'yyy'));
    }

    public function testReplaceLast()
    {
        $this->assertSame('foobar fooqux', (string) $this->stringable('foobar foobar')->replaceLast('bar', 'qux'));
        $this->assertSame('foo/bar? foo/qux?', (string) $this->stringable('foo/bar? foo/bar?')->replaceLast('bar?', 'qux?'));
        $this->assertSame('foobar foo', (string) $this->stringable('foobar foobar')->replaceLast('bar', ''));
        $this->assertSame('foobar foobar', (string) $this->stringable('foobar foobar')->replaceLast('xxx', 'yyy'));
        $this->assertSame('foobar foobar', (string) $this->stringable('foobar foobar')->replaceLast('', 'yyy'));
        // Test for multibyte string support
        $this->assertSame('Malmö Jönkxxxping', (string) $this->stringable('Malmö Jönköping')->replaceLast('ö', 'xxx'));
        $this->assertSame('Malmö Jönköping', (string) $this->stringable('Malmö Jönköping')->replaceLast('', 'yyy'));
    }

    public function testRemove()
    {
        $this->assertSame('Fbar', (string) $this->stringable('Foobar')->remove('o'));
        $this->assertSame('Foo', (string) $this->stringable('Foobar')->remove('bar'));
        $this->assertSame('oobar', (string) $this->stringable('Foobar')->remove('F'));
        $this->assertSame('Foobar', (string) $this->stringable('Foobar')->remove('f'));
        $this->assertSame('oobar', (string) $this->stringable('Foobar')->remove('f', false));

        $this->assertSame('Fbr', (string) $this->stringable('Foobar')->remove(['o', 'a']));
        $this->assertSame('Fbr', (string) $this->stringable('Foobar')->remove(collect(['o', 'a'])));
        $this->assertSame('Fooar', (string) $this->stringable('Foobar')->remove(['f', 'b']));
        $this->assertSame('ooar', (string) $this->stringable('Foobar')->remove(['f', 'b'], false));
        $this->assertSame('Foobar', (string) $this->stringable('Foo|bar')->remove(['f', '|']));
    }

    public function testReverse()
    {
        $this->assertSame('FooBar', (string) $this->stringable('raBooF')->reverse());
        $this->assertSame('Teniszütő', (string) $this->stringable('őtüzsineT')->reverse());
        $this->assertSame('❤MultiByte☆', (string) $this->stringable('☆etyBitluM❤')->reverse());
    }

    public function testSnake()
    {
        $this->assertSame('laravel_p_h_p_framework', (string) $this->stringable('LaravelPHPFramework')->snake());
        $this->assertSame('laravel_php_framework', (string) $this->stringable('LaravelPhpFramework')->snake());
        $this->assertSame('laravel php framework', (string) $this->stringable('LaravelPhpFramework')->snake(' '));
        $this->assertSame('laravel_php_framework', (string) $this->stringable('Laravel Php Framework')->snake());
        $this->assertSame('laravel_php_framework', (string) $this->stringable('Laravel    Php      Framework   ')->snake());
        // ensure cache keys don't overlap
        $this->assertSame('laravel__php__framework', (string) $this->stringable('LaravelPhpFramework')->snake('__'));
        $this->assertSame('laravel_php_framework_', (string) $this->stringable('LaravelPhpFramework_')->snake('_'));
        $this->assertSame('laravel_php_framework', (string) $this->stringable('laravel php Framework')->snake());
        $this->assertSame('laravel_php_frame_work', (string) $this->stringable('laravel php FrameWork')->snake());
        // prevent breaking changes
        $this->assertSame('foo-bar', (string) $this->stringable('foo-bar')->snake());
        $this->assertSame('foo-_bar', (string) $this->stringable('Foo-Bar')->snake());
        $this->assertSame('foo__bar', (string) $this->stringable('Foo_Bar')->snake());
        $this->assertSame('żółtałódka', (string) $this->stringable('ŻółtaŁódka')->snake());
    }

    public function testStudly()
    {
        $this->assertSame('LaravelPHPFramework', (string) $this->stringable('laravel_p_h_p_framework')->studly());
        $this->assertSame('LaravelPhpFramework', (string) $this->stringable('laravel_php_framework')->studly());
        $this->assertSame('LaravelPhPFramework', (string) $this->stringable('laravel-phP-framework')->studly());
        $this->assertSame('LaravelPhpFramework', (string) $this->stringable('laravel  -_-  php   -_-   framework   ')->studly());

        $this->assertSame('FooBar', (string) $this->stringable('fooBar')->studly());
        $this->assertSame('FooBar', (string) $this->stringable('foo_bar')->studly());
        $this->assertSame('FooBar', (string) $this->stringable('foo_bar')->studly()); // test cache
        $this->assertSame('FooBarBaz', (string) $this->stringable('foo-barBaz')->studly());
        $this->assertSame('FooBarBaz', (string) $this->stringable('foo-bar_baz')->studly());
    }

    public function testCamel()
    {
        $this->assertSame('laravelPHPFramework', (string) $this->stringable('Laravel_p_h_p_framework')->camel());
        $this->assertSame('laravelPhpFramework', (string) $this->stringable('Laravel_php_framework')->camel());
        $this->assertSame('laravelPhPFramework', (string) $this->stringable('Laravel-phP-framework')->camel());
        $this->assertSame('laravelPhpFramework', (string) $this->stringable('Laravel  -_-  php   -_-   framework   ')->camel());

        $this->assertSame('fooBar', (string) $this->stringable('FooBar')->camel());
        $this->assertSame('fooBar', (string) $this->stringable('foo_bar')->camel());
        $this->assertSame('fooBar', (string) $this->stringable('foo_bar')->camel()); // test cache
        $this->assertSame('fooBarBaz', (string) $this->stringable('Foo-barBaz')->camel());
        $this->assertSame('fooBarBaz', (string) $this->stringable('foo-bar_baz')->camel());
    }

    public function testSubstr()
    {
        $this->assertSame('Ё', (string) $this->stringable('БГДЖИЛЁ')->substr(-1));
        $this->assertSame('ЛЁ', (string) $this->stringable('БГДЖИЛЁ')->substr(-2));
        $this->assertSame('И', (string) $this->stringable('БГДЖИЛЁ')->substr(-3, 1));
        $this->assertSame('ДЖИЛ', (string) $this->stringable('БГДЖИЛЁ')->substr(2, -1));
        $this->assertSame('', (string) $this->stringable('БГДЖИЛЁ')->substr(4, -4));
        $this->assertSame('ИЛ', (string) $this->stringable('БГДЖИЛЁ')->substr(-3, -1));
        $this->assertSame('ГДЖИЛЁ', (string) $this->stringable('БГДЖИЛЁ')->substr(1));
        $this->assertSame('ГДЖ', (string) $this->stringable('БГДЖИЛЁ')->substr(1, 3));
        $this->assertSame('БГДЖ', (string) $this->stringable('БГДЖИЛЁ')->substr(0, 4));
        $this->assertSame('Ё', (string) $this->stringable('БГДЖИЛЁ')->substr(-1, 1));
        $this->assertSame('', (string) $this->stringable('Б')->substr(2));
    }

    public function testSwap()
    {
        $this->assertSame('PHP 8 is fantastic', (string) $this->stringable('PHP is awesome')->swap([
            'PHP' => 'PHP 8',
            'awesome' => 'fantastic',
        ]));
    }

    public function testSubstrCount()
    {
        $this->assertSame(3, $this->stringable('laravelPHPFramework')->substrCount('a'));
        $this->assertSame(0, $this->stringable('laravelPHPFramework')->substrCount('z'));
        $this->assertSame(1, $this->stringable('laravelPHPFramework')->substrCount('l', 2));
        $this->assertSame(0, $this->stringable('laravelPHPFramework')->substrCount('z', 2));
        $this->assertSame(1, $this->stringable('laravelPHPFramework')->substrCount('k', -1));
        $this->assertSame(1, $this->stringable('laravelPHPFramework')->substrCount('k', -1));
        $this->assertSame(1, $this->stringable('laravelPHPFramework')->substrCount('a', 1, 2));
        $this->assertSame(1, $this->stringable('laravelPHPFramework')->substrCount('a', 1, 2));
        $this->assertSame(3, $this->stringable('laravelPHPFramework')->substrCount('a', 1, -2));
        $this->assertSame(1, $this->stringable('laravelPHPFramework')->substrCount('a', -10, -3));
    }

    public function testSubstrReplace()
    {
        $this->assertSame('12:00', (string) $this->stringable('1200')->substrReplace(':', 2, 0));
        $this->assertSame('The Laravel Framework', (string) $this->stringable('The Framework')->substrReplace('Laravel ', 4, 0));
        $this->assertSame('Laravel – The PHP Framework for Web Artisans', (string) $this->stringable('Laravel Framework')->substrReplace('– The PHP Framework for Web Artisans', 8));
    }

    public function testPadBoth()
    {
        $this->assertSame('__Alien___', (string) $this->stringable('Alien')->padBoth(10, '_'));
        $this->assertSame('  Alien   ', (string) $this->stringable('Alien')->padBoth(10));
        $this->assertSame('  ❤MultiByte☆   ', (string) $this->stringable('❤MultiByte☆')->padBoth(16));
    }

    public function testPadLeft()
    {
        $this->assertSame('-=-=-Alien', (string) $this->stringable('Alien')->padLeft(10, '-='));
        $this->assertSame('     Alien', (string) $this->stringable('Alien')->padLeft(10));
        $this->assertSame('     ❤MultiByte☆', (string) $this->stringable('❤MultiByte☆')->padLeft(16));
    }

    public function testPadRight()
    {
        $this->assertSame('Alien-----', (string) $this->stringable('Alien')->padRight(10, '-'));
        $this->assertSame('Alien     ', (string) $this->stringable('Alien')->padRight(10));
        $this->assertSame('❤MultiByte☆     ', (string) $this->stringable('❤MultiByte☆')->padRight(16));
    }

    public function testExplode()
    {
        $this->assertInstanceOf(Collection::class, $this->stringable('Foo Bar Baz')->explode(' '));

        $this->assertSame('["Foo","Bar","Baz"]', (string) $this->stringable('Foo Bar Baz')->explode(' '));

        //  with limit
        $this->assertSame('["Foo","Bar Baz"]', (string) $this->stringable('Foo Bar Baz')->explode(' ', 2));
        $this->assertSame('["Foo","Bar"]', (string) $this->stringable('Foo Bar Baz')->explode(' ', -1));
    }

    public function testChunk()
    {
        $chunks = $this->stringable('foobarbaz')->split(3);

        $this->assertInstanceOf(Collection::class, $chunks);
        $this->assertSame(['foo', 'bar', 'baz'], $chunks->all());
    }

    public function testJsonSerialize()
    {
        $this->assertSame('"foo"', json_encode($this->stringable('foo')));
        $this->assertSame('"laravel-php-framework"', json_encode($this->stringable('LaravelPhpFramework')->kebab()));
        $this->assertSame('["laravel-php-framework"]', json_encode([$this->stringable('LaravelPhpFramework')->kebab()]));
        $this->assertSame('{"title":"laravel-php-framework"}', json_encode(['title' => $this->stringable('LaravelPhpFramework')->kebab()]));
    }

    public function testTap()
    {
        $stringable = $this->stringable('foobarbaz');

        $fromTheTap = '';

        $stringable = $stringable->tap(function (Stringable $string) use (&$fromTheTap) {
            $fromTheTap = $string->substr(0, 3);
        });

        $this->assertSame('foo', (string) $fromTheTap);
        $this->assertSame('foobarbaz', (string) $stringable);
    }

    public function testPipe()
    {
        $callback = function ($stringable) {
            return 'bar';
        };

        $this->assertInstanceOf(Stringable::class, $this->stringable('foo')->pipe($callback));
        $this->assertSame('bar', (string) $this->stringable('foo')->pipe($callback));
    }

    public function testMarkdown()
    {
        $this->assertEquals("<p><em>hello world</em></p>\n", $this->stringable('*hello world*')->markdown());
        $this->assertEquals("<h1>hello world</h1>\n", $this->stringable('# hello world')->markdown());
    }

    public function testInlineMarkdown()
    {
        $this->assertEquals("<em>hello world</em>\n", $this->stringable('*hello world*')->inlineMarkdown());
        $this->assertEquals("<a href=\"https://laravel.com\"><strong>Laravel</strong></a>\n", $this->stringable('[**Laravel**](https://laravel.com)')->inlineMarkdown());
    }

    public function testMask()
    {
        $this->assertSame('tay*************', (string) $this->stringable('taylor@email.com')->mask('*', 3));
        $this->assertSame('******@email.com', (string) $this->stringable('taylor@email.com')->mask('*', 0, 6));
        $this->assertSame('tay*************', (string) $this->stringable('taylor@email.com')->mask('*', -13));
        $this->assertSame('tay***@email.com', (string) $this->stringable('taylor@email.com')->mask('*', -13, 3));

        $this->assertSame('****************', (string) $this->stringable('taylor@email.com')->mask('*', -17));
        $this->assertSame('*****r@email.com', (string) $this->stringable('taylor@email.com')->mask('*', -99, 5));

        $this->assertSame('taylor@email.com', (string) $this->stringable('taylor@email.com')->mask('*', 16));
        $this->assertSame('taylor@email.com', (string) $this->stringable('taylor@email.com')->mask('*', 16, 99));

        $this->assertSame('taylor@email.com', (string) $this->stringable('taylor@email.com')->mask('', 3));

        $this->assertSame('taysssssssssssss', (string) $this->stringable('taylor@email.com')->mask('something', 3));

        $this->assertSame('这是一***', (string) $this->stringable('这是一段中文')->mask('*', 3));
        $this->assertSame('**一段中文', (string) $this->stringable('这是一段中文')->mask('*', 0, 2));
    }

    public function testRepeat()
    {
        $this->assertSame('aaaaa', (string) $this->stringable('a')->repeat(5));
        $this->assertSame('', (string) $this->stringable('')->repeat(5));
    }

    public function testWordCount()
    {
        $this->assertEquals(2, $this->stringable('Hello, world!')->wordCount());
        $this->assertEquals(10, $this->stringable('Hi, this is my first contribution to the Laravel framework.')->wordCount());
    }

    public function testWrap()
    {
        $this->assertEquals('This is me!', $this->stringable('is')->wrap('This ', ' me!'));
        $this->assertEquals('"value"', $this->stringable('value')->wrap('"'));
    }

    public function testToHtmlString()
    {
        $this->assertEquals(
            new HtmlString('<h1>Test String</h1>'),
            $this->stringable('<h1>Test String</h1>')->toHtmlString()
        );
    }

    public function testStripTags()
    {
        $this->assertSame('beforeafter', (string) $this->stringable('before<br>after')->stripTags());
        $this->assertSame('before<br>after', (string) $this->stringable('before<br>after')->stripTags('<br>'));
        $this->assertSame('before<br>after', (string) $this->stringable('<strong>before</strong><br>after')->stripTags('<br>'));
        $this->assertSame('<strong>before</strong><br>after', (string) $this->stringable('<strong>before</strong><br>after')->stripTags('<br><strong>'));
    }

    public function testScan()
    {
        $this->assertSame([123456], $this->stringable('SN/123456')->scan('SN/%d')->toArray());
        $this->assertSame(['Otwell', 'Taylor'], $this->stringable('Otwell, Taylor')->scan('%[^,],%s')->toArray());
        $this->assertSame(['filename', 'jpg'], $this->stringable('filename.jpg')->scan('%[^.].%s')->toArray());
    }

    public function testGet()
    {
        $this->assertSame('foo', $this->stringable('foo')->value());
        $this->assertSame('foo', $this->stringable('foo')->toString());
    }

    public function testExactly()
    {
        $this->assertTrue($this->stringable('foo')->exactly($this->stringable('foo')));
        $this->assertTrue($this->stringable('foo')->exactly('foo'));

        $this->assertFalse($this->stringable('Foo')->exactly($this->stringable('foo')));
        $this->assertFalse($this->stringable('Foo')->exactly('foo'));
        $this->assertFalse($this->stringable('[]')->exactly([]));
        $this->assertFalse($this->stringable('0')->exactly(0));
    }

    public function testToInteger()
    {
        $this->assertSame(123, $this->stringable('123')->toInteger());
        $this->assertSame(456, $this->stringable(456)->toInteger());
        $this->assertSame(78, $this->stringable('078')->toInteger());
        $this->assertSame(901, $this->stringable(' 901')->toInteger());
        $this->assertSame(0, $this->stringable('nan')->toInteger());
        $this->assertSame(1, $this->stringable('1ab')->toInteger());
        $this->assertSame(2, $this->stringable('2_000')->toInteger());
    }

    public function testToFloat()
    {
        $this->assertSame(1.23, $this->stringable('1.23')->toFloat());
        $this->assertSame(45.6, $this->stringable(45.6)->toFloat());
        $this->assertSame(.6, $this->stringable('.6')->toFloat());
        $this->assertSame(0.78, $this->stringable('0.78')->toFloat());
        $this->assertSame(90.1, $this->stringable(' 90.1')->toFloat());
        $this->assertSame(0.0, $this->stringable('nan')->toFloat());
        $this->assertSame(1.0, $this->stringable('1.ab')->toFloat());
        $this->assertSame(1e3, $this->stringable('1e3')->toFloat());
    }

    public function testBooleanMethod()
    {
        $this->assertTrue($this->stringable(true)->toBoolean());
        $this->assertTrue($this->stringable('true')->toBoolean());
        $this->assertFalse($this->stringable('false')->toBoolean());
        $this->assertTrue($this->stringable('1')->toBoolean());
        $this->assertFalse($this->stringable('0')->toBoolean());
        $this->assertTrue($this->stringable('on')->toBoolean());
        $this->assertFalse($this->stringable('off')->toBoolean());
        $this->assertTrue($this->stringable('yes')->toBoolean());
        $this->assertFalse($this->stringable('no')->toBoolean());
    }

    public function testToDate()
    {
        $current = Carbon::create(2020, 1, 1, 16, 30, 25);

        $this->assertEquals($current, $this->stringable('20-01-01 16:30:25')->toDate());
        $this->assertEquals($current, $this->stringable('1577896225')->toDate('U'));
        $this->assertEquals($current, $this->stringable('20-01-01 13:30:25')->toDate(null, 'America/Santiago'));

        $this->assertTrue($this->stringable('2020-01-01')->toDate()->isSameDay($current));
        $this->assertTrue($this->stringable('16:30:25')->toDate()->isSameSecond('16:30:25'));
    }

    public function testToDateThrowsException()
    {
        $this->expectException(\Carbon\Exceptions\InvalidFormatException::class);

        $this->stringable('not a date')->toDate();
    }
}


text:
package com.orientechnologies.orient.core.command;

public interface OCommandRequestAsynch {
	public OCommandResultListener getResultListener();

	public void setResultListener(OCommandResultListener iListener);
}

redpajama_set_name: RedPajamaGithub


text:
using System;
using Org.Apache.Reef.Utilities.Diagnostics;
using Org.Apache.Reef.Utilities.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Org.Apache.Reef.Test.Utility.Test
{
    [TestClass]
    public class TestExceptions
    {
        private static readonly Logger LOGGER = Logger.GetLogger(typeof(TestExceptions));

        [TestMethod]
        public void TestThrowCaught()
        {
            string msg = null;
            try
            {
                Exceptions.Throw(new ApplicationException("test"), LOGGER);
                msg = "not supposed to reach here";
                Assert.Fail(msg);
            }
            catch (ApplicationException e)
            {
                Exceptions.Caught(e, Level.Info, LOGGER);
            }
            Assert.IsNull(msg);
        }
    }
}


text:
package org.apache.tools.ant.gui.event;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.gui.core.AppContext;

/**
 * Build started. This event is a duplication of the information posted as
 * an AntBuildEvent when a build starts.
 *
 * @version $Revision: 1.1.1.1 $
 * @author Simeon Fitch
 */
public class BuildStartedEvent extends AntEvent {

    /** The originating event from Ant. */
    private BuildEvent _orig = null;

	/**
	 * Standard ctor.
	 *
	 * @param context The application context.
	 * @param orig The originating event.
	 */
    public BuildStartedEvent(AppContext context, BuildEvent orig) {
        super(context);
        _orig = orig;
    }

	/**
	 * Get the originating event.
	 *
	 * @return Originating event.
	 */
    public BuildEvent getBuildEvent() {
        return _orig;
    }

}


text:
<?php session_start(); ?>
<?php
$org=0;
if(isset($_SESSION['org'])) $org=$_SESSION['org'];
if(isset($_SESSION['security'])){
 if (!($_SESSION['security'] & 128)) {die("Secruity level too low for this page");}
}else{
 header('Location: Login.php');
 die("Please logon");
}
?>
<!DOCTYPE HTML>

<meta name="viewport" content="width=device-width">
<meta name="viewport" content="initial-scale=1.0">

<link rel="stylesheet" type="text/css" href="styletable1.css">

<?php $inc = "./orgs/" . $org . "/heading3.txt"; include $inc; ?>
<?php
include 'timehelpers.php';
function dtfmt($dt)
{
	if (substr($dt,0,4) != '0000')
		return substr($dt,8,2).'/'.substr($dt,5,2).'/'.substr($dt,0,4);
	else
		return '';
}
$DEBUG=0;
$diagtext="";
$pageid=2;
$pkcol=1;
$pagesortdata = $_SESSION['pagesortdata'];
$colsort = $pagesortdata[$pageid];
if ($_SERVER["REQUEST_METHOD"] == "GET")
{
 if(isset($_GET['col']))
 {
  if($_GET['col'] != "" && $_GET['col'] != null)
  {
   $colsort = $_GET['col'];
   $pagesortdata[$pageid] = $colsort;
   $_SESSION['pagesortdata'] = $pagesortdata;
  }
 }
}
if ($colsort == 0)
 	$colsort = $pkcol;
?>

<?php
if (true){echo '";echo "ORG NUM";echo "	";}
if (true){echo '";echo "NAME";echo "	";}
if (true){echo '";echo "ADDR1";echo "	";}
if (true){echo '";echo "ADDR2";echo "	";}
if (true){echo '";echo "ADDR3";echo "	";}
if (true){echo '";echo "ADDR4";echo "	";}
if (true){echo '";echo "COUNTRY";echo "	";}
if (true){echo '";echo "CONTACT NAME";echo "	";}
if (true){echo '";echo "EMAIL";echo "	";}
if (true){echo '";echo "TIMEZONE";echo "	";}
if (true){echo '";echo "AIRCRAFT PREFIX";echo "	";}
if (true){echo '";echo "HEIGHT BASED TOW CHARGING";echo "	";}
if (true){echo '";echo "TIME BASED TOW CHARGING";echo "	";}
if (true){echo '";echo "DEFAULT LOCATION";echo "	";}
if (true){echo '";echo "NAME OF OTHER CHARGES";echo "	";}
if (true){echo '";echo "DEFAULT TRACK LATITUDE";echo "	";}
if (true){echo '";echo "DEFAULT TRACK LONGITUDE";echo "	";}
if (true){echo '";echo "MAP CENTRE LATITUDE";echo "	";}
if (true){echo '";echo "MAP CENTRE LONGITUDE";echo "	";}
if (true){echo '";echo "TWITTER CONSUMER KEY";echo "	";}
if (true){echo '";echo "TWITTER CONSUMER SECRET";echo "	";}
if (true){echo '";echo "TWITTER ACCESS TOKEN";echo "	";}
if (true){echo '";echo "TWITTER ACCESS TOKEN SECRET";echo "	";}
?>

<?php
$con_params = require('./config/database.php'); $con_params = $con_params['gliding'];
$con=mysqli_connect($con_params['hostname'],$con_params['username'],$con_params['password'],$con_params['dbname']);
if (mysqli_connect_errno())
{
 echo "
Unable to connect to database
";
}
$sql= "SELECT organisations.id,organisations.name,organisations.addr1,organisations.addr2,organisations.addr3,organisations.addr4,organisations.country,organisations.contact_name,organisations.email,organisations.timezone,organisations.aircraft_prefix,organisations.tow_height_charging,organisations.tow_time_based,organisations.default_location,organisations.name_othercharges,organisations.def_launch_lat,organisations.def_launch_lon,organisations.map_centre_lat,organisations.map_centre_lon,organisations.twitter_consumerKey,organisations.twitter_consumerSecret,organisations.twitter_accessToken,organisations.twitter_accessTokenSecret FROM organisations";
$sql.=" ORDER BY ";
switch ($colsort) {
 case 0:
   $sql .= "id";
break;
 case 1:
   $sql .= "id";
   break;
 case 2:
   $sql .= "name";
   break;
 case 3:
   $sql .= "addr1";
   break;
 case 4:
   $sql .= "addr2";
   break;
 case 5:
   $sql .= "addr3";
   break;
 case 6:
   $sql .= "addr4";
   break;
 case 7:
   $sql .= "country";
   break;
 case 8:
   $sql .= "contact_name";
   break;
 case 9:
   $sql .= "email";
   break;
 case 10:
   $sql .= "timezone";
   break;
 case 11:
   $sql .= "aircraft_prefix";
   break;
 case 12:
   $sql .= "tow_height_charging";
   break;
 case 13:
   $sql .= "tow_time_based";
   break;
 case 14:
   $sql .= "default_location";
   break;
 case 15:
   $sql .= "name_othercharges";
   break;
 case 16:
   $sql .= "def_launch_lat";
   break;
 case 17:
   $sql .= "def_launch_lon";
   break;
 case 18:
   $sql .= "map_centre_lat";
   break;
 case 19:
   $sql .= "map_centre_lon";
   break;
 case 20:
   $sql .= "twitter_consumerKey";
   break;
 case 21:
   $sql .= "twitter_consumerSecret";
   break;
 case 22:
   $sql .= "twitter_accessToken";
   break;
 case 23:
   $sql .= "twitter_accessTokenSecret";
   break;
}
$sql .= " ASC";
$diagtext.= "SQL=".$sql;
$r = mysqli_query($con,$sql);
$rownum = 0;
while ($row = mysqli_fetch_array($r) )
{
 $rownum = $rownum + 1;
  echo "
";if (true){echo "";echo "";echo $row[0];echo "";echo "	";}
if (true){echo "";echo $row[1];echo "	";}
if (true){echo "";echo $row[2];echo "	";}
if (true){echo "";echo $row[3];echo "	";}
if (true){echo "";echo $row[4];echo "	";}
if (true){echo "";echo $row[5];echo "	";}
if (true){echo "";echo $row[6];echo "	";}
if (true){echo "";echo $row[7];echo "	";}
if (true){echo "";echo $row[8];echo "	";}
if (true){echo "";echo $row[9];echo "	";}
if (true){echo "";echo $row[10];echo "	";}
if (true){echo "";echo $row[11];echo "	";}
if (true){echo "";echo $row[12];echo "	";}
if (true){echo "";echo $row[13];echo "	";}
if (true){echo "";echo $row[14];echo "	";}
if (true){echo "";echo $row[15];echo "	";}
if (true){echo "";echo $row[16];echo "	";}
if (true){echo "";echo $row[17];echo "	";}
if (true){echo "";echo $row[18];echo "	";}
if (true){echo "";echo $row[19];echo "	";}
if (true){echo "";echo $row[20];echo "	";}
if (true){echo "";echo $row[21];echo "	";}
if (true){echo "";echo $row[22];echo "	";}
  echo "
";
}
?>

<form id="form1" action='Organisation' method='GET'><input type='submit' value = 'Create New'>
</form>
<?php if($DEBUG>0) echo "
".$diagtext."
";?>


text:
<?php

namespace TonicHealthCheck\Test\Incident\Siren\NotificationType;

use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit_Framework_TestCase;
use TonicForHealth\PagerDutyClient\Client\EventClient;
use TonicForHealth\PagerDutyClient\Entity\Event\Event;
use TonicHealthCheck\Incident\IncidentInterface;
use TonicHealthCheck\Incident\Siren\NotificationType\PagerDutyNotificationType;
use TonicHealthCheck\Test\Incident\IncidentCreateTrait;
use TonicHealthCheck\Test\Incident\Subject\SubjectCreateTrait;

/**
 * Class RequestNotificationTypeTest.
 */
class PagerDutyNotificationTypeTest extends PHPUnit_Framework_TestCase
{
    use SubjectCreateTrait;
    use IncidentCreateTrait;

    /**
     * @var PHPUnit_Framework_MockObject_MockObject|EventClient
     */
    protected $eventClientMock;

    /**
     * @var PagerDutyNotificationType;
     */
    protected $pagerDutyNType;

    /**
     * @var string
     */
    protected $serviceKey;

    /**
     * set up base env Request type test.
     */
    public function setUp()
    {
        $this->serviceKey = '5b2fb01f1f2257dbbde64469977261de';

        $this->eventClientMock = $this
            ->getMockBuilder(EventClient::class)
            ->disableOriginalConstructor()
            ->getMock();

        $this->pagerDutyNType = new PagerDutyNotificationType(
            $this->eventClientMock,
            $this->serviceKey
        );
    }

    /**
     * Test request notify create.
     */
    public function testNotifyCreate()
    {
        self::assertEquals($this->serviceKey, $this->pagerDutyNType->getServiceKey());

        $incident = $this->createIncidentMock();

        $incident
            ->expects(self::any())
            ->method('getStatus')
            ->willReturn(IncidentInterface::STATUS_OK + 1);

        $incidentOk = $this->createIncidentMock();

        $incidentOk
            ->expects(self::any())
            ->method('getStatus')
            ->willReturn(IncidentInterface::STATUS_OK);

        $subject = $this->createSubject('target', '* * * * *');

        $event = new Event();
        $event->serviceKey = $this->serviceKey;
        $event->description = $incident->getIdent();
        $event->incidentKey = 'hci_0';
        $event->details = [
            'log' => $incident->getMessage(),
            'status' => $incident->getStatus(),
            'type' => $incident->getType(),
            'id' => $incident->getId(),
        ];

        $this->eventClientMock
            ->expects(self::at(0))
            ->method('post')
            ->with($event);

        $event2 = clone $event;
        $event2->details = null;
        $event2->description = null;
        $event2->eventType = Event::EVENT_TYPE_RESOLVE;

        $this->eventClientMock
            ->expects(self::at(1))
            ->method('post')
            ->with($event2);

        $this->pagerDutyNType->notify($subject, $incident);
        $this->pagerDutyNType->notify($subject, $incidentOk);

    }

    /**
     * Test request notify update.
     */
    public function testNotifyUpdate()
    {
    }
}


text:
* Repackage for all available .NET Framework versions

## v0.3.0, Thu 2/11/2016

* Implement _*Changed_ and _*Changing_ events for _\*PasswordChar\*_ properties
* Fix the transparency of the toolbox bitmap

## v0.2.0, Tue 2/09/2016

Attribute the control as a toolbox item so it can be used in the Windows Forms
designer.

## v0.1.0, Sun 2/07/2016

(First release)


text:
require 'spec_helper'

feature 'Repo list', js: true do
  scenario 'user views list' do
    user = create(:user)
    repo = create(:repo, full_github_name: 'thoughtbot/my-repo')
    repo.users << user
    stub_user_emails_request(AuthenticationHelper::GITHUB_TOKEN)
    sign_in_as(user)

    visit root_path

    expect(page).to have_content repo.full_github_name
  end

  scenario 'user filters list' do
    user = create(:user)
    repo = create(:repo, full_github_name: 'thoughtbot/my-repo')
    repo.users << user
    stub_user_emails_request(AuthenticationHelper::GITHUB_TOKEN)
    sign_in_as(user)

    visit root_path
    find('.search').set(repo.full_github_name)

    expect(page).to have_content repo.full_github_name
  end

  scenario 'user syncs repos' do
    user = create(:user)
    repo = create(:repo)
    user.repos << repo
    stub_repo_requests(AuthenticationHelper::GITHUB_TOKEN)
    stub_user_emails_request(AuthenticationHelper::GITHUB_TOKEN)
    sign_in_as(user)

    visit root_path

    expect(page).to have_content(repo.full_github_name)

    click_link I18n.t('sync_repos')

    expect(page).to have_content I18n.t('syncing_repos').upcase
    expect(page).not_to have_content 'jimtom/My-Private-Repo'
  end

  scenario 'user signs up' do
    with_job_delay do
      user = create(:user)

      sign_in_as(user)

      expect(page).to have_content I18n.t('syncing_repos').upcase
    end
  end

  scenario 'user activates repo' do
    user = create(:user)
    repo = create(:repo)
    repo.users << user
    hook_url = "http://#{ENV['HOST']}/builds"
    stub_repo_request(repo.full_github_name)
    stub_add_collaborator_request(repo.full_github_name)
    stub_hook_creation_request(repo.full_github_name, hook_url)
    stub_user_emails_request(AuthenticationHelper::GITHUB_TOKEN)

    sign_in_as(user)
    find(".repos .toggle").click

    expect(page).to have_css('.active')
    expect(page).to have_content '1 OF 1'

    visit root_path

    expect(page).to have_css('.active')
    expect(page).to have_content '1 OF 1'
  end

  scenario 'user with admin access activates organization repo' do
    user = create(:user)
    repo = create(:repo, full_github_name: 'testing/repo')
    repo.users << user
    hook_url = "http://#{ENV['HOST']}/builds"
    team_id = 4567 # from fixture
    hound_user = 'houndci'
    stub_repo_with_org_request(repo.full_github_name)
    stub_hook_creation_request(repo.full_github_name, hook_url)
    stub_repo_teams_request(repo.full_github_name)
    stub_user_teams_request
    stub_add_user_to_team_request(hound_user, team_id)
    stub_user_emails_request(AuthenticationHelper::GITHUB_TOKEN)

    sign_in_as(user)
    find(".repos .toggle").click

    expect(page).to have_css('.active')
    expect(page).to have_content '1 OF 1'

    visit root_path

    expect(page).to have_css('.active')
    expect(page).to have_content '1 OF 1'
  end

  scenario 'user deactivates repo' do
    user = create(:user)
    repo = create(:repo, :active)
    repo.users << user
    stub_hook_removal_request(repo.full_github_name, repo.hook_id)
    stub_user_emails_request(AuthenticationHelper::GITHUB_TOKEN)

    sign_in_as(user)
    visit root_path
    find(".repos .toggle").click

    expect(page).not_to have_css('.active')
    expect(page).to have_content '0 OF 1'

    visit current_path

    expect(page).not_to have_css('.active')
    expect(page).to have_content '0 OF 1'
  end

  private

  def with_job_delay
    Resque.inline = false
    yield
  ensure
    Resque.inline = true
  end
end


text:
var winston = require('winston')
  , _ = require('underscore')
  , config = function(){
    this.port = 1337;
    this.server = '127.0.0.1';
    this.mongodb = 'mongodb://127.0.0.1:27017/optika';
    this.clientdir = '../client/';

    switch(process.env.NODE_ENV){
      case 'production':
        this.port = process.env.VMC_APP_PORT
        this.server = '';
        this.mongodb = 'mongodb://127.0.0.1:27017/optika';
        break;
    }
  };

config.instance = null;

winston.setLevels(winston.config.npm.levels);
winston.add(winston.transports.File , { level: 'silly', filename: 'server.log' });
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, { level: 'info', colorize: true });

winston.silly('winston silly test');
winston.debug('winston debug test');
winston.verbose('winston verbose test');
winston.info('winston info test');
winston.warn('winston warn test');
winston.error('winston error test');

winston.info('Node Environment', process.env.NODE_ENV);

config.getInstance = function() {
  if (this.instance === null)
    this.instance = new config();
  return this.instance;
}

module.exports = config.getInstance();


text:
module Carrierwave
  module Video
    VERSION = "0.5.6"
  end
end


text:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="11dp" />
    <solid android:color="#E7F2F8" />
</shape>


text:
using UnityEngine;
using System.Collections;

public class HUD : MonoBehaviour {

    public Texture pauseButtonTexture;
    public Texture soundONTexture;
    public Texture soundOFFTexture;

	public bool paused = false;

	protected bool displayingVictory = false;
	protected bool displayingDefeat = false;

	protected string victoryMessage;
	protected string defeatMessage;

	public GUIStyle guiStyleLevel;
	public GUIStyle guiStyleVictory;
	public GUIStyle guiStyleDefeat;

	void Awake(){
		// Check that the game is not paused when it starts
		Resume();

		// Initialize the victory and defeat messages
		victoryMessage = getRandomVictoryMessage();
		defeatMessage = getRandomDefeatMessage();
	}

    void OnGUI() {
		// Display the current level
		GUI.Label(new Rect(50, 20, 100, 20), "Level " + Application.loadedLevel, guiStyleLevel);

        // Create the pause button
        if (GUI.Button(new Rect (Screen.width - 100,Screen.height - 100, 100, 100), pauseButtonTexture)){
			if (!paused){
				Pause();
			} else {
				Resume();
			}
		}

		// Create the sound button
		if (PlayerPrefs.GetInt(Prefs.sound) == Prefs.off){
			AudioListener.pause = true;
	        if (GUI.Button(new Rect ( 0 ,Screen.height - 100, 100, 100), soundONTexture)){
				PlayerPrefs.SetInt(Prefs.sound, Prefs.on);
			}
		}
		if (PlayerPrefs.GetInt(Prefs.sound) == Prefs.on){
			AudioListener.pause = false;
	        if (GUI.Button(new Rect ( 0 ,Screen.height - 100, 100, 100), soundOFFTexture)){
				PlayerPrefs.SetInt(Prefs.sound, Prefs.off);
			}
		}

		// Show victory message
		if(Inventory.levelCompleted && !displayingDefeat){

			displayingVictory = true;

			GUI.Label(new Rect( 0 , (Screen.height / 2) - 100, Screen.width, 100),
								victoryMessage, guiStyleVictory);
		}

		// Show defeat message
		if(PlayerStatus.dead && !displayingVictory){

			displayingDefeat = false;

			GUI.Label(new Rect( 0 , (Screen.height / 2) - 50, Screen.width, 100),
								defeatMessage, guiStyleDefeat);
		}

		if (paused){
			// Create the pause menu
	        if (GUI.Button(new Rect ((Screen.width / 2) - 75, (Screen.height / 2) - 90 , 150, 80), "Resume")){
				// Resume button
				if (paused){
					Resume();
				}
			}

			if (GUI.Button(new Rect ((Screen.width / 2) - 75, (Screen.height / 2), 150, 80), "Level select")){
				// Level select button
				Application.LoadLevel(Levels.levelSelect);
			}

			if (GUI.Button(new Rect ((Screen.width / 2) - 75 , (Screen.height / 2) + 90, 150, 80), "Reset")){
				// Reset button
				Application.LoadLevel(Application.loadedLevel);
			}
		}
    }

	void Pause(){
		paused = true;
		Time.timeScale = 0.0f;
	}

	void Resume(){
		paused = false;
		Time.timeScale = 1.0f;
	}

	// Cool victory random messages
	protected string[] victoryMessages = new string[] {
		"Well done!",
		"Oh yeah!",
		"That was sweet",
		"Keep it rollin'",
		"Awesome :D",
		"That was good",
		"Fast as lighning ;)",
		"You are a master",
		"Rate 5 ;D",
		"How did you manage? :O",
		"I didn't though you could make it",
		"Impressive!",
		"Amazing!",
		"Delicious diamond :P",
		"Will you make the next one?",
		"Piece of cake!",
		"They see you rollin', they hatin'",
		"Omagawd!!1 ^^",
		"Victory!!",
		"Here! A cookie!"
	};

	string getRandomVictoryMessage(){
		return victoryMessages[Random.Range( 0, victoryMessages.Length)];
	}

	// Cool defeat random messages
	protected string[] defeatMessages = new string[] {
		"Woops",
		"What happened?",
		"You failed",
		"Can't you do it better? :)",
		"Oh no! :(",
		"You almost had it :P",
		"FAIL",
		"Deafeat!!",
		"Will you surrender?",
		"I knew you couldn't make it :/",
		"Too hard?",
		"Too bad...",
		"Ohhhhh...",
		"Try again",
		"Come on!",
		"You were not supposed to fail there",
		"The last try!",
		"Hihihi, losser",
		"What was that? xD",
		"I guess that was your best",
		"Don't hate the game...",
		"At least you tried... ^^",
		"Diamond is waiting",
		"No rollin'? :P",
		"Muahahahah!1!",
		"There is no cake for you",
		"This was the easy level...",
		"Insert Coin ;)",
	};

	string getRandomDefeatMessage(){
		return defeatMessages[Random.Range( 0, defeatMessages.Length)];
	}
}


text:
#import <ABI43_0_0React/ABI43_0_0RCTSurfaceProtocol.h>
#import <ABI43_0_0React/ABI43_0_0RCTSurfaceStage.h>
#import <ABI43_0_0React/ABI43_0_0renderer/mounting/MountingCoordinator.h>

NS_ASSUME_NONNULL_BEGIN

@class ABI43_0_0RCTBridge;
@class ABI43_0_0RCTSurfaceView;
@class ABI43_0_0RCTSurfacePresenter;
@protocol ABI43_0_0RCTSurfaceDelegate;

/**
 * (This is Fabric-compatible ABI43_0_0RCTSurface implementation.)
 *
 * ABI43_0_0RCTSurface instance represents ABI43_0_0React Native-powered piece of a user interface
 * which can be a full-screen app, separate modal view controller,
 * or even small widget.
 * It is called "Surface".
 *
 * The ABI43_0_0RCTSurface instance is completely thread-safe by design;
 * it can be created on any thread, and any its method can be called from
 * any thread (if the opposite is not mentioned explicitly).
 *
 * The primary goals of the ABI43_0_0RCTSurface are:
 *  * ability to measure and layout the surface in a thread-safe
 *    and synchronous manner;
 *  * ability to create a UIView instance on demand (later);
 *  * ability to communicate the current stage of the surface granularly.
 */
@interface ABI43_0_0RCTFabricSurface : NSObject <ABI43_0_0RCTSurfaceProtocol>

- (instancetype)initWithSurfacePresenter:(ABI43_0_0RCTSurfacePresenter *)surfacePresenter
                              moduleName:(NSString *)moduleName
                       initialProperties:(NSDictionary *)initialProperties;

#pragma mark - Dealing with UIView representation, the Main thread only access

/**
 * Creates (if needed) and returns `UIView` instance which represents the Surface.
 * The Surface will cache and *retain* this object.
 * Returning the UIView instance does not mean that the Surface is ready
 * to execute and layout. It can be just a handler which Surface will use later
 * to mount the actual views.
 * ABI43_0_0RCTSurface does not control (or influence in any way) the size or origin
 * of this view. Some superview (or another owner) must use other methods
 * of this class to setup proper layout and interop interactions with UIKit
 * or another UI framework.
 * This method must be called only from the main queue.
 */
- (ABI43_0_0RCTSurfaceView *)view;

#pragma mark - Start & Stop

/**
 * Starts or stops the Surface.
 * A Surface object can be stopped and then restarted.
 * The starting process includes initializing all underlying ABI43_0_0React Native
 * infrastructure and running ABI43_0_0React app.
 * Surface stops itself on deallocation automatically.
 * Returns YES in case of success. Returns NO if the Surface is already
 * started or stopped.
 */
- (BOOL)start;
- (BOOL)stop;

#pragma mark - Layout: Setting the size constrains

/**
 * Previously set `minimumSize` layout constraint.
 * Defaults to `{0, 0}`.
 */
@property (atomic, assign, readonly) CGSize minimumSize;

/**
 * Previously set `maximumSize` layout constraint.
 * Defaults to `{CGFLOAT_MAX, CGFLOAT_MAX}`.
 */
@property (atomic, assign, readonly) CGSize maximumSize;

/**
 * Previously set `viewportOffset` layout constraint.
 * Defaults to `{0, 0}`.
 */
@property (atomic, assign, readonly) CGPoint viewportOffset;

/**
 * Simple shortcut to `-[ABI43_0_0RCTSurface setMinimumSize:size maximumSize:size]`.
 */
- (void)setSize:(CGSize)size;

#pragma mark - Layout: Measuring

/**
 * Measures the Surface with given constraints.
 * This method does not cause any side effects on the surface object.
 */
- (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize;

/**
 * Return the current size of the root view based on (but not clamp by) current
 * size constraints.
 */
@property (atomic, assign, readonly) CGSize intrinsicSize;

#pragma mark - Synchronous waiting

/**
 * Synchronously blocks the current thread up to given `timeout` until
 * the Surface is rendered.
 */
- (BOOL)synchronouslyWaitFor:(NSTimeInterval)timeout;

@end

@interface ABI43_0_0RCTFabricSurface (Internal)

/**
 * Sets and clears given stage flags (bitmask).
 * Returns `YES` if the actual state was changed.
 */
- (BOOL)_setStage:(ABI43_0_0RCTSurfaceStage)stage;
- (BOOL)_unsetStage:(ABI43_0_0RCTSurfaceStage)stage;

@end

@interface ABI43_0_0RCTFabricSurface (Deprecated)

/**
 * Deprecated. Use `initWithSurfacePresenter:moduleName:initialProperties` instead.
 */
- (instancetype)initWithBridge:(ABI43_0_0RCTBridge *)bridge
                    moduleName:(NSString *)moduleName
             initialProperties:(NSDictionary *)initialProperties;

@end

NS_ASSUME_NONNULL_END


text:
package parser

import (
	"bytes"
	"errors"
)

//go:generate make

// StatementList is a list of statements.
type StatementList []Statement

func (l StatementList) String() string {
	var buf bytes.Buffer
	for i, s := range l {
		if i > 0 {
			_, _ = buf.WriteString("; ")
		}
		_, _ = buf.WriteString(s.String())
	}
	return buf.String()
}

// Syntax is an enum of the various syntax types.
type Syntax int

//go:generate stringer -type=Syntax
const (
	Traditional Syntax = iota
	Modern
)

// Parse parses the sql and returns a list of statements.
func Parse(sql string, syntax Syntax) (StatementList, error) {
	s := newScanner(sql, syntax)
	if sqlParse(s) != 0 {
		return nil, errors.New(s.lastError)
	}
	return s.stmts, nil
}

// ParseTraditional is short-hand for Parse(sql, Traditional)
func ParseTraditional(sql string) (StatementList, error) {
	return Parse(sql, Traditional)
}


text:
DIR="$(cd "$(dirname "${0}")" || exit; pwd)"

echo $DIR

# mount/mkisofs require root privilege
echo "* check root privilege"
if [ "$(whoami)" != "root" ]; then
  echo "root privilege required"
  exit 1
fi

# normally exit
exit 0


text:
"""This will run a test game with random AIs displaying on a board canvas"""

import Board
import BoardCanvas
import Building
import Tile
import Agent
import Player
import GameConstants
import threading
import Move
import Score

if __name__ == "__main__":
    board = Board.make_board(11,16)
    tile_supply = Tile.get_all_tiles()
    board_canvas = BoardCanvas.BoardCanvas(board, tile_supply)
    board_canvas.setup()

    def play_game(board, tile_supply, board_canvas):
        import time
        #time.sleep(1)
        colors = ['Blue', 'Green', 'Yellow', 'Red']
        names = ['Nick', 'Zach', 'Brian', 'Erin']
        players = [Player.make_player(names[i], 4, colors[i]) for i in range(4)]
        random_agent = Agent.get_random_agent()
        agents = [random_agent for _ in range(4)]

        def game_over(board, players):
            all_names = set([Player.get_player_name(player) for player in players])
            for color in GameConstants.BUILDINGS_COLORS:
                claimed = set()
                for building in Board.get_buildings_by_color(board, color):
                    if Building.has_owner(building) and Building.get_owner(building) != Building.NEUTRAL_OWNER:
                        claimed.add(Building.get_owner(building))
                if claimed != all_names:
                    return False
            return True

        def turn_moves():
            i = 0
            while True:
                if i < 2:
                    yield 1
                    i += 1
                else:
                    yield 2

        current_player = 0
        moves_per_turn = turn_moves()
        no_moves = 0
        while True:
            #def get_agent_moves(agent, board, current, num_moves=2, players=None):
            moves = next(moves_per_turn)
            #print(moves)agent, board, current, tile_supply, players, num_moves=2
            selected = Agent.get_agent_moves(agents[current_player], board, current_player, tile_supply, players, moves)
            #print(selected)
            all_pass = True
            for move in selected:
                if Move.get_move_type(move) != Move.NONE_POSSIBLE:
                    all_pass = False
                #print(move)
                board, players, tile_supply = Agent.apply_move(move, board, tile_supply, current_player, players)
                board_canvas.board = board
                board_canvas.tile_supply = tile_supply
                board_canvas.check_well
                board_canvas.update_board()
                #time.sleep(0.5)

            #print(tile_supply)
            #print(Player.get_player_color(players[current_player]), Player.get_tiles(players[current_player]))

            #print([Tile.get_tile_value(tile) for tile in tile_supply if Tile.get_tile_type(tile) == Tile.TOWER_TILE],
            #        [[Tile.get_tile_value(tile) for tile in Player.get_tiles(player) if Tile.get_tile_type(tile) == Tile.TOWER_TILE] for player in players])

            if  all_pass:
                no_moves += 1
            else:
                no_moves == 0

            if no_moves == len(players) or game_over(board, players):
                board_canvas.update_board()

                #Score############################
                get_score = Score.get_score_function(board)
                for i in range(len(players)):
                    score = get_score(players[i])
                    print (Player.get_player_color(players[i]), score)
                    print (Player.get_tiles(players[i]))
                Score.displayScores(players, board)

                input()

                #time.sleep(3)
                board = Board.make_board(11,16)
                tile_supply = Tile.get_all_tiles()
                thread = threading.Thread(target = play_game, args=[board, tile_supply, board_canvas])
                board_canvas.board = board
                board_canvas.clear_board()
                board_canvas.check_well()
                board_canvas.update_board()
                thread.start()
                return
            current_player = (current_player + 1) % len(players)
            #time.sleep(1)
            #input()
            #print(board)

    thread = threading.Thread(target = play_game, args=[board, tile_supply, board_canvas])
    thread.start()
    #play_game(board, board_canvas)
    board_canvas.mainloop()


text:
#ifdef HAVE_CONFIG_H
#include "../../../ext_config.h"
#endif

#include <php.h>
#include "../../../php_ext.h"
#include "../../../ext.h"

#include <Zend/zend_exceptions.h>

#include "kernel/main.h"

ZEPHIR_INIT_CLASS(ZendFramework_ModuleManager_Exception_ExceptionInterface) {

	ZEPHIR_REGISTER_INTERFACE(Zend\\ModuleManager\\Exception, ExceptionInterface, zendframework, modulemanager_exception_exceptioninterface, NULL);

	return SUCCESS;

}


text:
<?php

declare(strict_types=1);

namespace Ordermind\LogicalPermissions\AccessChecker;

use Ordermind\LogicalPermissions\BypassAccessCheckerInterface;
use Ordermind\LogicalPermissions\PermissionTree\FullPermissionTree;

class BypassAccessCheckerDecorator implements BypassAccessCheckerInterface
{
    protected ?BypassAccessCheckerInterface $bypassAccessChecker;

    public function __construct(?BypassAccessCheckerInterface $bypassAccessChecker = null)
    {
        $this->bypassAccessChecker = $bypassAccessChecker;
    }

    public function isBypassAllowed(FullPermissionTree $fullPermissionTree, $context, bool $allowBypass): bool
    {
        if (!$allowBypass) {
            return false;
        }

        if (!$fullPermissionTree->hasNoBypassTree()) {
            return true;
        }

        return !$fullPermissionTree->getNoBypassTree()->evaluate($context);
    }

    /**
     * {@inheritDoc}
     */
    public function checkBypassAccess($context): bool
    {
        if (null === $this->bypassAccessChecker) {
            return false;
        }

        return $this->bypassAccessChecker->checkBypassAccess($context);
    }
}


text:
from neutron.common import exceptions

class VcnsException(exceptions.NeutronException):
    pass

class VcnsGeneralException(VcnsException):
    def __init__(self, message):
        self.message = message
        super(VcnsGeneralException, self).__init__()

class VcnsBadRequest(exceptions.BadRequest):
    pass

class VcnsNotFound(exceptions.NotFound):
    message = _('%(resource)s not found: %(msg)s')

class VcnsApiException(VcnsException):
    message = _("An unknown exception %(status)s occurred: %(response)s.")

    def __init__(self, **kwargs):
        super(VcnsApiException, self).__init__(**kwargs)

        self.status = kwargs.get('status')
        self.header = kwargs.get('header')
        self.response = kwargs.get('response')

class ResourceRedirect(VcnsApiException):
    message = _("Resource %(uri)s has been redirected")

class RequestBad(VcnsApiException):
    message = _("Request %(uri)s is Bad, response %(response)s")

class Forbidden(VcnsApiException):
    message = _("Forbidden: %(uri)s")

class ResourceNotFound(VcnsApiException):
    message = _("Resource %(uri)s not found")

class MediaTypeUnsupport(VcnsApiException):
    message = _("Media Type %(uri)s is not supported")

class ServiceUnavailable(VcnsApiException):
    message = _("Service on available: %(uri)s")


text:
template <int MULTIPLY, int SHIFT> class CScaledFirstOrderFilter
{
public:

    __inline void Flush()
    {
        m_nLastValue = 0;
    }

    __inline int Compress(const int nInput)
    {
        int nRetVal = nInput - ((m_nLastValue * MULTIPLY) >> SHIFT);
        m_nLastValue = nInput;
        return nRetVal;
    }

    __inline int Decompress(const int nInput)
    {
        m_nLastValue = nInput + ((m_nLastValue * MULTIPLY) >> SHIFT);
        return m_nLastValue;
    }

protected:

    int m_nLastValue;
};

#endif // #ifndef APE_SCALEDFIRSTORDERFILTER_H


text:
'use strict';

angular.module('angularPicasa', [])
  .directive('picasa', ['picasaService', function(picasaService) {
    return {
      //works on attribute
      restrict: 'A',
      scope: {
        picasa: '@'
      },
      templateUrl: 'templates/vendor/picasa/picasa.html',
      link: function(scope, element, attrs) {
        if (attrs.height !== undefined && attrs.width !== undefined) {
          scope.size = 'both';
        } else {
          if (attrs.height !== undefined) {
            scope.size = 'height';
          }
          if (attrs.width !== undefined) {
            scope.size = 'width';
          }
        }
        scope.height = attrs.height;
        scope.width = attrs.width;

        if (attrs.thumbheight !== undefined && attrs.thumbwidth !== undefined) {
          scope.thumbSize = 'both';
        } else {
          if (attrs.thumbheight !== undefined) {
            scope.thumbSize = 'height';
          }
          if (attrs.thumbwidth !== undefined) {
            scope.thumbSize = 'width';
          }
        }
        scope.thumbheight = attrs.thumbheight;
        scope.thumbwidth = attrs.thumbwidth;

        scope.$watch('picasa', function () {
          if (scope.picasa === '') {
            return;
          }
          picasaService.get(scope.picasa).then(function(data) {
            scope.photoObjects = data;
            scope.current = data[0];
            scope.ready = true;
          })
        });

        scope.setCurrent = function(photo) {
          scope.current = photo;
        };
        scope.move = function(event) {
          var thumbDiv = element[0].lastElementChild;
          var x = event.clientX - thumbDiv.offsetLeft;
          var center = thumbDiv.offsetWidth / 2;
          var factor = 20;

          var delta = (x - center)/center * factor;

          if (delta > 0 && thumbDiv.scrollLeft < (thumbDiv.scrollWidth - thumbDiv.clientWidth)) {
              thumbDiv.scrollLeft += delta;
          }
          if (delta < 0 && thumbDiv.scrollLeft > 0) {
              thumbDiv.scrollLeft += delta;
          }

        };

      },
      controller :'GalleryLightboxCtrl'
    };
  }])
  .directive('picasaCarousel', ['picasaService', function(picasaService) {
    return {
      //works on attribute
      restrict: 'A',
      scope: {
        picasaCarousel: '@'
      },
      templateUrl: 'templates/vendor/picasa/picasa-carousel.html',
      link: function(scope, element, attrs) {
        if (attrs.height !== undefined && attrs.width !== undefined) {
          scope.size = 'both';
        } else {
          if (attrs.height !== undefined) {
            scope.size = 'height';
          }
          if (attrs.width !== undefined) {
            scope.size = 'width';
          }
        }
        scope.height = attrs.height;
        scope.width = attrs.width;

        if (attrs.thumbheight !== undefined && attrs.thumbwidth !== undefined) {
          scope.thumbSize = 'both';
        } else {
          if (attrs.thumbheight !== undefined) {
            scope.thumbSize = 'height';
          }
          if (attrs.thumbwidth !== undefined) {
            scope.thumbSize = 'width';
          }
        }
        scope.thumbheight = attrs.thumbheight;
        scope.thumbwidth = attrs.thumbwidth;

        scope.$watch('picasaCarousel', function () {
          if (scope.picasaCarousel === '') {
            return;
          }
          picasaService.get(scope.picasaCarousel).then(function(data) {
            scope.photoObjects = data;
            scope.photoObjects[0].active = true ;
            scope.current = data[0];
            scope.ready = true;
          })
        });

        scope.setCurrent = function(photo) {
          scope.current = photo;
        };
        scope.move = function(event) {
          var thumbDiv = element[0].lastElementChild;
          var x = event.clientX - thumbDiv.offsetLeft;
          var center = thumbDiv.offsetWidth / 2;
          var factor = 20;

          var delta = (x - center)/center * factor;

          if (delta > 0 && thumbDiv.scrollLeft < (thumbDiv.scrollWidth - thumbDiv.clientWidth)) {
              thumbDiv.scrollLeft += delta;
          }
          if (delta < 0 && thumbDiv.scrollLeft > 0) {
              thumbDiv.scrollLeft += delta;
          }

        }
      }
    };
  }])
  .factory('picasaService', ['$http', '$q', function($http, $q) {
    // Service logic

    $http.defaults.useXDomain = true;

    function parsePhoto(entry) {
      var lastThumb = entry.media$group.media$thumbnail.length - 1
      var photo = {
        thumb: entry.media$group.media$thumbnail[lastThumb].url,
        thumbheight: entry.media$group.media$thumbnail[lastThumb].height,
        thumbwidth: entry.media$group.media$thumbnail[lastThumb].width,
        url: entry.media$group.media$content[0].url
      };
      return photo;
    }

    function parsePhotos(url) {
      var d = $q.defer();
      var photo;
      var photos = [];
      loadPhotos(url).then(function(data) {
        if (!data.feed) {
          photos.push(parsePhoto(data.entry));
        } else {
          var entries = data.feed.entry;
          for (var i = 0; i < entries.length; i++) {
            photos.push(parsePhoto(entries[i]));
          }
        }
        d.resolve(photos);

      });
      return d.promise;
    }

    function loadPhotos(url) {
      var d = $q.defer();
      $http.jsonp(url + '?alt=json&kind=photo&hl=pl&imgmax=912&callback=JSON_CALLBACK').success(function(data, status) {
        d.resolve(data);
      });
      return d.promise;
    }

    // Public API here
    return {
      get : function (url) {
        return parsePhotos(url);
      }
    };
  }]);