math_ml 0.14 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,202 +0,0 @@
1
- require "math_ml"
2
-
3
- describe MathML::LaTeX::Scanner do
4
- def new_scanner(src)
5
- MathML::LaTeX::Scanner.new(src)
6
- end
7
-
8
- it "#done, #rest" do
9
- s = new_scanner("0123")
10
- s.pos = 2
11
- s.done.should == "01"
12
- s.rest.should == "23"
13
- end
14
-
15
- it "#_check" do
16
- s = new_scanner(" ")
17
- s._check(/\s/).should == " "
18
- s.pos.should == 0
19
- end
20
-
21
- it "#_scan" do
22
- s = new_scanner(" ")
23
- s._scan(/\s/).should == " "
24
- s.pos.should == 1
25
- end
26
-
27
- it "#check" do
28
- s = new_scanner(" a")
29
- s.check(/a/).should == "a"
30
- s.pos.should == 0
31
- end
32
-
33
- it "#scan, #reset" do
34
- s = new_scanner(" a")
35
- s.scan(/a/).should == "a"
36
- s.pos.should == 2
37
-
38
- s.reset
39
- s.pos.should == 0
40
- s.scan(/b/).should be_nil
41
- s.pos.should == 0
42
-
43
- s = new_scanner(" %comment\na")
44
- s.scan(/a/).should == "a"
45
- s.pos.should == 11
46
-
47
- s.reset
48
- s.scan(/b/).should be_nil
49
- s.pos.should == 0
50
- end
51
-
52
- it "#eos" do
53
- new_scanner("").should be_eos
54
- new_scanner(" ").should be_eos
55
- new_scanner(" %test\n%test").should be_eos
56
- new_scanner(" a").should_not be_eos
57
- new_scanner(" \\command").should_not be_eos
58
- end
59
-
60
- it "#check_command" do
61
- '\t'.should == '\\t'
62
-
63
- new_scanner("test").check_command.should be_nil
64
- s = new_scanner(' \test')
65
- s.check_command.should == '\\test'
66
- s[1].should == "test"
67
-
68
- new_scanner(' \test next').check_command.should == '\test'
69
- new_scanner(' \test_a').check_command.should == '\test'
70
- end
71
-
72
- it "#scan_command" do
73
- new_scanner("test").scan_command.should be_nil
74
-
75
- s = new_scanner(' \test')
76
- s.scan_command.should == '\test'
77
- s[1].should == "test"
78
- s.pos.should == 6
79
-
80
- s = new_scanner(' \test rest')
81
- s.scan_command.should == '\test'
82
- s.pos.should == 6
83
-
84
- s = new_scanner(' \test_a')
85
- s.scan_command.should == '\test'
86
- s.pos.should == 6
87
-
88
- s = new_scanner(' \_test')
89
- s.check_command.should == '\_'
90
- s.scan_command.should == '\_'
91
- s.rest.should == "test"
92
- end
93
-
94
- it "#scan_block" do
95
- new_scanner(" a").scan_block.should == nil
96
- new_scanner(" a").check_block.should == nil
97
-
98
- i = " {{}{}{{}{}}} "
99
- e = "{#{i}}"
100
- s = new_scanner(" #{e} test")
101
- s.check_block.should == e
102
- s.matched.should == e
103
- s[1].should == i
104
- s.scan_block.should == e
105
- s.matched.should == e
106
- s[1].should == i
107
- s.rest.should == " test"
108
-
109
- new_scanner(' \command test').scan_block.should == nil
110
- new_scanner(' \command test').check_block.should == nil
111
-
112
- new_scanner("").scan_block.should == nil
113
- new_scanner("").check_block.should == nil
114
-
115
- new_scanner(" ").scan_block.should == nil
116
- new_scanner(" ").check_block.should == nil
117
-
118
- s = new_scanner("{test")
119
- lambda{s.scan_block}.should raise_error(MathML::LaTeX::BlockNotClosed)
120
- end
121
-
122
- it "#scan_any" do
123
- s0 = " %comment\n "
124
- s1 = "{}"
125
- s = new_scanner(s0+s1)
126
- s.scan_any.should == s1
127
- s.reset
128
- s.scan_any(true).should == s0+s1
129
- s.matched.should == s1
130
-
131
- s1 = '\command'
132
- s = new_scanner(s0+s1)
133
- s.scan_any.should == s1
134
- s.reset
135
- s.scan_any(true).should == s0+s1
136
-
137
- s1 = 'a'
138
- s = new_scanner(s0+s1)
139
- s.scan_any.should == s1
140
- s.reset
141
- s.scan_any(true).should == s0+s1
142
-
143
- s = new_scanner(" ")
144
- s.scan_any.should == nil
145
- s.reset
146
- s.scan_any(true).should == " "
147
-
148
- s = new_scanner('\begin{env}test\end{env}')
149
- s.scan_any.should == '\begin'
150
- end
151
-
152
- it "#peek_command" do
153
- new_scanner(' \test').peek_command.should == "test"
154
- new_scanner("").peek_command.should == nil
155
- new_scanner(" ").peek_command.should == nil
156
- new_scanner(" a").peek_command.should == nil
157
- end
158
-
159
- it "#scan_option" do
160
- s = new_scanner(" []")
161
- s.scan_option.should == "[]"
162
- s[1].should == ""
163
- s.pos.should == 3
164
-
165
- s = new_scanner(" [ opt ]")
166
- s.scan_option.should == "[ opt ]"
167
- s[1].should == " opt "
168
- s.pos.should == 8
169
-
170
- s = new_scanner(" [[]]")
171
- s.scan_option.should == "[[]"
172
- s[1].should == "["
173
-
174
- s = new_scanner(" [{[]}]")
175
- s.scan_option.should == "[{[]}]"
176
- s[1].should == "{[]}"
177
-
178
- lambda{new_scanner("[").scan_option}.should raise_error(MathML::LaTeX::OptionNotClosed)
179
- end
180
-
181
- it "#check_option" do
182
- s = new_scanner(" []")
183
- s.check_option.should == "[]"
184
- s[1].should == ""
185
- s.pos.should == 0
186
-
187
- s = new_scanner(" [ opt ]")
188
- s.check_option.should == "[ opt ]"
189
- s[1].should == " opt "
190
- s.pos.should == 0
191
-
192
- s = new_scanner(" [[]]")
193
- s.check_option.should == "[[]"
194
- s[1].should == "["
195
-
196
- s = new_scanner(" [{[]}]")
197
- s.check_option.should == "[{[]}]"
198
- s[1].should == "{[]}"
199
-
200
- lambda{new_scanner("[").check_option}.should raise_error(MathML::LaTeX::OptionNotClosed)
201
- end
202
- end
@@ -1,29 +0,0 @@
1
- require "math_ml/string"
2
-
3
- describe MathML::String do
4
- it ".mathml_latex_parser" do
5
- MathML::String.mathml_latex_parser.should be_kind_of(MathML::LaTeX::Parser)
6
- mlp = MathML::LaTeX::Parser.new
7
- MathML::String.mathml_latex_parser = mlp
8
- MathML::String.mathml_latex_parser.should equal(mlp)
9
- lambda{MathML::String.mathml_latex_parser=String}.should raise_error(TypeError)
10
- MathML::String.mathml_latex_parser.should equal(mlp)
11
-
12
- MathML::String.mathml_latex_parser = nil
13
- MathML::String.mathml_latex_parser.should be_kind_of(MathML::LaTeX::Parser)
14
- MathML::String.mathml_latex_parser.should_not equal(mlp)
15
- end
16
- end
17
-
18
- describe String do
19
- it "#parse" do
20
- mlp = MathML::LaTeX::Parser.new
21
- "".to_mathml.to_s.should == mlp.parse("").to_s
22
- "".to_mathml(true).to_s.should == mlp.parse("", true).to_s
23
-
24
- MathML::String.mathml_latex_parser.macro.parse(<<'EOT')
25
- \newcommand{\test}{x}
26
- EOT
27
- '\test'.to_mathml.to_s.should == mlp.parse("x").to_s
28
- end
29
- end