Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
75   361   18   4.41
2   252   0.24   17
17     1.06  
1    
 
  Latex2UnicodeParserTest       Line # 33 75 18 97.9% 0.9787234
 
  (12)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15    package org.qedeq.kernel.bo.service.unicode;
16   
17    import org.qedeq.base.io.SourceArea;
18    import org.qedeq.base.io.SourcePosition;
19    import org.qedeq.kernel.bo.service.latex.LatexContentException;
20    import org.qedeq.kernel.bo.test.QedeqBoTestCase;
21    import org.qedeq.kernel.se.common.DefaultModuleAddress;
22    import org.qedeq.kernel.se.common.ModuleContext;
23    import org.qedeq.kernel.se.common.ModuleDataException;
24    import org.qedeq.kernel.se.common.Plugin;
25    import org.qedeq.kernel.se.common.SourceFileException;
26    import org.qedeq.kernel.se.common.SourceFileExceptionList;
27   
28    /**
29    * For test of generating Utf8 output.
30    *
31    * @author Michael Meyling
32    */
 
33    public class Latex2UnicodeParserTest extends QedeqBoTestCase {
34   
35    private ReferenceFinder finder;
36   
37    private SourceFileExceptionList warnings;
38   
 
39  0 toggle public Latex2UnicodeParserTest() {
40  0 super();
41    }
42   
 
43  12 toggle public Latex2UnicodeParserTest(final String name) {
44  12 super(name);
45    }
46   
 
47  12 toggle public void setUp() {
48  12 finder = new ReferenceFinder() {
49   
 
50  6 toggle public String getReferenceLink(String reference,
51    SourcePosition startDelta, SourcePosition endDelta) {
52    // System.out.println("reference: " + reference);
53  6 if ("missing".equals(reference)) {
54  5 addWarning(1, "reference not found: " + reference, startDelta, endDelta);
55  5 return "[" + reference + "?]";
56    }
57  1 return "[" + reference + "]";
58    }
59   
 
60  9 toggle public void addWarning(int code, String msg, SourcePosition startDelta,
61    SourcePosition endDelta) {
62  9 ModuleDataException e = new LatexContentException(code, msg,
63    new ModuleContext(new DefaultModuleAddress(), "", startDelta, endDelta));
64  9 final SourceFileException sf = new SourceFileException((Plugin) null, e,
65    new SourceArea("memory", startDelta, endDelta), null);
66   
67  9 warnings.add(sf);
68   
69    }
70    };
71  12 warnings = new SourceFileExceptionList();
72    }
73   
74    /**
75    * Check that there are no LaTeX warnings in Q2L001.
76    *
77    * @throws Exception
78    */
 
79  1 toggle public void test01() throws Exception {
80  1 final String text = "The project \\textbf{Hilbert II} deals with the formal "
81    + "presentation and documentation of mathematical knowledge. For this reason "
82    + "\\textbf{Hilbert II} provides a program suite to accomplish that tasks. The "
83    + "concrete documentation of mathematical basics is also a purpose of this project."
84    + " \n"
85    + " For further informations about the \\textbf{Hilbert II} project see under "
86    + "\\url{http://www.qedeq.org}.\n"
87    + "\n"
88    + " \\par\n"
89    + " This document describes the logical axioms and the rules and meta rules "
90    + "that are used to derive new propositions.\n"
91    + "\n"
92    + " \\par\n"
93    + " The presentation is axiomatic and in a formal form. A formal calculus "
94    + "is given that enables us to derive all true formulas. Additional derived rules, "
95    + "theorems, definitions, abbreviations and syntax extensions basically correspond "
96    + "with the mathematical practice.\n"
97    + "\n"
98    + " \\par\n"
99    + " This document is also written in a formal language, the original "
100    + "text is a XML file with a syntax defined by the XSD \\url{http://www.qedeq.org/"
101    + "current/xml/qedeq.xsd}.\n"
102    + "\n"
103    + " \\par\n"
104    + " This document is work in progress and is updated from time to time. "
105    + "Especially at the locations marked by {\\glqq+++\\grqq} additions or changes will "
106    + "take place.\n";
107  1 final String result = "The project \uff28\uff49\uff4c\uff42\uff45\uff52\uff54 \uff29\uff29 deals with the formal presentation and "
108    + "documentation of mathematical knowledge. For this reason \uff28\uff49\uff4c\uff42\uff45\uff52\uff54 \uff29\uff29 provides a "
109    + "program suite to accomplish that tasks. The concrete documentation of mathematical "
110    + "basics is also a purpose of this project. For further informations about the "
111    + "\uff28\uff49\uff4c\uff42\uff45\uff52\uff54 \uff29\uff29 project see under http://www.qedeq.org .\n\n"
112    + "This document describes "
113    + "the logical axioms and the rules and meta rules that are used to derive new "
114    + "propositions.\n\n"
115    + "The presentation is axiomatic and in a formal form. A formal calculus "
116    + "is given that enables us to derive all true formulas. Additional derived rules, "
117    + "theorems, definitions, abbreviations and syntax extensions basically correspond "
118    + "with the mathematical practice.\n\n"
119    + "This document is also written in a formal "
120    + "language, the original text is a XML file with a syntax defined by the XSD "
121    + "http://www.qedeq.org/current/xml/qedeq.xsd .\n\n"
122    + "This document is work in progress "
123    + "and is updated from time to time. Especially at the locations marked by \u201e+++\u201d "
124    + "additions or changes will take place.";
125  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 0));
126  1 assertEquals(0, warnings.size());
127    }
128   
 
