math_ml 0.9 → 0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/math_ml.rb CHANGED
@@ -14,12 +14,12 @@ module MathML
14
14
  end
15
15
 
16
16
  def self.pcstring(s, encoded=false)
17
- EimXML::PCString.new(s, encoded)
17
+ s.is_a?(EimXML::PCString) ? s : EimXML::PCString.new(s, encoded)
18
18
  end
19
19
 
20
20
  class Error < StandardError; end
21
21
  end
22
22
 
23
23
  require "math_ml/element"
24
+ require "math_ml/symbol/entity_reference"
24
25
  require "math_ml/latex"
25
- require "math_ml/latex/builtin_commands"
@@ -2,6 +2,8 @@ require "eim_xml/parser"
2
2
  require "eim_xml/dsl"
3
3
  require "math_ml"
4
4
  require "spec/util"
5
+ require "math_ml/symbol/character_reference"
6
+ require "math_ml/symbol/utf8"
5
7
 
6
8
  describe MathML::LaTeX::Parser do
7
9
  include MathML::Spec::Util
@@ -473,7 +475,89 @@ EOS
473
475
  end
474
476
 
475
477
  it "should parse symbols" do
476
- smml('\precneqq').should == "<mo><mfrac linethickness='0' mathsize='1%'><mo>&prec;</mo><mo>&ne;</mo></mfrac></mo>"
478
+ smml('\precneqq').should == "<mo>&#x2ab5;</mo>"
479
+ end
480
+ end
481
+
482
+ context ".new should accept symbol table" do
483
+ it "character reference" do
484
+ @parser = MathML::LaTeX::Parser.new(:symbol=>MathML::Symbol::CharacterReference)
485
+ smml('\alpha').should == "<mi>&#x3b1;</mi>"
486
+ smml('\mathbb{abcABC}').should == "<mrow><mrow><mi>&#x1d552;</mi><mi>&#x1d553;</mi><mi>&#x1d554;</mi><mi>&#x1d538;</mi><mi>&#x1d539;</mi><mi>&#x2102;</mi></mrow></mrow>"
487
+ smml('\mathscr{abcABC}').should == "<mrow><mrow><mi>&#x1d4b6;</mi><mi>&#x1d4b7;</mi><mi>&#x1d4b8;</mi><mi>&#x1d49c;</mi><mi>&#x212c;</mi><mi>&#x1d49e;</mi></mrow></mrow>"
488
+ smml('\mathfrak{abcABC}').should == "<mrow><mrow><mi>&#x1d51e;</mi><mi>&#x1d51f;</mi><mi>&#x1d520;</mi><mi>&#x1d504;</mi><mi>&#x1d505;</mi><mi>&#x212d;</mi></mrow></mrow>"
489
+ end
490
+
491
+ it "utf8" do
492
+ @parser = MathML::LaTeX::Parser.new(:symbol=>MathML::Symbol::UTF8)
493
+ smml('\alpha').should == "<mi>α</mi>"
494
+ smml('\mathbb{abcABC}').should == "<mrow><mrow><mi>𝕒</mi><mi>𝕓</mi><mi>𝕔</mi><mi>𝔸</mi><mi>𝔹</mi><mi>ℂ</mi></mrow></mrow>"
495
+ smml('\mathscr{abcABC}').should == "<mrow><mrow><mi>𝒶</mi><mi>𝒷</mi><mi>𝒸</mi><mi>𝒜</mi><mi>ℬ</mi><mi>𝒞</mi></mrow></mrow>"
496
+ smml('\mathfrak{abcABC}').should == "<mrow><mrow><mi>𝔞</mi><mi>𝔟</mi><mi>𝔠</mi><mi>𝔄</mi><mi>𝔅</mi><mi>ℭ</mi></mrow></mrow>"
497
+ end
498
+ end
499
+
500
+ context "#symbol_table" do
501
+ it "should return when .new was given name of symbol-module" do
502
+ ps = MathML::LaTeX::Parser
503
+ symbol = MathML::Symbol
504
+
505
+ ps.new(:symbol=>symbol::UTF8).symbol_table.should == symbol::UTF8
506
+ ps.new(:symbol=>symbol::EntityReference).symbol_table.should == symbol::EntityReference
507
+ ps.new(:symbol=>symbol::CharacterReference).symbol_table.should == symbol::CharacterReference
508
+
509
+ ps.new(:symbol=>:utf8).symbol_table.should == symbol::UTF8
510
+ ps.new(:symbol=>:entity).symbol_table.should == symbol::EntityReference
511
+ ps.new(:symbol=>:character).symbol_table.should == symbol::CharacterReference
512
+
513
+ ps.new.symbol_table.should == symbol::EntityReference
514
+ ps.new(:symbol=>nil).symbol_table.should == symbol::EntityReference
515
+ end
516
+
517
+ context "should return default symbol module" do
518
+ before do
519
+ @loaded_features = $LOADED_FEATURES.dup
520
+ $LOADED_FEATURES.delete_if{|i| i=~/math_ml/}
521
+ if ::Object.const_defined?(:MathML)
522
+ @MathML = ::Object.const_get(:MathML)
523
+ ::Object.module_eval{remove_const(:MathML)}
524
+ end
525
+ end
526
+
527
+ after do
528
+ $LOADED_FEATURES.clear
529
+ $LOADED_FEATURES.push(@loaded_features.shift) until @loaded_features.empty?
530
+ if @MathML
531
+ ::Object.module_eval{remove_const(:MathML)}
532
+ ::Object.const_set(:MathML, @MathML)
533
+ end
534
+ end
535
+
536
+ it "character entity reference version by default" do
537
+ require("math_ml").should be_true
538
+ MathML::LaTeX::Parser.new.symbol_table.should == MathML::Symbol::EntityReference
539
+ end
540
+
541
+ describe "character entity reference version when set by requiring" do
542
+ it do
543
+ require("math_ml/symbol/entity_reference").should be_true
544
+ MathML::LaTeX::Parser.new.symbol_table.should == MathML::Symbol::EntityReference
545
+ end
546
+ end
547
+
548
+ describe "utf8 version when set by requiring" do
549
+ it do
550
+ require("math_ml/symbol/utf8").should be_true
551
+ MathML::LaTeX::Parser.new.symbol_table.should == MathML::Symbol::UTF8
552
+ end
553
+ end
554
+
555
+ describe "numeric character reference version when set by requiring" do
556
+ it do
557
+ require("math_ml/symbol/character_reference").should be_true
558
+ MathML::LaTeX::Parser.new.symbol_table.should == MathML::Symbol::CharacterReference
559
+ end
560
+ end
477
561
  end
