4def755ed761b16ebad2847664f5a7404d18a5ea
[smo/teiv.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2024 Ericsson
4  *  Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21 package org.oran.smo.yangtools.parser.model.util.test;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.Arrays;
26 import java.util.List;
27
28 import org.junit.Test;
29
30 import org.oran.smo.yangtools.parser.model.util.StringHelper;
31
32 public class StringHelperTest {
33
34     //    @Test
35     //    public void test_to_double_quoted_string(){
36     //
37     //          assertTrue(StringHelper.convertToDoubleQuotedString("").equals("\"\""));
38     //          assertTrue(StringHelper.convertToDoubleQuotedString(" ").equals("\" \""));
39     //
40     //          assertTrue(StringHelper.convertToDoubleQuotedString("ABC").equals("\"ABC\""));
41     //          assertTrue(StringHelper.convertToDoubleQuotedString("ABC ").equals("\"ABC \""));
42     //          assertTrue(StringHelper.convertToDoubleQuotedString(" ABC ").equals("\" ABC \""));
43     //
44     //          assertTrue(StringHelper.convertToDoubleQuotedString("AB\"C").equals("\"AB\\\"C\""));    // AB"C   -->   AB\"C
45     //          assertTrue(StringHelper.convertToDoubleQuotedString("AB\nC").equals("\"AB\\nC\""));             // AB<CR>C   -->   AB\nC
46     //          assertTrue(StringHelper.convertToDoubleQuotedString("AB\tC").equals("\"AB\\tC\""));             // AB<TAB>C   -->   AB\tC
47     //          assertTrue(StringHelper.convertToDoubleQuotedString("AB\\C").equals("\"AB\\\\C\""));            // AB\C   -->   AB\\C
48     //    }
49
50     @Test
51     public void test_to_module_revision() {
52
53         assertTrue(StringHelper.getModuleNameAndRevision("module1", null).equals("'module1'"));
54         assertTrue(StringHelper.getModuleNameAndRevision("module1", "").equals("'module1'"));
55         assertTrue(StringHelper.getModuleNameAndRevision("module1", "revision1").equals("'module1/revision1'"));
56     }
57
58     @Test
59     public void test_list_to_string() {
60
61         final List<String> list = Arrays.asList("ABC", "DEF");
62
63         assertTrue(StringHelper.toString(list, null, null, null, null, null).equals("ABCDEF"));
64         assertTrue(StringHelper.toString(list, "", "", "", "", "").equals("ABCDEF"));
65
66         assertTrue(StringHelper.toString(list, "[", "]", "", "", "").equals("[ABCDEF]"));
67         assertTrue(StringHelper.toString(list, "[", "]", ",", "", "").equals("[ABC,DEF]"));
68         assertTrue(StringHelper.toString(list, "[", "]", ",", "{", "}").equals("[{ABC},{DEF}]"));
69
70     }
71
72 }