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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 package org.oran.smo.yangtools.parser.model.util.test;
23 import static org.junit.Assert.assertTrue;
25 import java.util.Arrays;
26 import java.util.List;
28 import org.junit.Test;
30 import org.oran.smo.yangtools.parser.model.util.StringHelper;
32 public class StringHelperTest {
35 // public void test_to_double_quoted_string(){
37 // assertTrue(StringHelper.convertToDoubleQuotedString("").equals("\"\""));
38 // assertTrue(StringHelper.convertToDoubleQuotedString(" ").equals("\" \""));
40 // assertTrue(StringHelper.convertToDoubleQuotedString("ABC").equals("\"ABC\""));
41 // assertTrue(StringHelper.convertToDoubleQuotedString("ABC ").equals("\"ABC \""));
42 // assertTrue(StringHelper.convertToDoubleQuotedString(" ABC ").equals("\" ABC \""));
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
51 public void test_to_module_revision() {
53 assertTrue(StringHelper.getModuleNameAndRevision("module1", null).equals("'module1'"));
54 assertTrue(StringHelper.getModuleNameAndRevision("module1", "").equals("'module1'"));
55 assertTrue(StringHelper.getModuleNameAndRevision("module1", "revision1").equals("'module1/revision1'"));
59 public void test_list_to_string() {
61 final List<String> list = Arrays.asList("ABC", "DEF");
63 assertTrue(StringHelper.toString(list, null, null, null, null, null).equals("ABCDEF"));
64 assertTrue(StringHelper.toString(list, "", "", "", "", "").equals("ABCDEF"));
66 assertTrue(StringHelper.toString(list, "[", "]", "", "", "").equals("[ABCDEF]"));
67 assertTrue(StringHelper.toString(list, "[", "]", ",", "", "").equals("[ABC,DEF]"));
68 assertTrue(StringHelper.toString(list, "[", "]", ",", "{", "}").equals("[{ABC},{DEF}]"));