@@ -21,7 +21,7 @@ public class ConfigParserTests
2121 /// </summary>
2222 static ConfigParserTests ( )
2323 {
24- // Allow the usage of ANSI encoding other than the default one
24+ // Allow the usage of ANSI encoding other than the default one
2525 Encoding . RegisterProvider ( CodePagesEncodingProvider . Instance ) ;
2626
2727 RealWorldConfigFiles = Directory
@@ -285,7 +285,7 @@ public void BooleanValuesAreParsedCorrectly()
285285 {
286286 MultiLineValues = MultiLineValues . QuoteDelimitedValues ,
287287 Encoding = Encoding . UTF8 ,
288- // if some day Boolean.ToString(IFormatProvider) will work
288+ // if some day Boolean.ToString(IFormatProvider) will work
289289 // https://msdn.microsoft.com/en-us/library/s802ct92(v=vs.110).aspx#Anchor_1
290290 Culture = new CultureInfo ( "en-US" ) ,
291291 BooleanConverter = new YesNoConverter ( "vero" , "falso" )
@@ -642,5 +642,44 @@ public void ParsingConfigFileStringWorks()
642642 // null
643643 Assert . Null ( configFileFromString . GetValue ( "Advanced" , "valueLessKey" ) ) ;
644644 }
645+
646+
647+ /// <summary>
648+ /// Reading non-existing empty values, then writing, then re-reading config file again.
649+ /// </summary>
650+ [ Fact ]
651+ public void ReadingWritingReadingConfigFile ( )
652+ {
653+ var configFilepath = $ "{ Path . GetTempFileName ( ) } .wakatime.cfg";
654+ var configParser = new ConfigParser (
655+ configFilepath ,
656+ new ConfigParserSettings
657+ {
658+ MultiLineValues = MultiLineValues . Simple | MultiLineValues . QuoteDelimitedValues ,
659+ Encoding = new UTF8Encoding ( false , false ) ,
660+ NewLine = "\r \n " ,
661+ }
662+ ) ;
663+
664+ configParser . GetValue ( "settings" , "api_key" , string . Empty ) ;
665+ configParser . GetValue ( "settings" , "debug" , false ) ;
666+ configParser . GetValue ( "settings" , "proxy" , string . Empty ) ;
667+
668+ configParser . SetValue ( "settings" , "api_key" , new Guid ( "00000000-0000-0000-0000-000000000000" ) . ToString ( ) ) ;
669+ configParser . SetValue ( "settings" , "debug" , true ) ;
670+ configParser . SetValue ( "settings" , "proxy" , string . Empty ) ;
671+
672+ configParser . Save ( configFilepath ) ;
673+
674+ var configFileContent = File . ReadAllText ( configFilepath , Encoding . UTF8 ) ;
675+ var configExpectedBuilder = new StringBuilder ( ) ;
676+ configExpectedBuilder . AppendLine ( "[settings]" ) ;
677+ configExpectedBuilder . AppendLine ( "api_key=00000000-0000-0000-0000-000000000000" ) ;
678+ configExpectedBuilder . AppendLine ( "debug=true" ) ;
679+ configExpectedBuilder . AppendLine ( "proxy=" ) ;
680+ var configExpectedContent = configExpectedBuilder . ToString ( ) . TrimEnd ( new char [ ] { '\r ' , '\n ' } ) ;
681+
682+ Assert . Equal ( configExpectedContent , configFileContent ) ;
683+ }
645684 }
646685}
0 commit comments