@@ -732,6 +732,27 @@ TEST_CASE("std::optional", "[optional]") {
732
732
}
733
733
#endif
734
734
735
+ #ifdef CXXOPTS_HAS_FILESYSTEM
736
+ TEST_CASE (" std::filesystem::path" , " [path]" ) {
737
+ std::filesystem::path path;
738
+ cxxopts::Options options (" path" , " - tests path" );
739
+ options.add_options ()
740
+ (" path" , " a path" , cxxopts::value<std::filesystem::path>(path));
741
+
742
+ Argv av ({" path" , " --path" , " Hello World.txt" });
743
+
744
+ auto ** argv = av.argv ();
745
+ auto argc = av.argc ();
746
+
747
+ REQUIRE (path.empty ());
748
+
749
+ options.parse (argc, argv);
750
+
751
+ REQUIRE (!path.empty ());
752
+ CHECK (path == " Hello World.txt" );
753
+ }
754
+ #endif
755
+
735
756
TEST_CASE (" Unrecognised options" , " [options]" ) {
736
757
cxxopts::Options options (" unknown_options" , " - test unknown options" );
737
758
@@ -877,6 +898,60 @@ TEST_CASE("Optional value", "[optional]")
877
898
}
878
899
#endif
879
900
901
+ #ifdef CXXOPTS_HAS_OPTIONAL
902
+ TEST_CASE (" std::filesystem::path value" , " [path]" )
903
+ {
904
+ cxxopts::Options options (" options" , " query as std::fileystem::path" );
905
+ options.add_options ()
906
+ (" a" , " Path" , cxxopts::value<std::filesystem::path>())
907
+ (" b" , " Path" , cxxopts::value<std::filesystem::path>())
908
+ (" c" , " Path" , cxxopts::value<std::filesystem::path>())
909
+ (" d" , " Path" , cxxopts::value<std::filesystem::path>())
910
+ (" e" , " Path" , cxxopts::value<std::filesystem::path>())
911
+ ;
912
+
913
+ SECTION (" Available" ) {
914
+ Argv av ({
915
+ " available" ,
916
+ " -a" , " hello.txt" ,
917
+ " -b" , " C:\\ Users\\ JoeCitizen\\ hello world.txt" ,
918
+ " -c" , " /home/joecitzen/hello world.txt" ,
919
+ " -d" , " ../world.txt"
920
+ });
921
+
922
+ auto ** argv = av.argv ();
923
+ auto argc = av.argc ();
924
+
925
+ auto result = options.parse (argc, argv);
926
+
927
+ CHECK (result.as_optional <std::filesystem::path>(" a" ));
928
+ CHECK (result.as_optional <std::filesystem::path>(" b" ));
929
+ CHECK (result.as_optional <std::filesystem::path>(" c" ));
930
+ CHECK (result.as_optional <std::filesystem::path>(" d" ));
931
+ CHECK (!result.as_optional <std::filesystem::path>(" e" ));
932
+
933
+ CHECK (result.as_optional <std::filesystem::path>(" a" ) == " hello.txt" );
934
+ CHECK (result.as_optional <std::filesystem::path>(" b" ) == " C:\\ Users\\ JoeCitizen\\ hello world.txt" );
935
+ CHECK (result.as_optional <std::filesystem::path>(" c" ) == " /home/joecitzen/hello world.txt" );
936
+ CHECK (result.as_optional <std::filesystem::path>(" d" ) == " ../world.txt" );
937
+ }
938
+
939
+ SECTION (" Unavailable" ) {
940
+ Argv av ({
941
+ " unavailable"
942
+ });
943
+
944
+ auto ** argv = av.argv ();
945
+ auto argc = av.argc ();
946
+
947
+ auto result = options.parse (argc, argv);
948
+
949
+ CHECK (!result.as_optional <std::filesystem::path>(" a" ));
950
+ }
951
+
952
+ }
953
+ #endif
954
+
880
955
TEST_CASE (" Initializer list with group" , " [options]" ) {
881
956
cxxopts::Options options (" Initializer list group" , " - test initializer list with group" );
882
957
0 commit comments