//@@author A0138493W
package utask.logic.parser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.junit.Test;

public class ParserUtilTest {

    @Test
    public void parse_index() {
        Optional<Integer> index = ParserUtil.parseIndex(" ");
        assertTrue (!index.isPresent());

        index = ParserUtil.parseIndex("%");
        assertTrue (!index.isPresent());

        index = ParserUtil.parseIndex("abc");
        assertTrue (!index.isPresent());

        index = ParserUtil.parseIndex("16");
        assertFalse (!index.isPresent());

    }

    @Test
    public void parse_multiple_indexes() {
        Optional<List<Integer>> indexList = ParserUtil.parseMultiIndex(" ");
        assertTrue (!indexList.isPresent());

        indexList = ParserUtil.parseMultiIndex(" , 1");
        assertTrue (!indexList.isPresent());

        indexList = ParserUtil.parseMultiIndex("1, a");
        assertTrue (!indexList.isPresent());

        indexList = ParserUtil.parseMultiIndex("1, 2 to c");
        assertTrue (!indexList.isPresent());

        indexList = ParserUtil.parseMultiIndex("1, 1");
        assertFalse (!indexList.isPresent());
        assertEquals ("1", indexList.get().get(0).toString());

        indexList = ParserUtil.parseMultiIndex(" 1, 1 to 3");
        assertFalse (!indexList.isPresent());
        ArrayList<Integer> expectedList = new ArrayList<Integer>();
        expectedList.add(3);
        expectedList.add(2);
        expectedList.add(1);
        assertEquals (expectedList, indexList.get());
    }

    @Test
    public void is_path_valid() {
        if (System.getProperty("os.name").contains("Windows")) {
            assertTrue (ParserUtil.isPathValid("C:\\path\\to\\destination"));
        } else {
            assertTrue (ParserUtil.isPathValid("/Users/James/Desktop"));
        }

    }
}

@@ -420,39 +420,39 @@
 ;%0A        assert
-Tru
+Fals
 e (
-!
 index.isPresent(
@@ -499,9 +499,10 @@
 ex(%22
-%25
+-1
 %22);%0A
@@ -519,103 +519,15 @@
 sert
-True (!index.isPresent());%0A%0A        index = ParserUtil.parseIndex(%22abc%22);%0A        assertTru
+Fals
 e (
-!
 inde
@@ -598,32 +598,30 @@
       assert
-Fals
+Tru
 e (
-!
 index.isPres
@@ -784,117 +784,15 @@
 sert
-True (!indexList.isPresent());%0A%0A        indexList = ParserUtil.parseMultiIndex(%22 , 1%22);%0A        assertTru
+Fals
 e (
-!
 inde
@@ -864,12 +864,13 @@
 ex(%22
+-
 1, 
-a
+2
 %22);%0A
@@ -875,39 +875,39 @@
 ;%0A        assert
-Tru
+Fals
 e (
-!
 indexList.isPres
@@ -980,110 +980,8 @@
 %22);%0A
-        assertTrue (!indexList.isPresent());%0A%0A        indexList = ParserUtil.parseMultiIndex(%221, 1%22);%0A
     
@@ -989,33 +989,32 @@
    assertFalse (
-!
 indexList.isPres
@@ -1024,71 +1024,8 @@
 ());
-%0A        assertEquals (%221%22, indexList.get().get(0).toString());
 %0A%0A  
@@ -1070,16 +1070,18 @@
 iIndex(%22
+1,
  1, 1 to
@@ -1086,55 +1086,12 @@
 to 3
-%22);%0A        assertFalse (!indexList.isPresent()
+, 4%22
 );%0A 
@@ -1157,16 +1157,45 @@
 ger%3E();%0A
+        expectedList.add(4);%0A
         
@@ -1273,16 +1273,60 @@
 add(1);%0A
+        assertTrue (indexList.isPresent());%0A
         
@@ -1665,17 +1665,17 @@
       %7D%0A
-%0A
     %7D%0A
+%0A
 %7D%0A

Use mix test cases