Home | History | Annotate | Download | only in runtime
      1 /*******************************************************************************
      2  * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors
      3  * All rights reserved. This program and the accompanying materials
      4  * are made available under the terms of the Eclipse Public License v1.0
      5  * which accompanies this distribution, and is available at
      6  * http://www.eclipse.org/legal/epl-v10.html
      7  *
      8  * Contributors:
      9  *    Marc R. Hoffmann - initial API and implementation
     10  *
     11  *******************************************************************************/
     12 package org.jacoco.core.runtime;
     13 
     14 import static org.junit.Assert.assertEquals;
     15 
     16 import java.util.Arrays;
     17 
     18 import org.junit.Test;
     19 
     20 /**
     21  * Unit tests for {@link CommandLineSupport}.
     22  */
     23 public class CommandLineSupportTest {
     24 
     25 	@Test
     26 	public void testQuote1() {
     27 		assertEquals("aBc", CommandLineSupport.quote("aBc"));
     28 	}
     29 
     30 	@Test
     31 	public void testQuote2() {
     32 		assertEquals("\"a c\"", CommandLineSupport.quote("a c"));
     33 	}
     34 
     35 	@Test
     36 	public void testQuote3() {
     37 		assertEquals("\"a\\\"c\"", CommandLineSupport.quote("a\"c"));
     38 	}
     39 
     40 	@Test
     41 	public void testQuote4() {
     42 		assertEquals("\" xy \"", CommandLineSupport.quote(" xy "));
     43 	}
     44 
     45 	@Test
     46 	public void testQuote5() {
     47 		assertEquals("a\\\\b", CommandLineSupport.quote("a\\b"));
     48 	}
     49 
     50 	@Test
     51 	public void testQuoteList1() {
     52 		assertEquals("", CommandLineSupport.quote(Arrays.<String> asList()));
     53 	}
     54 
     55 	@Test
     56 	public void testQuoteList2() {
     57 		assertEquals("a", CommandLineSupport.quote(Arrays.asList("a")));
     58 	}
     59 
     60 	@Test
     61 	public void testQuoteList3() {
     62 		assertEquals("a b c",
     63 				CommandLineSupport.quote(Arrays.asList("a", "b", "c")));
     64 	}
     65 
     66 	@Test
     67 	public void testQuoteList4() {
     68 		assertEquals("a \"b b\" c",
     69 				CommandLineSupport.quote(Arrays.asList("a", "b b", "c")));
     70 	}
     71 
     72 	@Test
     73 	public void testSplit1() {
     74 		assertEquals(Arrays.asList(), CommandLineSupport.split(null));
     75 	}
     76 
     77 	@Test
     78 	public void testSplit2() {
     79 		assertEquals(Arrays.asList(), CommandLineSupport.split(""));
     80 	}
     81 
     82 	@Test
     83 	public void testSplit3() {
     84 		assertEquals(Arrays.asList("abc"), CommandLineSupport.split("abc"));
     85 	}
     86 
     87 	@Test
     88 	public void testSplit4() {
     89 		assertEquals(Arrays.asList("aa", "bbbb", "cccccc"),
     90 				CommandLineSupport.split("  aa  bbbb  cccccc   "));
     91 	}
     92 
     93 	@Test
     94 	public void testSplit5() {
     95 		assertEquals(Arrays.asList("a a", "b b "),
     96 				CommandLineSupport.split("\"a a\" \"b b \" "));
     97 	}
     98 
     99 	@Test
    100 	public void testSplit6() {
    101 		assertEquals(Arrays.asList("a\"c"), CommandLineSupport.split("a\\\"c"));
    102 	}
    103 
    104 	@Test
    105 	public void testSplit7() {
    106 		assertEquals(Arrays.asList("a\\c"), CommandLineSupport.split("a\\c"));
    107 	}
    108 
    109 	@Test
    110 	public void testSplit8() {
    111 		assertEquals(Arrays.asList("a\\"), CommandLineSupport.split("a\\"));
    112 	}
    113 
    114 	@Test
    115 	public void testSplit9() {
    116 		assertEquals(Arrays.asList("a\\", "b"),
    117 				CommandLineSupport.split("a\\ b"));
    118 	}
    119 
    120 	@Test
    121 	public void testSplit10() {
    122 		assertEquals(Arrays.asList("a\\b"), CommandLineSupport.split("a\\\\b"));
    123 	}
    124 
    125 }
    126