1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace Tests;
7
8use Symfony\Component\Finder\Finder;
9
10class ZalgoTest extends TestCase
11{
12 /**
13 * @dataProvider zalgoExamples
14 */
15 public function testCombination($text)
16 {
17 $this->assertSame(unzalgo($text), $text);
18 }
19
20 // Quick test that unzalgo isn't eating the wrong characters.
21 public function testTranslations()
22 {
23 $path = realpath(__DIR__.'/../resources/lang');
24
25 $files = Finder::create()->files()->in($path)->sortByName();
26 foreach ($files as $file) {
27 $contents = $file->getContents();
28 $this->assertSame($contents, unzalgo($contents), $file->getRelativePathname());
29 }
30 }
31
32 /**
33 * This does not seem like the best idea.
34 *
35 * @dataProvider zalgoExamples
36 */
37 public function testUnzalgo($expected, $level)
38 {
39 $text = 't́̌͌̌͘e̎̀́͐̅s̐̑̈͋͡ť̎̅̌̅i͛̋̋͋̽ñ̈́̌̽̿g̈́̆͋͡͞';
40
41 $this->assertSame(unzalgo($text, $level), $expected);
42 }
43
44 public function combinationExamples()
45 {
46 return [
47 ['👩🏻⚕️'],
48 ['再⃝'],
49 ['N⃝H⃝K⃝'],
50 ];
51 }
52
53 public static function zalgoExamples()
54 {
55 return [
56 ['testing', 0],
57 ['t͘e̎s̐ťi͛ñg̈́', 1],
58 ['t́͘e̎̀s̐̑ť̎i͛̋ñ̈́g̈́͡', 2],
59 ];
60 }
61}