129  1 toggle public void test02() throws Exception {
130  1 final String text = "At the beginning we quote \\emph{D. Hilbert} from the lecture "
131    + "{\\glqq The Logical Basis of Mathematics\\grqq}, September \n"
132    + " 1922\\footnote{Lecture given at the Deutsche Naturforscher-Gesellschaft, "
133    + "September 1922.}.\n"
134    + "\n"
135    + " \\par\n"
136    + " \\begin{quote} {\n"
137    + " \\glqq The fundamental idea of my proof theory is the following:\n"
138    + " \n"
139    + " \\par\n"
140    + " All the propositions that constitute in mathematics are converted into "
141    + "formulas, so that mathematics proper becomes all inventory of formulas. These "
142    + "differ from the ordinary formulas of mathematics only in that, besides the "
143    + "ordinary signs, \n"
144    + " the logical signs especially {\\glqq implies\\grqq} ($\\rightarrow$) "
145    + "and for {\\glqq not\\grqq} ($\\bar{\\quad}$) occur in them. \n"
146    + " Certain formulas, which serve as building blocks for the formal edifice "
147    + "of mathematics, are called axioms. A proof is an array that must be given as such "
148    + "to our perceptual intuition of it of inferences according to the schema\\\\\n"
149    + " \\begin{eqnarray*}\n"
150    + " & A & \\\\\n"
151    + " & A \\rightarrow B& \\\\\n"
152    + " \\cline{2-3}\n"
153    + " & B &\n"
154    + " \\end{eqnarray*}\n"
155    + " where each of the premises, that is, the formulae, $A$ and "
156    + "$A \\rightarrow B$ in the array either is an axiom or directly from an axiom by "
157    + "substitution, or else coincides with the end formula $B$ of an inference occurring "
158    + "earlier in the proof or results from it by substitution. A formula is said to be "
159    + "provable if it is either an axiom or the end formula of a proof.\\grqq}\n"
160    + " \\end{quote}\n";
161  1 final String result = "At the beginning we quote D . H i l b e r t from the lecture "
162    + "\u201eThe Logical \n"
163    + "Basis of Mathematics\u201d, September 1922\n"
164    + " \u250c\n"
165    + " \u2502 Lecture given at the Deutsche Naturforscher-Gesellschaft, September \n"
166    + " \u2502 1922.\n"
167    + " \u2514\n"
168    + ".\n"
169    + "\n"
170    + "\n"
171    + " \u201eThe fundamental idea of my proof theory is the following:\n"
172    + "\n"
173    + " All the propositions that constitute in mathematics are converted into \n"
174    + " formulas, so that mathematics proper becomes all inventory of formulas. \n"
175    + " These differ from the ordinary formulas of mathematics only in that, \n"
176    + " besides the ordinary signs, the logical signs especially \u201eimplies\u201d (\u2192) and\n"
177    + " for \u201enot\u201d (\u203e ) occur in them. Certain formulas, which serve as building \n"
178    + " blocks for the formal edifice of mathematics, are called axioms. A proof \n"
179    + " is an array that must be given as such to our perceptual intuition of it \n"
180    + " of inferences according to the schema\n"
181    + " A \n"
182    + " A \u2192 B \n"
183    + " _______________________________________\n"
184    + " B \n"
185    + " where each of the premises, that is, the formulae, A and A \u2192 B in the \n"
186    + " array either is an axiom or directly from an axiom by substitution, or \n"
187    + " else coincides with the end formula B of an inference occurring earlier in\n"
188    + " the proof or results from it by substitution. A formula is said to be \n"
189    + " provable if it is either an axiom or the end formula of a proof.\u201d\n";
190    // System.out.println(warnings);
191  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 80));
192  1 assertEquals(0, warnings.size());
193    }
194   
195    /**
196    * Test if leading whitespace is removed.
197    *
198    * @throws Exception
199    */
 
