Package com.dubture.twig.test.testcases

Source Code of com.dubture.twig.test.testcases.TwigTextSequenceUtilitiesTest

/*******************************************************************************
* This file is part of the Twig eclipse plugin.
*
* (c) Robert Gruendler <r.gruendler@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
******************************************************************************/
package com.dubture.twig.test.testcases;

import junit.framework.TestCase;

import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.dubture.twig.core.documentModel.provisional.contenttype.ContentTypeIdForTwig;
import com.dubture.twig.core.util.text.TwigTextSequenceUtilities;

/**
*
* Tests for the {@link TwigTextSequenceUtilities}
*
*
* @author Robert Gruendler <r.gruendler@gmail.com>
*
*/
@SuppressWarnings("restriction")
public class TwigTextSequenceUtilitiesTest extends TestCase
{

    @Before
    protected void setUp() throws Exception
    {
        super.setUp();
    }

    @After
    protected void tearDown() throws Exception
    {
        super.tearDown();
    }

    @Test
    public void testStatement()
    {

        try {
            IStructuredModel model = createModel(ContentTypeIdForTwig.CONTENT_TYPE_ID_TWIG);

            IStructuredDocument fDoc = model.getStructuredDocument();
            String fText = "{% for item in items %}";
            fDoc.set(fText);
//            IStructuredDocumentRegion[] regions = fDoc
//                    .getStructuredDocumentRegions();

            // assertEquals(1, regions.length);
            // int offset = 8;
            //
            // TextSequence statement =
            // TwigTextSequenceUtilities.getStatement(offset, regions[0],
            // false);
            // assertEquals("for i", statement.toString());

        } catch (Exception e) {
            e.printStackTrace();
            fail();

        }
    }

    @Test
    public void testPrint()
    {

        try {
            IStructuredModel model = createModel(ContentTypeIdForTwig.CONTENT_TYPE_ID_TWIG);

            IStructuredDocument fDoc = model.getStructuredDocument();
            String fText = "{{ item.href }}";
            fDoc.set(fText);
            IStructuredDocumentRegion[] regions = fDoc
                    .getStructuredDocumentRegions();

            assertEquals(1, regions.length);
//            int offset = 8;

//            TextSequence statement = TwigTextSequenceUtilities.getStatement(
//                    offset, regions[0], false);
            // assertNotNull(statement);
            // assertEquals("item.", statement.toString());

        } catch (Exception e) {
            e.printStackTrace();
            fail();

        }
    }

    @Test
    public void testSinglePrint()
    {

        try {
            IStructuredModel model = createModel(ContentTypeIdForTwig.CONTENT_TYPE_ID_TWIG);

            IStructuredDocument fDoc = model.getStructuredDocument();
            String fText = "{{ endblock }}";
            fDoc.set(fText);
            IStructuredDocumentRegion[] regions = fDoc
                    .getStructuredDocumentRegions();

            assertEquals(1, regions.length);
            //int offset = 5;

            // TextSequence statement =
            // TwigTextSequenceUtilities.getStatement(offset, regions[0],
            // false);
            // assertEquals("en", statement.toString());

        } catch (Exception e) {
            e.printStackTrace();
            fail();

        }

    }

    private IStructuredModel createModel(String contentTypeID)
    {

        IModelManager manager = StructuredModelManager.getModelManager();
        return manager.createUnManagedStructuredModelFor(contentTypeID);

    }
}
TOP

Related Classes of com.dubture.twig.test.testcases.TwigTextSequenceUtilitiesTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.