Ejemplo n.º 1
0
        public virtual void test_of_propertyNoEquals()
        {
            IniFile test = IniFile.of(CharSource.wrap("[section]\na\n"));
            Multimap <string, string> keyValues1 = ImmutableListMultimap.of("a", "");

            assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1)));

            assertEquals(test.section("section"), PropertySet.of(keyValues1));
            assertEquals(test.section("section").contains("a"), true);
            assertEquals(test.section("section").valueList("a"), ImmutableList.of(""));
            assertEquals(test.section("section").contains("b"), false);
            assertEquals(test.section("section").keys(), ImmutableSet.of("a"));
            assertEquals(test.section("section").asMultimap(), ImmutableListMultimap.of("a", ""));
            assertEquals(test.ToString(), "{section={a=[]}}");
        }
Ejemplo n.º 2
0
        public virtual void test_of_list()
        {
            IniFile test = IniFile.of(CharSource.wrap(INI3));
            Multimap <string, string> keyValues1 = ImmutableListMultimap.of("a", "x", "a", "y");

            assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1)));

            assertEquals(test.section("section"), PropertySet.of(keyValues1));
            assertEquals(test.section("section").contains("a"), true);
            assertThrowsIllegalArg(() => test.section("section").value("a"));
            assertEquals(test.section("section").valueList("a"), ImmutableList.of("x", "y"));
            assertEquals(test.section("section").contains("b"), false);
            assertEquals(test.section("section").keys(), ImmutableSet.of("a"));
            assertEquals(test.section("section").asMultimap(), ImmutableListMultimap.of("a", "x", "a", "y"));
            assertEquals(test.ToString(), "{section={a=[x, y]}}");
        }
Ejemplo n.º 3
0
        public virtual void test_of_noLists()
        {
            IniFile test = IniFile.of(CharSource.wrap(INI1));
            Multimap <string, string> keyValues1 = ImmutableListMultimap.of("c", "x", "b", "y", "a", "z");
            Multimap <string, string> keyValues2 = ImmutableListMultimap.of("a", "m", "b", "n");

            assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1), "name", PropertySet.of(keyValues2)));

            assertEquals(test.contains("section"), true);
            assertEquals(test.section("section"), PropertySet.of(keyValues1));
            assertEquals(test.section("section").contains("c"), true);
            assertEquals(test.section("section").value("c"), "x");
            assertEquals(test.section("section").valueList("c"), ImmutableList.of("x"));
            assertEquals(test.section("section").contains("b"), true);
            assertEquals(test.section("section").value("b"), "y");
            assertEquals(test.section("section").valueList("b"), ImmutableList.of("y"));
            assertEquals(test.section("section").contains("a"), true);
            assertEquals(test.section("section").value("a"), "z");
            assertEquals(test.section("section").valueList("a"), ImmutableList.of("z"));
            assertEquals(test.section("section").contains("d"), false);
            // order must be retained
            assertEquals(ImmutableList.copyOf(test.section("section").keys()), ImmutableList.of("c", "b", "a"));
            assertEquals(test.section("section").asMultimap(), ImmutableListMultimap.of("c", "x", "b", "y", "a", "z"));

            assertEquals(test.contains("name"), true);
            assertEquals(test.section("name"), PropertySet.of(keyValues2));
            assertEquals(test.section("name").contains("a"), true);
            assertEquals(test.section("name").value("a"), "m");
            assertEquals(test.section("name").valueList("a"), ImmutableList.of("m"));
            assertEquals(test.section("name").contains("b"), true);
            assertEquals(test.section("name").value("b"), "n");
            assertEquals(test.section("name").valueList("b"), ImmutableList.of("n"));
            assertEquals(test.section("name").contains("c"), false);
            assertEquals(ImmutableList.copyOf(test.section("name").keys()), ImmutableList.of("a", "b"));
            assertEquals(test.section("name").asMultimap(), ImmutableListMultimap.of("a", "m", "b", "n"));

            assertEquals(test.contains("unknown"), false);
            assertThrowsIllegalArg(() => test.section("unknown"));
            assertEquals(test.section("section").valueList("unknown"), ImmutableList.of());
            assertThrowsIllegalArg(() => test.section("section").value("unknown"));
            assertEquals(test.ToString(), "{section={c=[x], b=[y], a=[z]}, name={a=[m], b=[n]}}");
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Obtains an instance of <seealso cref="CharSource"/> from a text variable, specified as a byte array.
 /// This also takes in a specific character set, as a <seealso cref="Charset"/>.
 /// </summary>
 /// <param name="content">  the text to create a <seealso cref="CharSource"/> for </param>
 /// <param name="charset">  the charset to build the new CharSource based on </param>
 /// <returns>  a new instance of <seealso cref="CharSource"/> </returns>
 public static CharSource ofContent(sbyte[] content, Charset charset)
 {
     return(CharSource.wrap(StringHelper.NewString(content, charset)));
 }
Ejemplo n.º 5
0
 //---------------------------------------------------------------------------------------------
 /// <summary>
 /// Obtains an instance of <seealso cref="CharSource"/> from a text variable, specified as a <seealso cref="String"/> object.
 /// </summary>
 /// <param name="content">  the text to create a <seealso cref="CharSource"/> for </param>
 /// <returns>  a new instance of <seealso cref="CharSource"/> with UTF-8 for charset </returns>
 public static CharSource ofContent(string content)
 {
     return(CharSource.wrap(content));
 }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void test_of_invalid_propertyAtStart()
        public virtual void test_of_invalid_propertyAtStart()
        {
            string invalid = "a = x\n";

            IniFile.of(CharSource.wrap(invalid));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void test_of_invalid_emptyKey()
        public virtual void test_of_invalid_emptyKey()
        {
            string invalid = "= y\n";

            PropertiesFile.of(CharSource.wrap(invalid));
        }