200  1 toggle public void test03() throws Exception {
201  1 final String text = " \n \t hi";
202  1 final String result = "hi";
203  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 80));
204  1 assertEquals(0, warnings.size());
205    }
206   
207    /**
208    * Test problems during "\qref" are found.
209    *
210    * @throws Exception
211    */
 
212  1 toggle public void test04() throws Exception {
213  1 final String text = " \\qref{123] missing";
214  1 final String result = "123] missing";
215  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 80));
216    // System.out.println(warnings);
217  1 assertEquals(2, warnings.size());
218  1 final SourceFileException first = warnings.get(0);
219  1 assertEquals("memory:1:10:1:23", first.getSourceArea().toString());
220  1 final SourceFileException second = warnings.get(1);
221  1 assertEquals("memory:1:10:1:11", second.getSourceArea().toString());
222    }
223   
224    /**
225    * Test if missing "}" is correctly warned.
226    *
227    * @throws Exception
228    */
 
229  1 toggle public void test05() throws Exception {
230  1 final String text = " {%% ignore me\n missing\n still missing";
231  1 final String result = "missing still missing";
232  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 80));
233  1 assertEquals(1, warnings.size());
234  1 final SourceFileException first = warnings.get(0);
235  1 assertEquals("memory:1:5:3:16", first.getSourceArea().toString());
236    }
237   
238    /**
239    * Test if leading whitespace is removed.
240    *
241    * @throws Exception
242    */
 
243  1 toggle public void test06() throws Exception {
244  1 final String text = "A \\emph{Hilbert} B \\emph{Bernays}.";
245  1 final String result = "A H i l b e r t "
246    + "B B e r n a y s .";
247  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 0));
248  1 assertEquals(0, warnings.size());
249    }
250   
251    /**
252    * Test if leading whitespace is removed.
253    *
254    * @throws Exception
255    */
 
