From 6a46f2813c9a693e66930b86fd964636e75e3dbc Mon Sep 17 00:00:00 2001 From: physikerwelt Date: Thu, 21 Nov 2024 23:01:09 +0100 Subject: [PATCH] Add tests for AmsMappings Change-Id: Ia4fbba3cda087b17587a953a6c01c6fae2fe2b64 --- src/WikiTexVC/MMLmappings/AMSMappings.php | 8 +-- .../WikiTexVC/MMLmappings/AmsMappingsTest.php | 72 +++++++++++++++++++ 2 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 tests/phpunit/unit/WikiTexVC/MMLmappings/AmsMappingsTest.php diff --git a/src/WikiTexVC/MMLmappings/AMSMappings.php b/src/WikiTexVC/MMLmappings/AMSMappings.php index 447c4d8a9..b440902ae 100644 --- a/src/WikiTexVC/MMLmappings/AMSMappings.php +++ b/src/WikiTexVC/MMLmappings/AMSMappings.php @@ -363,8 +363,8 @@ class AMSMappings { // Just an empty private constructor, for singleton pattern } - public static function removeInstance() { - self::$instance = null; + public static function getAll(): array { + return self::ALL; } public static function getInstance() { @@ -372,10 +372,6 @@ class AMSMappings { return self::$instance; } - public static function getEntryFromList( $keylist, $key ) { - return self::ALL[$keylist][$key] ?? null; - } - public static function getOperatorByKey( $key ) { // √ to \\u.... this is only temporary probably entities.php will be refactored with \u vals again $key = MMLutil::x2uNotation( $key ); diff --git a/tests/phpunit/unit/WikiTexVC/MMLmappings/AmsMappingsTest.php b/tests/phpunit/unit/WikiTexVC/MMLmappings/AmsMappingsTest.php new file mode 100644 index 000000000..87f63ecd6 --- /dev/null +++ b/tests/phpunit/unit/WikiTexVC/MMLmappings/AmsMappingsTest.php @@ -0,0 +1,72 @@ +assertIsArray( $all ); + $this->assertNotEmpty( $all ); + } + + public function provideTestCases(): array { + // the second argument is an array of known problems which should be removed in the future + return [ + 'amsmacros' => [ 'amsmacros', [ 'MultiIntegral', 'HandleTag', 'HandleNoTag', 'HandleRef', 'HandleDeclareOp', + 'HandleShove' ] ], + ]; + } + + /** + * @dataProvider provideTestCases + */ + public function testValidMethods( $setName, $knownProblems = [] ) { + foreach ( AMSMappings::getAll()[$setName] as $symbol => $payload ) { + $methodName = is_array( $payload ) ? $payload[0] : $payload; + if ( in_array( $methodName, $knownProblems ) ) { + continue; + } + $this->assertTrue( method_exists( BaseParsing::class, $methodName ), + 'Method ' . $methodName . ' for symbol ' . $symbol . ' does not exist in BaseParsing' ); + + } + } + + public function testGetOperatorByKey() { + $this->assertEquals( '⨌', AMSMappings::getOperatorByKey( 'iiiint' )[0] ); + } + + public function testGetMathDelimiterByKey() { + $this->assertEquals( '|', AMSMappings::getMathDelimiterByKey( 'lvert' )[0] ); + } + + public function testGetSymbolDelimiterByKey() { + $this->assertEquals( '⌜', AMSMappings::getSymbolDelimiterByKey( 'ulcorner' )[0] ); + } + + public function testGetMacroByKey() { + $this->assertEquals( 'Tilde', AMSMappings::getMacroByKey( '\\nobreakspace' )[0] ); + $this->assertEquals( 'macro', AMSMappings::getMacroByKey( 'implies' )[0] ); + } + + public function testGetInstance() { + $this->assertInstanceOf( AMSMappings::class, AMSMappings::getInstance() ); + } + + public function testGetIdentifierByKey() { + $this->assertEquals( 'Γ', AMSMappings::getIdentifierByKey( 'varGamma' )[0] ); + } + + public function testGetEnvironmentByKey() { + $this->assertEquals( 'EqnArray', AMSMappings::getEnvironmentByKey( 'align' )[0] ); + } + +}