/* This file is part of SableCC ( http://sablecc.org ).
 *
 * See the NOTICE file distributed with this work for copyright information.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.sablecc.sablecc.automaton.globalTests;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.sablecc.sablecc.alphabet.AdjacencyRealm;
import org.sablecc.sablecc.alphabet.Realms;
import org.sablecc.sablecc.automaton.Dfa;
import org.sablecc.sablecc.automaton.MinimalDfa;
import org.sablecc.sablecc.automaton.Nfa;

public class commentsTest {

    @Test
    public void commentTest() {

        AdjacencyRealm<Character> charRealm = Realms.getCharacter();

        // Building Nfa instances for differents useful intervals
        Nfa<Character> any = new Nfa<Character>(charRealm.createInterval('#',
                '}'));
        Nfa<Character> slash = new Nfa<Character>(charRealm.createInterval('/'));
        Nfa<Character> star = new Nfa<Character>(charRealm.createInterval('*'));
        Nfa<Character> noStar = new Nfa<Character>(charRealm.createInterval(
                '#', ')')).unionWith(new Nfa<Character>(charRealm
                .createInterval('+', '}')));
        Nfa<Character> noStarOrSlash = new Nfa<Character>(charRealm
                .createInterval('#', ')')).unionWith(
                new Nfa<Character>(charRealm.createInterval('+', '.')))
                .unionWith(
                        new Nfa<Character>(charRealm.createInterval('0', '}')));

        // Building minimal dfa comment using method shortest
        Nfa<Character> comment = new Nfa<Character>();
        comment = slash.concatenateWith(star).concatenateWith(any.oneOrMore())
                .concatenateWith(star).concatenateWith(slash);
        Dfa<Character> shortestComment = comment.shortest();
        MinimalDfa<Character> minimalDfaShortestComment = new MinimalDfa<Character>(
                shortestComment);

        // Building minimal dfa comment by construction
        Nfa<Character> constructionComment = new Nfa<Character>();
        constructionComment = slash.concatenateWith(star).concatenateWith(
                noStar.oneOrMore()).concatenateWith(
                star.concatenateWith(
                        noStarOrSlash.concatenateWith(noStar.oneOrMore()))
                        .zeroOrOne()).oneOrMore().concatenateWith(star)
                .concatenateWith(slash);
        Dfa<Character> constructedDfaComment = new Dfa<Character>(
                constructionComment);
        MinimalDfa<Character> minimalDfaConstructionComment = new MinimalDfa<Character>(
                constructedDfaComment);

        // Testing for equality between the 2 minimalDfa for equivalent Dfa
        assertEquals("The two minimal Dfa insstances should be equals.",
                minimalDfaConstructionComment, minimalDfaShortestComment);
    }
}

@@ -2069,33 +2069,40 @@
 hortest%0A        
-N
+MinimalD
 fa%3CCharacter%3E co
@@ -2099,17 +2099,25 @@
 racter%3E 
-c
+shortestC
 omment =
@@ -2113,33 +2113,40 @@
 stComment = new 
-N
+MinimalD
 fa%3CCharacter%3E();
@@ -2147,34 +2147,30 @@
 er%3E(
-);%0A        comment = slash
+slash%0A                
 .con
@@ -2208,19 +2208,20 @@
 ith(any.
-one
+zero
 OrMore()
@@ -2287,462 +2287,305 @@
 ash)
-;%0A        Dfa%3CCharacter%3E shortestComment = comment.shortest();%0A        MinimalDfa%3CCharacter%3E minimalDfaShortestComment = new MinimalDfa%3CCharacter%3E(%0A                shortestComment);%0A%0A        // Building minimal dfa comment by construction%0A        Nfa%3CCharacter%3E constructionComment = new Nfa%3CCharacter%3E();%0A        constructionComment = slash.concatenateWith(star).concatenateWith(%0A                noStar.oneOrMore()).concatenateWith(%0A                star
+.shortest());%0A%0A        // Building minimal dfa comment by construction%0A        Nfa%3CCharacter%3E part1 = noStarOrSlash.concatenateWith(noStar%0A                .zeroOrMore());%0A        Nfa%3CCharacter%3E part2 = star.concatenateWith(part1.zeroOrOne());%0A%0A        Nfa%3CCharacter%3E constructionCommentNfa = slash
 .con
@@ -2593,24 +2593,29 @@
 atenateWith(
+star)
 %0A           
@@ -2623,29 +2623,8 @@
     
-        noStarOrSlash
 .con
@@ -2643,19 +2643,20 @@
 (noStar.
-one
+zero
 OrMore()
@@ -2656,17 +2656,33 @@
 rMore())
-)
+.concatenateWith(
 %0A       
@@ -2702,33 +2702,27 @@
     
+part2
 .zeroOr
-One()).oneOr
 More()
+)
 .con
@@ -2789,16 +2789,23 @@
         
+Minimal
 Dfa%3CChar
@@ -2816,29 +2816,27 @@
 r%3E construct
-edDfa
+ion
 Comment = ne
@@ -2837,16 +2837,23 @@
 t = new 
+Minimal
 Dfa%3CChar
@@ -2880,45 +2880,12 @@
     
-constructionComment);%0A        Minimal
+new 
 Dfa%3C
@@ -2894,28 +2894,18 @@
 aracter%3E
- minimalDfaC
+(c
 onstruct
@@ -2918,75 +2918,12 @@
 ment
- = new MinimalDfa%3CCharacter%3E(%0A                constructedDfaComment
+Nfa)
 );%0A%0A
@@ -3091,50 +3091,98 @@
     
-minimalDfaConstructionComment, minimalDfaS
+shortestComment.toString(), constructionComment.toString());%0A%0A        System.out.println(s
 hort

Fix global automaton test.