478
562
  end
479
563
  end
File without changes
data/spec/util.rb CHANGED
@@ -1,13 +1,19 @@
1
+ require "rspec"
1
2
  module MathML
2
3
  module Spec
3
4
  module Util
4
5
  def raise_parse_error(message, done, rest)
5
- simple_matcher("parse_error") do |given|
6
- given.should raise_error(MathML::LaTeX::ParseError){ |e|
7
- e.message.should == message
8
- e.done.should == done
9
- e.rest.should == rest
10
- }
6
+ RSpec::Matchers::Matcher.new(:raise_parse_error) do
7
+ match do |given|
8
+ begin
9
+ given.call
10
+ @error = nil
11
+ rescue Exception
12
+ @error = $!
13
+ end
14
+ @error.is_a?(MathML::LaTeX::ParseError) &&
15
+ [@error.message, @error.done, @error.rest] == [message, done, rest]
16
+ end
11
17
  end
12
18
  end
13
19
 
@@ -16,7 +22,7 @@ module MathML
16
22
  end
17
23
 
18
24
  def math_ml(src, display_style=false, parser=nil)
19
- parser ||= new_parser
25
+ parser ||= @parser || new_parser
20
26
  parser.parse(src, display_style)
21
27
  end
22
28
 
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: math_ml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 9
9
- version: "0.9"
8
+ - 10
9
+ version: "0.10"
10
10
  platform: ruby
11
11
  authors:
12
12
  - KURODA Hiraku
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-06 00:00:00 +09:00
17
+ date: 2010-12-12 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -40,22 +40,26 @@ extensions: []
40
40
  extra_rdoc_files: []
41
41
 
42
42
  files:
43
- - Rakefile.utirake
44
43
  - Rakefile
45
- - lib/math_ml.rb
46
- - lib/math_ml/latex/builtin_commands.rb
44
+ - Rakefile.utirake
45
+ - lib/math_ml/element.rb
46
+ - lib/math_ml/string.rb
47
47
  - lib/math_ml/util.rb
48
48
  - lib/math_ml/latex.rb
49
- - lib/math_ml/string.rb
50
- - lib/math_ml/element.rb
51
- - spec/math_ml_latex_scanner_spec.rb
52
- - spec/math_ml_element_spec.rb
53
- - spec/math_ml_latex_parser_spec.rb
54
- - spec/util.rb
55
- - spec/math_ml_latex_macro_spec.rb
56
- - spec/math_ml_util_spec.rb
49
+ - lib/math_ml/latex/builtin.rb
50
+ - lib/math_ml/latex/builtin/symbol.rb
51
+ - lib/math_ml/symbol/character_reference.rb
52
+ - lib/math_ml/symbol/entity_reference.rb
53
+ - lib/math_ml/symbol/utf8.rb
54
+ - lib/math_ml.rb
57
55
  - spec/math_ml_spec.rb
58
- - spec/math_ml_string_spec.rb
56
+ - spec/math_ml/element_spec.rb
57
+ - spec/math_ml/util_spec.rb
58
+ - spec/math_ml/string_spec.rb
59
+ - spec/math_ml/latex/macro_spec.rb
60
+ - spec/math_ml/latex/scanner_spec.rb
61
+ - spec/math_ml/latex/parser_spec.rb
62
+ - spec/util.rb
59
63
  has_rdoc: true
60
64
  homepage: http://mathml.rubyforge.org/
61
65
  licenses: []