@@ -928,3 +928,62 @@ void test_config_read__nosection(void)
928928 git_buf_dispose (& buf );
929929 git_config_free (cfg );
930930}
931+
932+ enum {
933+ MAP_TRUE = 0 ,
934+ MAP_FALSE = 1 ,
935+ MAP_ALWAYS = 2
936+ };
937+
938+ static git_configmap _test_map1 [] = {
939+ {GIT_CONFIGMAP_STRING , "always" , MAP_ALWAYS },
940+ {GIT_CONFIGMAP_FALSE , NULL , MAP_FALSE },
941+ {GIT_CONFIGMAP_TRUE , NULL , MAP_TRUE },
942+ };
943+
944+ static git_configmap _test_map2 [] = {
945+ {GIT_CONFIGMAP_INT32 , NULL , 0 },
946+ };
947+
948+ void test_config_read__get_mapped (void )
949+ {
950+ git_config * cfg ;
951+ int val ;
952+ int known_good ;
953+
954+ cl_set_cleanup (& clean_test_config , NULL );
955+ cl_git_mkfile ("./testconfig" , "[header]\n key1 = 1\n key2 = true\n key3\n key4 = always\n key5 = false\n key6 = 0\n key7 = never\n" );
956+ cl_git_pass (git_config_open_ondisk (& cfg , "./testconfig" ));
957+
958+ // check aprsing bool and string
959+ cl_git_pass (git_config_get_mapped (& val , cfg , "header.key1" , _test_map1 , ARRAY_SIZE (_test_map1 )));
960+ cl_assert_equal_i (val , MAP_TRUE );
961+ cl_git_pass (git_config_get_mapped (& val , cfg , "header.key2" , _test_map1 , ARRAY_SIZE (_test_map1 )));
962+ cl_assert_equal_i (val , MAP_TRUE );
963+
964+ cl_git_pass (git_config_get_mapped (& val , cfg , "header.key4" , _test_map1 , ARRAY_SIZE (_test_map1 )));
965+ cl_assert_equal_i (val , MAP_ALWAYS );
966+
967+ cl_git_pass (git_config_get_mapped (& val , cfg , "header.key5" , _test_map1 , ARRAY_SIZE (_test_map1 )));
968+ cl_assert_equal_i (val , MAP_FALSE );
969+ cl_git_pass (git_config_get_mapped (& val , cfg , "header.key6" , _test_map1 , ARRAY_SIZE (_test_map1 )));
970+ cl_assert_equal_i (val , MAP_FALSE );
971+
972+ cl_git_fail (git_config_get_mapped (& val , cfg , "header.key7" , _test_map1 , ARRAY_SIZE (_test_map1 )));
973+
974+ // check parsing int values
975+ cl_git_pass (git_config_get_mapped (& val , cfg , "header.key1" , _test_map2 , ARRAY_SIZE (_test_map2 )));
976+ cl_git_pass (git_config_get_int32 (& known_good , cfg , "header.key1" ));
977+ cl_assert_equal_i (val , known_good );
978+ cl_git_pass (git_config_get_mapped (& val , cfg , "header.key6" , _test_map2 , ARRAY_SIZE (_test_map2 )));
979+ cl_git_pass (git_config_get_int32 (& known_good , cfg , "header.key6" ));
980+ cl_assert_equal_i (val , known_good );
981+
982+ cl_git_fail (git_config_get_mapped (& val , cfg , "header.key2" , _test_map2 , ARRAY_SIZE (_test_map2 )));
983+ cl_git_fail (git_config_get_mapped (& val , cfg , "header.key3" , _test_map2 , ARRAY_SIZE (_test_map2 )));
984+ cl_git_fail (git_config_get_mapped (& val , cfg , "header.key4" , _test_map2 , ARRAY_SIZE (_test_map2 )));
985+ cl_git_fail (git_config_get_mapped (& val , cfg , "header.key5" , _test_map2 , ARRAY_SIZE (_test_map2 )));
986+ cl_git_fail (git_config_get_mapped (& val , cfg , "header.key7" , _test_map2 , ARRAY_SIZE (_test_map2 )));
987+
988+ git_config_free (cfg );
989+ }
0 commit comments