File: util.rb

package info (click to toggle)
ruby-mathml 0.14-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 412 kB
  • ctags: 236
  • sloc: ruby: 9,833; makefile: 10
file content (40 lines) | stat: -rw-r--r-- 958 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require "rspec"
module MathML
	module Spec
		module Util
		    RSpec::Matchers.define :raise_parse_error do |*attributes|
		        match do |given|
                    message = attributes[0]
                    done = attributes[1]
                    rest = attributes[2]

				    begin
						given.call
						@error = nil
					rescue Exception
						@error = $!
					end
					@error.is_a?(MathML::LaTeX::ParseError) &&
						[@error.message, @error.done, @error.rest] == [message, done, rest]
				end
			end

			def new_parser
				MathML::LaTeX::Parser.new
			end

			def math_ml(src, display_style=false, parser=nil)
				parser ||= @parser || new_parser
				parser.parse(src, display_style)
			end

			def strip_math_ml(math_ml)
				math_ml.to_s.gsub(/>\s*/, ">").gsub(/\s*</, "<")[/\A<math [^>]*>(.*)<\/math>\Z/m, 1]
			end

			def smml(src, display_style=false, parser=nil)
				strip_math_ml(math_ml(src, display_style, parser))
			end
		end
	end
end