math_ml 0.13 → 1.0.0
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.
- checksums.yaml +7 -0
- data/LICENSE +339 -0
- data/lib/math_ml/element.rb +233 -225
- data/lib/math_ml/latex/builtin/symbol.rb +546 -546
- data/lib/math_ml/latex/builtin.rb +3 -3
- data/lib/math_ml/latex.rb +1140 -1102
- data/lib/math_ml/string.rb +17 -16
- data/lib/math_ml/symbol/character_reference.rb +2100 -2101
- data/lib/math_ml/symbol/entity_reference.rb +2100 -2100
- data/lib/math_ml/symbol/utf8.rb +2100 -2102
- data/lib/math_ml/util.rb +350 -339
- data/lib/math_ml.rb +14 -14
- metadata +43 -73
- data/Rakefile +0 -60
- data/Rakefile.utirake +0 -392
- data/spec/math_ml/element_spec.rb +0 -32
- data/spec/math_ml/latex/macro_spec.rb +0 -122
- data/spec/math_ml/latex/parser_spec.rb +0 -578
- data/spec/math_ml/latex/scanner_spec.rb +0 -202
- data/spec/math_ml/string_spec.rb +0 -29
- data/spec/math_ml/util_spec.rb +0 -700
- data/spec/math_ml_spec.rb +0 -14
- data/spec/util.rb +0 -43
@@ -1,122 +0,0 @@
|
|
1
|
-
require "math_ml"
|
2
|
-
require "spec/util"
|
3
|
-
|
4
|
-
describe MathML::LaTeX::Macro do
|
5
|
-
include MathML::Spec::Util
|
6
|
-
|
7
|
-
before(:all) do
|
8
|
-
@src = <<'EOT'
|
9
|
-
\newcommand{\newcom}{test}
|
10
|
-
\newcommand{\paramcom}[2]{param2 #2, param1 #1.}
|
11
|
-
\newcommand\ALPHA\alpha
|
12
|
-
\newcommand\BETA[1]\beta
|
13
|
-
\newcommand{\nothing}{}
|
14
|
-
\newenvironment{newenv}{begin_newenv}{end_newenv}
|
15
|
-
\newenvironment{paramenv}[2]{begin 1:#1, 2:#2}{end 2:#2 1:#1}
|
16
|
-
\newenvironment{nothing}{}{}
|
17
|
-
\newenvironment{separated environment}{sep}{env}
|
18
|
-
\newenvironment ENV
|
19
|
-
EOT
|
20
|
-
end
|
21
|
-
|
22
|
-
before do
|
23
|
-
@m = MathML::LaTeX::Macro.new
|
24
|
-
@m.parse(@src)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "#parse" do
|
28
|
-
@m = MathML::LaTeX::Macro.new
|
29
|
-
lambda{@m.parse(@src)}.should_not raise_error
|
30
|
-
|
31
|
-
@m = MathML::LaTeX::Macro.new
|
32
|
-
lambda{@m.parse('\newcommand{notcommand}{}')}.should raise_parse_error("Need newcommand.", '\\newcommand{', "notcommand}{}")
|
33
|
-
lambda{@m.parse('\newcommand{\separated command}{}')}.should raise_parse_error("Syntax error.", '\newcommand{\separated', " command}{}")
|
34
|
-
lambda{@m.parse('\newcommand{\nobody}')}.should raise_parse_error("Need parameter.", '\newcommand{\nobody}', "")
|
35
|
-
lambda{@m.parse('\newcommand{\noparam}{#1}')}.should raise_parse_error("Parameter \# too large.", '\newcommand{\noparam}{#', "1}")
|
36
|
-
lambda{@m.parse('\newcommand{\overopt}[1]{#1#2}')}.should raise_parse_error("Parameter \# too large.", '\newcommand{\overopt}[1]{#1#', "2}")
|
37
|
-
lambda{@m.parse('\newcommand{\strangeopt}[-1]')}.should raise_parse_error("Need positive number.", '\newcommand{\strangeopt}[', "-1]")
|
38
|
-
lambda{@m.parse('\newcommand{\strangeopt}[a]')}.should raise_parse_error("Need positive number.", '\newcommand{\strangeopt}[', "a]")
|
39
|
-
|
40
|
-
lambda{@m.parse('\newenvironment{\command}{}{}')}.should raise_parse_error("Syntax error.", '\newenvironment{', '\command}{}{}')
|
41
|
-
lambda{@m.parse('\newenvironment{nobegin}')}.should raise_parse_error("Need begin block.", '\newenvironment{nobegin}', "")
|
42
|
-
lambda{@m.parse('\newenvironment{noend}{}')}.should raise_parse_error("Need end block.", '\newenvironment{noend}{}', "")
|
43
|
-
lambda{@m.parse('\newenvironment{noparam}{#1}{}')}.should raise_parse_error("Parameter \# too large.", '\newenvironment{noparam}{#', "1}{}")
|
44
|
-
lambda{@m.parse('\newenvironment{overparam}[1]{#1#2}{}')}.should raise_parse_error("Parameter \# too large.", '\newenvironment{overparam}[1]{#1#', "2}{}")
|
45
|
-
lambda{@m.parse('\newenvironment{strangeparam}[-1]{}{}')}.should raise_parse_error("Need positive number.", '\newenvironment{strangeparam}[', "-1]{}{}")
|
46
|
-
lambda{@m.parse('\newenvironment{strangeparam}[a]{}{}')}.should raise_parse_error("Need positive number.", '\newenvironment{strangeparam}[', "a]{}{}")
|
47
|
-
|
48
|
-
lambda{@m.parse('\newcommand{\valid}{OK} \invalid{\test}{NG}')}.should raise_parse_error("Syntax error.", '\newcommand{\valid}{OK} ', '\invalid{\test}{NG}')
|
49
|
-
lambda{@m.parse('\newcommand{\valid}{OK} invalid{\test}{NG}')}.should raise_parse_error("Syntax error.", '\newcommand{\valid}{OK} ', 'invalid{\test}{NG}')
|
50
|
-
|
51
|
-
lambda{@m.parse('\newcommand{\newcom}[test')}.should raise_parse_error("Option not closed.", '\newcommand{\newcom}', '[test')
|
52
|
-
lambda{@m.parse('\newcommand{\newcom}[1][test')}.should raise_parse_error("Option not closed.", '\newcommand{\newcom}[1]', '[test')
|
53
|
-
lambda{@m.parse('\newcommand{\newcom}[1][]{#1#2}')}.should raise_parse_error("Parameter \# too large.", '\newcommand{\newcom}[1][]{#1#', '2}')
|
54
|
-
lambda{@m.parse('\newenvironment{newenv}[1][test')}.should raise_parse_error("Option not closed.", '\newenvironment{newenv}[1]', '[test')
|
55
|
-
lambda{@m.parse('\newenvironment{newenv}[1][test')}.should raise_parse_error("Option not closed.", '\newenvironment{newenv}[1]', '[test')
|
56
|
-
|
57
|
-
lambda{@m.parse('\newcommand{\newcom')}.should raise_parse_error("Block not closed.", '\newcommand', '{\newcom')
|
58
|
-
lambda{@m.parse('\newcommand{\newcom}{test1{test2}{test3')}.should raise_parse_error("Block not closed.", '\newcommand{\newcom}', '{test1{test2}{test3')
|
59
|
-
|
60
|
-
lambda{@m.parse('\newenvironment{newenv}[1][]{#1 #2}')}.should raise_parse_error("Parameter \# too large.", '\newenvironment{newenv}[1][]{#1 #', '2}')
|
61
|
-
end
|
62
|
-
|
63
|
-
it "#commands" do
|
64
|
-
@m.commands("newcom").num.should == 0
|
65
|
-
@m.commands("paramcom").num.should == 2
|
66
|
-
@m.commands("no").should == nil
|
67
|
-
end
|
68
|
-
|
69
|
-
it "#expand_command" do
|
70
|
-
@m.expand_command("not coommand", []).should == nil
|
71
|
-
|
72
|
-
@m.expand_command("newcom", []).should == "test"
|
73
|
-
@m.expand_command("newcom", ["dummy_param"]).should == "test"
|
74
|
-
@m.expand_command("paramcom", ["1", "2"]).should == "param2 2, param1 1."
|
75
|
-
@m.expand_command("paramcom", ["12", "34"]).should == "param2 34, param1 12."
|
76
|
-
lambda{@m.expand_command("paramcom", ["12"])}.should raise_parse_error("Need more parameter.", "", "")
|
77
|
-
lambda{@m.expand_command("paramcom", [])}.should raise_parse_error("Need more parameter.", "", "")
|
78
|
-
end
|
79
|
-
|
80
|
-
it "#environments" do
|
81
|
-
@m.environments("newenv").num.should == 0
|
82
|
-
@m.environments("paramenv").num.should == 2
|
83
|
-
@m.environments("not_env").should == nil
|
84
|
-
@m.environments("separated environment").num.should == 0
|
85
|
-
end
|
86
|
-
|
87
|
-
it "#expand_environment" do
|
88
|
-
@m.expand_environment('notregistered', "dummy", []).should == nil
|
89
|
-
@m.expand_environment("newenv", "body", []).should == ' begin_newenv body end_newenv '
|
90
|
-
@m.expand_environment("paramenv", "body", ["1", "2"]).should == ' begin 1:1, 2:2 body end 2:2 1:1 '
|
91
|
-
@m.expand_environment("paramenv", "body", ["12", "34"]).should == ' begin 1:12, 2:34 body end 2:34 1:12 '
|
92
|
-
lambda{@m.expand_environment("paramenv", "body", ["1"])}.should raise_parse_error("Need more parameter.", "", "")
|
93
|
-
lambda{@m.expand_environment("paramenv", "body", [])}.should raise_parse_error("Need more parameter.", "", "")
|
94
|
-
@m.expand_environment("nothing", "body", []).should == ' body '
|
95
|
-
@m.expand_environment("separated environment", "body", []).should == ' sep body env '
|
96
|
-
@m.expand_environment("E", "body", []).should == ' N body V '
|
97
|
-
end
|
98
|
-
|
99
|
-
it "#expand_with_options" do
|
100
|
-
src = <<'EOT'
|
101
|
-
\newcommand{\opt}[1][x]{#1}
|
102
|
-
\newcommand{\optparam}[2][]{#1#2}
|
103
|
-
\newenvironment{newenv}[1][x]{s:#1}{e:#1}
|
104
|
-
\newenvironment{optenv}[2][]{s:#1}{e:#2}
|
105
|
-
EOT
|
106
|
-
|
107
|
-
m = MathML::LaTeX::Macro.new
|
108
|
-
m.parse(src)
|
109
|
-
|
110
|
-
m.expand_command("opt", []).should == 'x'
|
111
|
-
m.expand_command("opt", [], "1").should == '1'
|
112
|
-
|
113
|
-
m.expand_command("optparam", ["1"]).should == '1'
|
114
|
-
m.expand_command("optparam", ["1"], "2").should == '21'
|
115
|
-
|
116
|
-
m.expand_environment("newenv", "test", []).should == " s:x test e:x "
|
117
|
-
m.expand_environment("newenv", "test", [], "1").should == " s:1 test e:1 "
|
118
|
-
|
119
|
-
m.expand_environment("optenv", "test", ["1"]).should == " s: test e:1 "
|
120
|
-
m.expand_environment("optenv", "test", ["1"], "2").should == " s:2 test e:1 "
|
121
|
-
end
|
122
|
-
end
|