256  1 toggle public void test07() throws Exception {
257  1 final String text = " In this chapter we start with the very basic axioms and "
258    + "definitions of set theory. We shall make no attempt to introduce a formal language"
259    + "\\footnote{Despite of this, in the original text of this document the formulas of "
260    + "axioms, definitions and propositions are written in a formal language. The "
261    + "original text is a XML file with a syntax defined by the XSD "
262    + "\\url{http://www.qedeq.org/current/xml/qedeq.xsd}. A more detailed description of "
263    + "the formula language is given in "
264    + "\\url{http://www.qedeq.org/current/doc/project/qedeq_logic_language_en.pdf}.} but "
265    + "shall be content with the common logical operators. To be more precise: "
266    + "precondition is a first-order predicate calculus with identity.\n";
267  1 final String result = "In this chapter we start with the very basic axioms and definitions of set \n"
268    + "theory. We shall make no attempt to introduce a formal language\n"
269    + " \u250c\n"
270    + " \u2502 Despite of this, in the original text of this document the formulas \n"
271    + " \u2502 of axioms, definitions and propositions are written in a formal \n"
272    + " \u2502 language. The original text is a XML file with a syntax defined by \n"
273    + " \u2502 the XSD http://www.qedeq.org/current/xml/qedeq.xsd . A more \n"
274    + " \u2502 detailed description of the formula language is given in \n"
275    + " \u2502 http://www.qedeq.org/current/doc/project/qedeq_logic_language_en.pdf .\n"
276    + " \u2514\n"
277    + " but shall be content with the common logical operators. To be more precise: \n"
278    + "precondition is a first-order predicate calculus with identity.";
279  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 80));
280  1 assertEquals(0, warnings.size());
281    }
282   
283    /**
284    * Test problems during "\qref" are found.
285    *
286    * @throws Exception
287    */
 
288  1 toggle public void test08() throws Exception {
289  1 final String text = " in \\qref{gold} we trust.";
290  1 final String result = "in [gold] we trust.";
291  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 80));
292    // System.out.println(warnings);
293  1 assertEquals(0, warnings.size());
294    }
295   
296    /**
297    * Test problems during "\qref" are found.
298    *
299    * @throws Exception
300    */
 
301  1 toggle public void test09() throws Exception {
302  1 final String text = "\n we {crossed} the \\qref{missing} river at noon";
303  1 final String result = "we crossed the [missing?] river at noon";
304  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 80));
305    // System.out.println(warnings);
306  1 assertEquals(1, warnings.size());
307  1 final SourceFileException first = warnings.get(0);
308  1 assertEquals("memory:2:27:2:36", first.getSourceArea().toString());
309    }
310   
311    /**
312    * Test problems during "\qref" are found.
313    *
314    * @throws Exception
315    */
 
316  1 toggle public void test10() throws Exception {
317  1 final String text = "\n {we {crossed} the \\qref{missing} river at noon}";
318  1 final String result = "we crossed the [missing?] river at noon";
319  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 80));
320    // System.out.println(warnings);
321  1 assertEquals(1, warnings.size());
322  1 final SourceFileException first = warnings.get(0);
323  1 assertEquals("memory:2:28:2:37", first.getSourceArea().toString());
324    }
325   
326    /**
327    * Test problems during "\qref" are found.
328    *
329    * @throws Exception
330    */
 
331  1 toggle public void test11() throws Exception {
332  1 final String text = "\n {we {crossed} the \\qref{missing} river at \\qref{missing} }";
333  1 final String result = "we crossed the [missing?] river at [missing?]";
334  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 80));
335    // System.out.println(warnings);
336  1 assertEquals(2, warnings.size());
337  1 final SourceFileException first = warnings.get(0);
338    // System.out.println("Area: " + (new TextInput(text)).getSourceArea(first.getSourceArea()));
339  1 assertEquals("memory:2:28:2:37", first.getSourceArea().toString());
340  1 final SourceFileException second = warnings.get(1);
341    // System.out.println("Area: " + (new TextInput(text)).getSourceArea(second.getSourceArea()));
342  1 assertEquals("memory:2:52:2:61", second.getSourceArea().toString());
343    }
344   
345    /**
346    * Test problems during "\qref" are found.
347    *
348    * @throws Exception
349    */
 
350  1 toggle public void test12() throws Exception {
351  1 final String text = "\n {we {crossed} the \\qref{missing{}} river at \\qref{missing} }";
352  1 final String result = "we crossed the missing river at [missing?]";
353  1 assertEquals(result, Latex2UnicodeParser.transform(finder, text, 80));
354    // System.out.println(warnings);
355  1 assertEquals(2, warnings.size());
356  1 final SourceFileException first = warnings.get(0);
357    // System.out.println("Area: " + (new TextInput(text)).getSourceArea(first.getSourceArea()));
358  1 assertEquals("memory:2:28:2:39", first.getSourceArea().toString());
359    }
360   
361    }