@@ -336,6 +336,66 @@ TEST(VerilogProjectTest, UpdateFileContents) {
336
336
EXPECT_EQ (project.LookupFileOrigin (search_substring), from_file);
337
337
}
338
338
339
+ TEST (VerilogProjectTest, UpdateFileContentsEmptyFile) {
340
+ // Users can add empty files to the filelist and subsequently
341
+ // remove them.
342
+ const auto tempdir = ::testing::TempDir ();
343
+ const std::string project_root_dir = JoinPath (tempdir, " srcs" );
344
+ EXPECT_TRUE (CreateDir (project_root_dir).ok ());
345
+
346
+ // root is directory with sources.
347
+ VerilogProject project (project_root_dir, {});
348
+
349
+ // Prepare file to be auto-loaded later
350
+ const ScopedTestFile tf (project_root_dir, " " );
351
+ const absl::string_view reference_name = Basename (tf.filename ());
352
+
353
+ // Push a local analyzed name under the name of the file.
354
+ constexpr absl::string_view external_content (" localparam int p = 1;\n " );
355
+ std::unique_ptr<VerilogAnalyzer> analyzed_structure =
356
+ std::make_unique<VerilogAnalyzer>(external_content, " internal" );
357
+ project.UpdateFileContents (tf.filename (), analyzed_structure.get ());
358
+
359
+ // Look up the file and see that content is the external content
360
+ VerilogSourceFile *from_file;
361
+ absl::string_view search_substring;
362
+ from_file = *project.OpenTranslationUnit (reference_name);
363
+ EXPECT_EQ (from_file->GetContent (), external_content);
364
+
365
+ // ... and we find our file given the substring.
366
+ search_substring = from_file->GetContent ().substr (5 );
367
+ EXPECT_EQ (project.LookupFileOrigin (search_substring), from_file);
368
+
369
+ // Prepare an empty file
370
+ constexpr absl::string_view empty_file_content (" " );
371
+ const ScopedTestFile empty_file (project_root_dir, empty_file_content);
372
+ const absl::string_view empty_file_reference =
373
+ Basename (empty_file.filename ());
374
+
375
+ // Push the empty file into the project
376
+ std::unique_ptr<VerilogAnalyzer> analyzed_empty_structure =
377
+ std::make_unique<VerilogAnalyzer>(empty_file_content, " internal" );
378
+ project.UpdateFileContents (empty_file.filename (),
379
+ analyzed_empty_structure.get ());
380
+
381
+ // Check the content from the two files are present
382
+ from_file = *project.OpenTranslationUnit (reference_name);
383
+ EXPECT_EQ (from_file->GetContent (), external_content);
384
+
385
+ from_file = *project.OpenTranslationUnit (empty_file_reference);
386
+ EXPECT_EQ (from_file->GetContent (), empty_file_content);
387
+
388
+ // Remove the empty file
389
+ project.UpdateFileContents (empty_file.filename (), nullptr );
390
+
391
+ // Make sure the remaining file is still present
392
+ from_file = *project.OpenTranslationUnit (reference_name);
393
+ EXPECT_EQ (from_file->GetContent (), external_content);
394
+
395
+ // Make sure the empty file was removed
396
+ EXPECT_EQ (project.LookupFileOrigin (empty_file.filename ()), nullptr );
397
+ }
398
+
339
399
TEST (VerilogProjectTest, LookupFileOriginTest) {
340
400
const auto tempdir = ::testing::TempDir ();
341
401
const std::string sources_dir = JoinPath (tempdir, " srcs" );
0 commit comments