001 /*
002 * Copyright 2007 - 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: MFencedTest.java,v 92b6a7c39d7f 2010/08/11 20:23:17 max $ */
018
019 package net.sourceforge.jeuclid.test.elements;
020
021 import junit.framework.Assert;
022 import net.sourceforge.jeuclid.DOMBuilder;
023 import net.sourceforge.jeuclid.MathMLParserSupport;
024
025 import org.junit.Test;
026 import org.w3c.dom.Document;
027 import org.w3c.dom.mathml.MathMLDocument;
028 import org.w3c.dom.mathml.MathMLFencedElement;
029 import org.w3c.dom.mathml.MathMLMathElement;
030
031 /**
032 * Various tests for the MFenced Element.
033 *
034 * @version $Revision: 92b6a7c39d7f $
035 */
036 public class MFencedTest {
037
038 /**
039 * Tests three different values for separators.
040 *
041 * @throws Exception
042 * if anything goes wrong.
043 */
044 @Test
045 public void testSeparators() throws Exception {
046 Assert.assertEquals(",", this.createFenced("").getSeparators());
047 Assert.assertEquals("", this.createFenced("separators=''").getSeparators());
048 Assert.assertEquals(",", this.createFenced("separators=','").getSeparators());
049 Assert.assertEquals("|", this.createFenced("separators='|'").getSeparators());
050 Assert.assertEquals("|", this.createFenced("separators=' | '").getSeparators());
051 Assert.assertEquals("|,", this.createFenced("separators=' | , '").getSeparators());
052 }
053
054 private MathMLFencedElement createFenced(final String content) throws Exception {
055 final Document docWithID = MathMLParserSupport
056 .parseString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><math mode=\"display\">"
057 + "<mfenced " + content + " />" + "</math>");
058 final MathMLDocument docElement = DOMBuilder.getInstance()
059 .createJeuclidDom(docWithID);
060 final MathMLMathElement mathElement = (MathMLMathElement) docElement
061 .getFirstChild();
062 final MathMLFencedElement fencedElement = (MathMLFencedElement) mathElement
063 .getFirstChild();
064 return fencedElement;
065 }
066 }