| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use strictscip-perl cpan Config-IniFiles 3.002000 strict/; |
| 4 | use warningsscip-perl cpan Config-IniFiles 3.002000 warnings/; |
| 5 | |
| 6 | # Originally: 9 |
| 7 | use Test::Morescip-perl cpan Config-IniFiles 3.002000 Test/More/ tests => 11; |
| 8 | |
| 9 | use Config::IniFilesscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/; |
| 10 | |
| 11 | use libscip-perl cpan Config-IniFiles 3.002000 lib/ "./t/lib"; |
| 12 | |
| 13 | use Config::IniFiles::TestPathsscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/TestPaths/; |
| 14 | |
| 15 | my ( $en, $ini, $success ); |
| 16 | |
| 17 | # test 1 |
| 18 | # print "Empty list when no groups ........ "; |
| 19 | $en = Config::IniFiles->newscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/new().( -file => t_filescip-perl cpan Config-IniFiles 3.002000 main/t_file().('en.ini') ); |
| 20 | |
| 21 | # TEST |
| 22 | isscip-perl cpan Config-IniFiles 3.002000 main/is().( scalarscip-perl cpan Config-IniFiles 3.002000 main/scalar().( $en->Groupsscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/Groups(). ), 0, "Empty list when no groups" ); |
| 23 | |
| 24 | # test 2 |
| 25 | # print "Creating new object, no file ..... "; |
| 26 | $ini = Config::IniFiles->newscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/new().; |
| 27 | |
| 28 | # TEST |
| 29 | okscip-perl cpan Config-IniFiles 3.002000 main/ok().( $ini, "Creating new object" ); |
| 30 | |
| 31 | # test 3 |
| 32 | # print "Setting new file name ............."; |
| 33 | # TEST |
| 34 | okscip-perl cpan Config-IniFiles 3.002000 main/ok().( $ini->SetFileNamescip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/SetFileName().( t_filescip-perl cpan Config-IniFiles 3.002000 main/t_file().('test06.ini') ), "Setting new file name" ); |
| 35 | |
| 36 | # test 4 |
| 37 | # print "Saving under new file name ........"; |
| 38 | # TEST |
| 39 | okscip-perl cpan Config-IniFiles 3.002000 main/ok().( $ini->RewriteConfigscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/RewriteConfig().() && ( -f t_filescip-perl cpan Config-IniFiles 3.002000 main/t_file().('test06.ini') ), |
| 40 | "Saving under new file name ........" ); |
| 41 | |
| 42 | # test 5 |
| 43 | # print "SetSectionComment ................."; |
| 44 | $ini->newvalscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/newval().( "Section1", "Parameter1", "Value1" ); |
| 45 | my @section_comment = ( |
| 46 | "Line 1 of section comment.", |
| 47 | "Line 2 of section comment", |
| 48 | "Line 3 of section comment" |
| 49 | ); |
| 50 | |
| 51 | # TEST |
| 52 | okscip-perl cpan Config-IniFiles 3.002000 main/ok().( $ini->SetSectionCommentscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/SetSectionComment().( "Section1", @section_comment ), |
| 53 | "SetSectionComment() was successful." ); |
| 54 | |
| 55 | # test 6 |
| 56 | # print "GetSectionComment ................."; |
| 57 | { |
| 58 | my @comment = $ini->GetSectionCommentscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/GetSectionComment().("Section1"); |
| 59 | |
| 60 | # TEST |
| 61 | is_deeplyscip-perl cpan Config-IniFiles 3.002000 main/is_deeply().( |
| 62 | \@comment, |
| 63 | [ |
| 64 | "# Line 1 of section comment.", |
| 65 | "# Line 2 of section comment", |
| 66 | "# Line 3 of section comment", |
| 67 | ], |
| 68 | "multi-line GetSectionComment", |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | # test 7 |
| 73 | # print "DeleteSectionComment .............."; |
| 74 | $ini->DeleteSectionCommentscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/DeleteSectionComment().("Section1"); |
| 75 | |
| 76 | # TEST |
| 77 | okscip-perl cpan Config-IniFiles 3.002000 main/ok().( |
| 78 | !definedscip-perl cpan Config-IniFiles 3.002000 main/defined().( $ini->GetSectionCommentscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/GetSectionComment().("Section1") ), |
| 79 | "DeleteSectionComment was successful." |
| 80 | ); |
| 81 | |
| 82 | # test 8 |
| 83 | # CopySection |
| 84 | $ini->CopySectionscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/CopySection().( 'Section1', 'Section2' ); |
| 85 | |
| 86 | # TEST |
| 87 | okscip-perl cpan Config-IniFiles 3.002000 main/ok().( $ini->Parametersscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/Parameters().('Section2'), "CopySection was successful." ); |
| 88 | |
| 89 | # test 9 |
| 90 | # DeleteSection |
| 91 | $ini->DeleteSectionscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/DeleteSection().('Section1'); |
| 92 | |
| 93 | # TEST |
| 94 | okscip-perl cpan Config-IniFiles 3.002000 main/ok().( !$ini->Parametersscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/Parameters().('Section1'), "DeleteSection was successful." ); |
| 95 | |
| 96 | # test 10 |
| 97 | # RenameSection |
| 98 | $ini->RenameSectionscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/RenameSection().( 'Section2', 'Section1' ); |
| 99 | |
| 100 | # TEST |
| 101 | okscip-perl cpan Config-IniFiles 3.002000 main/ok().( |
| 102 | !$ini->Parametersscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/Parameters().('Section2') |
| 103 | && $ini->Parametersscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/Parameters().('Section1') |
| 104 | && $ini->valscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/val().( 'Section1', 'Parameter1' ) eq 'Value1', |
| 105 | "RenameSection was successful." |
| 106 | ); |
| 107 | |
| 108 | # test 11 |
| 109 | # Delete entire config |
| 110 | $ini->Deletescip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/Delete().(); |
| 111 | |
| 112 | # TEST |
| 113 | okscip-perl cpan Config-IniFiles 3.002000 main/ok().( !$ini->Sectionsscip-perl cpan Config-IniFiles 3.002000 Config/IniFiles/Sections().(), "Delete entire config" ); |
| 114 | |
| 115 | # Clean up when we're done |
| 116 | t_unlinkscip-perl cpan Config-IniFiles 3.002000 main/t_unlink().("test06.ini"); |
| 117 |