diff options
Diffstat (limited to 'vendor/oojs/oojs-ui/bin')
-rw-r--r-- | vendor/oojs/oojs-ui/bin/docparser.rb | 70 | ||||
-rw-r--r-- | vendor/oojs/oojs-ui/bin/generate-JSPHP-for-karma.php | 20 | ||||
-rw-r--r-- | vendor/oojs/oojs-ui/bin/testsuitegenerator.rb | 12 |
3 files changed, 66 insertions, 36 deletions
diff --git a/vendor/oojs/oojs-ui/bin/docparser.rb b/vendor/oojs/oojs-ui/bin/docparser.rb index 9f58549b..64bbf81e 100644 --- a/vendor/oojs/oojs-ui/bin/docparser.rb +++ b/vendor/oojs/oojs-ui/bin/docparser.rb @@ -1,6 +1,12 @@ require 'pp' require 'json' +$bad_input = false +def bad_input file, text + $bad_input = true + $stderr.puts "#{file}: unrecognized input: #{text}" +end + def parse_dir dirname Dir.entries(dirname).map{|filename| if filename == '.' || filename == '..' @@ -63,13 +69,13 @@ def parse_file filename ignore = false comment, code_line = d.split '*/' - comment.split("\n").each{|c| - next if c.strip == '/**' - c.sub!(/^[ \t]*\*[ \t]?/, '') # strip leading * + comment.split("\n").each{|comment_line| + next if comment_line.strip == '/**' + comment_line.sub!(/^[ \t]*\*[ \t]?/, '') # strip leading '*' and whitespace - m = c.match(/^@(\w+)[ \t]*(.*)/) - unless m - previous_item[:description] << c + "\n" + m = comment_line.match(/^@(\w+)[ \t]*(.*)/) + if !m + previous_item[:description] << comment_line + "\n" next end @@ -93,11 +99,13 @@ def parse_file filename when 'property', 'var' kind = :property m = content.match(/^\{?(.+?)\}?( .+)?$/) - if m.captures - type, description = m.captures - data[:type] = type - data[:description] = description if description + if !m + bad_input filename, comment_line + next end + type, description = m.captures + data[:type] = type + data[:description] = description if description when 'event' kind = :event data[:name] = content.strip @@ -124,20 +132,28 @@ def parse_file filename end end when 'cfg' # JS only - type, name, default, description = content.match(/^\{(.+?)\} \[?([\w.$]+?)(?:=(.+?))?\]?( .+)?$/).captures + m = content.match(/^\{(.+?)\} \[?([\w.$]+?)(?:=(.+?))?\]?( .+)?$/) + if !m + bad_input filename, comment_line + next + end + type, name, default, description = m.captures data[:config] << {name: name, type: cleanup_class_name(type), description: description || '', default: default} previous_item = data[:config][-1] when 'return' case filetype when :js - type, description = content.match(/^\{(.+?)\}( .+)?$/).captures - data[:return] = {type: cleanup_class_name(type), description: description || ''} - previous_item = data[:return] + m = content.match(/^\{(.+?)\}( .+)?$/) when :php - type, description = content.match(/^(\S+)( .+)?$/).captures - data[:return] = {type: cleanup_class_name(type), description: description || ''} - previous_item = data[:return] + m = content.match(/^(\S+)( .+)?$/) + end + if !m + bad_input filename, comment_line + next end + type, description = m.captures + data[:return] = {type: cleanup_class_name(type), description: description || ''} + previous_item = data[:return] when 'private' data[:visibility] = :private when 'protected' @@ -153,7 +169,8 @@ def parse_file filename 'see' # skip else - fail "unrecognized keyword: #{keyword}" + bad_input filename, comment_line + next end } @@ -163,6 +180,10 @@ def parse_file filename case filetype when :js m = code_line.match(/(?:(static|prototype)\.)?(\w+) =/) + if !m + bad_input filename, code_line.strip + next + end kind_, name = m.captures data[:static] = true if kind_ == 'static' kind = {'static' => :property, 'prototype' => :method}[ kind_.strip ] if kind_ && !kind @@ -175,6 +196,10 @@ def parse_file filename (\w+) (?:\sextends\s(\w+))? /x) + if !m + bad_input filename, code_line.strip + next + end visibility, static, kind_, name, parent = m.captures kind = {'$' => :property, 'function' => :method, 'class' => :class}[ kind_.strip ] data[:visibility] = {'private' => :private, 'protected' => :protected, 'public' => :public}[ visibility ] || :public @@ -223,10 +248,15 @@ end def parse_any_path path if File.directory? path - parse_dir path + result = parse_dir path else - parse_file path + result = parse_file path + end + if $bad_input + $stderr.puts 'Unrecognized inputs encountered, stopping.' + exit 1 end + result end if __FILE__ == $PROGRAM_NAME diff --git a/vendor/oojs/oojs-ui/bin/generate-JSPHP-for-karma.php b/vendor/oojs/oojs-ui/bin/generate-JSPHP-for-karma.php index 445da65c..2cee51e6 100644 --- a/vendor/oojs/oojs-ui/bin/generate-JSPHP-for-karma.php +++ b/vendor/oojs/oojs-ui/bin/generate-JSPHP-for-karma.php @@ -1,26 +1,20 @@ <?php -// Quick and dirty autoloader to make it possible to run without Composer. -spl_autoload_register( function ( $class ) { - $class = preg_replace( '/^OOUI\\\\/', '', $class ); - foreach ( array( 'elements', 'layouts', 'themes', 'widgets', '.' ) as $dir ) { - $path = "../php/$dir/$class.php"; - if ( file_exists( $path ) ) { - require_once $path; - return; - } - } -} ); +require_once __DIR__ . '/../vendor/autoload.php'; -$testSuiteJSON = file_get_contents( 'JSPHP-suite.json' ); +$testSuiteJSON = file_get_contents( __DIR__ . '/../tests/JSPHP-suite.json' ); $testSuite = json_decode( $testSuiteJSON, true ); $testSuiteOutput = array(); +// @codingStandardsIgnoreStart function new_OOUI( $class, $config = array() ) { + // @codingStandardsIgnoreEnd $class = "OOUI\\" . $class; return new $class( $config ); } +// @codingStandardsIgnoreStart function unstub( &$value ) { + // @codingStandardsIgnoreEnd if ( is_string( $value ) && substr( $value, 0, 13 ) === '_placeholder_' ) { $value = json_decode( substr( $value, 13 ), true ); array_walk_recursive( $value['config'], 'unstub' ); @@ -47,4 +41,4 @@ $testSuiteOutputJSON = json_encode( $testSuiteOutput, JSON_PRETTY_PRINT ); echo "var testSuiteConfigs = $testSuiteJSON;\n\n"; echo "var testSuitePHPOutput = $testSuiteOutputJSON;\n\n"; -echo file_get_contents( 'JSPHP.test.karma.js' ); +echo file_get_contents( __DIR__ . '/../tests/JSPHP.test.karma.js' ); diff --git a/vendor/oojs/oojs-ui/bin/testsuitegenerator.rb b/vendor/oojs/oojs-ui/bin/testsuitegenerator.rb index 28ab1a85..48ba012c 100644 --- a/vendor/oojs/oojs-ui/bin/testsuitegenerator.rb +++ b/vendor/oojs/oojs-ui/bin/testsuitegenerator.rb @@ -18,7 +18,7 @@ else .reject{|c| c[:abstract] } # can't test abstract classes .reject{|c| !c[:parent] || c[:parent] == 'ElementMixin' || c[:parent] == 'Theme' } # can't test abstract .reject{|c| %w[Element Widget Layout Theme].include? c[:name] } # no toplevel - .reject{|c| c[:name] == 'DropdownInputWidget' } # different PHP and JS implementations + .reject{|c| %w[DropdownInputWidget RadioSelectInputWidget].include? c[:name] } # different PHP and JS implementations # values to test for each type expandos = { @@ -31,10 +31,13 @@ else # values to test for names sensible_values = { 'href' => ['http://example.com/'], - ['TextInputWidget', 'type'] => %w[text password], - ['ButtonInputWidget', 'type'] => %w[button input], + ['TextInputWidget', 'type'] => %w[text password foo], + ['ButtonInputWidget', 'type'] => %w[button submit foo], ['FieldLayout', 'help'] => true, # different PHP and JS implementations + ['ActionFieldLayout', 'help'] => true, # different PHP and JS implementations ['FieldsetLayout', 'help'] => true, # different PHP and JS implementations + ['FieldLayout', 'errors'] => expandos['string'].map{|v| [v] }, # treat as string[] + ['FieldLayout', 'notices'] => expandos['string'].map{|v| [v] }, # treat as string[] 'type' => %w[text button], 'method' => %w[GET POST], 'action' => [], @@ -44,6 +47,7 @@ else 'name' => true, 'autofocus' => true, # usually makes no sense in JS 'tabIndex' => [-1, 0, 100], + 'maxLength' => [100], 'icon' => ['picture'], 'indicator' => ['down'], 'flags' => %w[constructive], @@ -140,7 +144,9 @@ else end end + $stderr.puts "Generated #{tests.length} test cases." tests = tests.group_by{|t| t[:class] } + $stderr.puts tests.map{|class_name, class_tests| "* #{class_name}: #{class_tests.length}" } puts JSON.pretty_generate tests end |