@@ -83,6 +83,8 @@ int main(int argc, char** argv)
8383 mpark::get_if<runcpp2::Data::LocalSource>(&dependencySource.Source );
8484 ssTEST_OUTPUT_ASSERT (" Should be Local source" , local != nullptr );
8585 ssTEST_OUTPUT_ASSERT (" Path" , local->Path == " ../external/mylib" );
86+ ssTEST_OUTPUT_ASSERT ( " Default CopyMode" ,
87+ local->CopyMode == runcpp2::Data::LocalCopyMode::Auto);
8688
8789 // Test ToString() and Equals()
8890 ssTEST_OUTPUT_EXECUTION
@@ -99,6 +101,92 @@ int main(int argc, char** argv)
99101 dependencySource.Equals (parsedOutput));
100102 };
101103
104+ ssTEST (" DependencySource Should Parse Local Source With CopyMode" )
105+ {
106+ const std::vector<std::pair<std::string,
107+ runcpp2::Data::LocalCopyMode>> testCases =
108+ {
109+ {" Auto" , runcpp2::Data::LocalCopyMode::Auto},
110+ {" Symlink" , runcpp2::Data::LocalCopyMode::Symlink},
111+ {" Hardlink" , runcpp2::Data::LocalCopyMode::Hardlink},
112+ {" Copy" , runcpp2::Data::LocalCopyMode::Copy}
113+ };
114+
115+ for (const std::pair<std::string,
116+ runcpp2::Data::LocalCopyMode>& testCase : testCases)
117+ {
118+ ssTEST_OUTPUT (" Test Copy Mode: " << testCase.first );
119+ ssTEST_OUTPUT_SETUP
120+ (
121+ std::string yamlStr = R"(
122+ Local:
123+ Path: ../external/mylib
124+ CopyMode: )" + testCase.first ;
125+
126+ ryml::Tree tree = ryml::parse_in_arena (c4::to_csubstr (yamlStr));
127+ ryml::ConstNodeRef root = tree.rootref ();
128+ runcpp2::Data::DependencySource dependencySource;
129+ );
130+
131+ ssTEST_OUTPUT_EXECUTION
132+ (
133+ ryml::ConstNodeRef nodeRef = root;
134+ bool parseResult = dependencySource.ParseYAML_Node (nodeRef);
135+ );
136+
137+ ssTEST_OUTPUT_ASSERT (" ParseYAML_Node should succeed" , parseResult);
138+
139+ const runcpp2::Data::LocalSource* local =
140+ mpark::get_if<runcpp2::Data::LocalSource>(&dependencySource.Source );
141+ ssTEST_OUTPUT_ASSERT (" Should be Local source" , local != nullptr );
142+
143+ if (!local)
144+ return ;
145+
146+ ssTEST_OUTPUT_ASSERT (" Path" , local->Path , " ../external/mylib" );
147+ ssTEST_OUTPUT_ASSERT (" CopyMode" , local->CopyMode == testCase.second );
148+
149+ // Test ToString() and Equals()
150+ ssTEST_OUTPUT_EXECUTION
151+ (
152+ std::string yamlOutput = dependencySource.ToString (" " );
153+ ryml::Tree outputTree = ryml::parse_in_arena (ryml::to_csubstr (yamlOutput));
154+
155+ runcpp2::Data::DependencySource parsedOutput;
156+ nodeRef = outputTree.rootref ();
157+ parsedOutput.ParseYAML_Node (nodeRef);
158+ );
159+
160+ ssTEST_OUTPUT_ASSERT ( " Parsed output should equal original" ,
161+ dependencySource.Equals (parsedOutput));
162+ }
163+ };
164+
165+ ssTEST (" DependencySource Should Handle Invalid CopyMode" )
166+ {
167+ ssTEST_OUTPUT_SETUP
168+ (
169+ const char * yamlStr = R"(
170+ Local:
171+ Path: ../external/mylib
172+ CopyMode: InvalidMode
173+ )" ;
174+
175+ ryml::Tree tree = ryml::parse_in_arena (c4::to_csubstr (yamlStr));
176+ ryml::ConstNodeRef root = tree.rootref ();
177+
178+ runcpp2::Data::DependencySource dependencySource;
179+ );
180+
181+ ssTEST_OUTPUT_EXECUTION
182+ (
183+ ryml::ConstNodeRef nodeRef = root;
184+ bool parseResult = dependencySource.ParseYAML_Node (nodeRef);
185+ );
186+
187+ ssTEST_OUTPUT_ASSERT (" ParseYAML_Node should fail" , !parseResult);
188+ };
189+
102190 ssTEST_END_TEST_GROUP ();
103191 return 0 ;
104192}
0 commit comments