001    /*
002     * Copyright 2009 - 2010 JEuclid, http://jeuclid.sf.net
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    /* $Id: MMultiTest.java,v 92b6a7c39d7f 2010/08/11 20:23:17 max $ */
018    
019    package net.sourceforge.jeuclid.test.elements;
020    
021    import net.sourceforge.jeuclid.DOMBuilder;
022    import net.sourceforge.jeuclid.MathMLParserSupport;
023    
024    import org.junit.Assert;
025    import org.junit.Test;
026    import org.w3c.dom.Document;
027    import org.w3c.dom.mathml.MathMLDocument;
028    import org.w3c.dom.mathml.MathMLMathElement;
029    import org.w3c.dom.mathml.MathMLMultiScriptsElement;
030    
031    /**
032     * Various tests for the MMultiscript Element.
033     *
034     * @version $Revision: 92b6a7c39d7f $
035     */
036    public class MMultiTest {
037    
038        /**
039         * Tests Proper identification of sub and superscripts.
040         *
041         * @throws Exception
042         *             if anything goes wrong.
043         */
044        @Test
045        public void testIdentSimple() throws Exception {
046            final Document docWithID = MathMLParserSupport
047                    .parseString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math mode=\"display\">"
048                            + "<mmultiscripts>"
049                            + "<mi>x</mi>"
050                            + "<mn>1</mn>"
051                            + "<mn>2</mn>"
052                            + "<mprescripts/> "
053                            + "<mn>3</mn>"
054                            + "<mn>4</mn>" + "</mmultiscripts></math>");
055            final MathMLDocument docElement = DOMBuilder.getInstance()
056                    .createJeuclidDom(docWithID);
057            final MathMLMathElement mathElement = (MathMLMathElement) docElement
058                    .getFirstChild();
059            final MathMLMultiScriptsElement multiElement = (MathMLMultiScriptsElement) mathElement
060                    .getFirstChild();
061    
062            Assert.assertEquals(multiElement.getBase().getTextContent(), "x");
063            Assert.assertEquals(multiElement.getSubScript(1).getTextContent(), "1");
064            Assert.assertEquals(multiElement.getSuperScript(1).getTextContent(),
065                    "2");
066            Assert.assertEquals(multiElement.getPreSubScript(1).getTextContent(),
067                    "3");
068            Assert.assertEquals(multiElement.getPreSuperScript(1).getTextContent(),
069                    "4");
070    
071        }
072    
073        /**
074         * Tests Proper identification of sub and superscripts with whitespace.
075         *
076         * @throws Exception
077         *             if anything goes wrong.
078         */
079        @Test
080        public void testIdentSpace() throws Exception {
081            final Document docWithID = MathMLParserSupport
082                    .parseString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math mode=\"display\">"
083                            + "<mmultiscripts>\n"
084                            + "  <mi>x</mi>\n"
085                            + "  <mn>1</mn>\n"
086                            + "  <mn>2</mn>\n"
087                            + "  <mprescripts/>\n"
088                            + "  <mn>3</mn>\n"
089                            + "  <mn>4</mn>\n" + "</mmultiscripts></math>");
090            final MathMLDocument docElement = DOMBuilder.getInstance()
091                    .createJeuclidDom(docWithID);
092            final MathMLMathElement mathElement = (MathMLMathElement) docElement
093                    .getFirstChild();
094            final MathMLMultiScriptsElement multiElement = (MathMLMultiScriptsElement) mathElement
095                    .getFirstChild();
096    
097            Assert.assertEquals(multiElement.getBase().getTextContent(), "x");
098            Assert.assertEquals(multiElement.getSubScript(1).getTextContent(), "1");
099            Assert.assertEquals(multiElement.getSuperScript(1).getTextContent(),
100                    "2");
101            Assert.assertEquals(multiElement.getPreSubScript(1).getTextContent(),
102                    "3");
103            Assert.assertEquals(multiElement.getPreSuperScript(1).getTextContent(),
104                    "4");
105    
106        }
107    
108    }